Make config -x <kernel> only return non-zero characters,

so that:

	config -x <kernel> | grep <something>

just works.

Reported by:	Danny Braniss <danny@cs.huji.ac.il>
This commit is contained in:
Wojciech A. Koszek 2009-02-06 00:50:21 +00:00
parent 506c6a3a3d
commit d030e65009

View File

@ -669,7 +669,7 @@ kernconfdump(const char *file)
struct stat st; struct stat st;
FILE *fp, *pp; FILE *fp, *pp;
int error, len, osz, r; int error, len, osz, r;
unsigned int off, size; unsigned int i, off, size;
char *cmd, *o; char *cmd, *o;
r = open(file, O_RDONLY); r = open(file, O_RDONLY);
@ -707,7 +707,18 @@ kernconfdump(const char *file)
r = fseek(fp, off, SEEK_CUR); r = fseek(fp, off, SEEK_CUR);
if (r != 0) if (r != 0)
errx(EXIT_FAILURE, "fseek() failed"); errx(EXIT_FAILURE, "fseek() failed");
while ((r = fgetc(fp)) != EOF && size-- > 0) for (i = 0; i < size - 1; i++) {
r = fgetc(fp);
if (r == EOF)
break;
/*
* If '\0' is present in the middle of the configuration
* string, this means something very weird is happening.
* Make such case very visible.
*/
assert(r != '\0' && ("Char present in the configuration "
"string mustn't be equal to 0"));
fputc(r, stdout); fputc(r, stdout);
}
fclose(fp); fclose(fp);
} }