Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

kconfig: introduce getline_stripped() helper

Currently, newline characters are stripped away in multiple places
on the caller.

Doing that in the callee is helpful for further cleanups.

Signed-off-by: Masahiro Yamada <masahiroy@kernel.org>

+26 -14
+26 -14
scripts/kconfig/confdata.c
··· 337 337 return -1; 338 338 } 339 339 340 + /* like getline(), but the newline character is stripped away */ 341 + static ssize_t getline_stripped(char **lineptr, size_t *n, FILE *stream) 342 + { 343 + ssize_t len; 344 + 345 + len = compat_getline(lineptr, n, stream); 346 + 347 + if (len > 0 && (*lineptr)[len - 1] == '\n') { 348 + len--; 349 + (*lineptr)[len] = '\0'; 350 + 351 + if (len > 0 && (*lineptr)[len - 1] == '\r') { 352 + len--; 353 + (*lineptr)[len] = '\0'; 354 + } 355 + } 356 + 357 + return len; 358 + } 359 + 340 360 int conf_read_simple(const char *name, int def) 341 361 { 342 362 FILE *in = NULL; 343 363 char *line = NULL; 344 364 size_t line_asize = 0; 345 - char *p, *p2, *val; 365 + char *p, *val; 346 366 struct symbol *sym; 347 367 int i, def_flags; 348 368 const char *warn_unknown, *werror, *sym_name; ··· 441 421 } 442 422 } 443 423 444 - while (compat_getline(&line, &line_asize, in) != -1) { 424 + while (getline_stripped(&line, &line_asize, in) != -1) { 445 425 conf_lineno++; 446 426 if (line[0] == '#') { 447 427 if (line[1] != ' ') ··· 463 443 p = strchr(sym_name, '='); 464 444 if (!p) 465 445 continue; 466 - *p++ = 0; 467 - val = p; 468 - p2 = strchr(p, '\n'); 469 - if (p2) { 470 - *p2-- = 0; 471 - if (*p2 == '\r') 472 - *p2 = 0; 473 - } 446 + *p = 0; 447 + val = p + 1; 474 448 } else { 475 - if (line[0] != '\r' && line[0] != '\n') 476 - conf_warning("unexpected data: %.*s", 477 - (int)strcspn(line, "\r\n"), line); 478 - 449 + if (line[0] != '\0') 450 + conf_warning("unexpected data: %s", line); 479 451 continue; 480 452 } 481 453