Nathan Lynch <nath...@linux.ibm.com> writes: > Nathan Lynch <nath...@linux.ibm.com> writes: >> Michael Ellerman <m...@ellerman.id.au> writes: >>> +static int search_proc_maps(char *needle, unsigned long *low, unsigned >>> long *high) >> >> ^^ const?
Sorry I meant to do this but then forgot. >>> +{ >>> + unsigned long start, end; >>> + static char buf[4096]; >>> + char name[128]; >>> + FILE *f; >>> + int rc = -1; >>> + >>> + f = fopen("/proc/self/maps", "r"); >>> + if (!f) { >>> + perror("fopen"); >>> + return -1; >>> + } >>> + >>> + while (fgets(buf, sizeof(buf), f)) { >>> + rc = sscanf(buf, "%lx-%lx %*c%*c%*c%*c %*x %*d:%*d %*d %127s\n", >>> + &start, &end, name); >> >> I suspect it doesn't matter in practice for this particular test, but >> since this looks like a generally useful function that could gain users >> in the future: does this spuriously fail if the matching line straddles >> a 4096-byte boundary? Maybe fscanf(3) should be used instead? > > Or maybe I should read the fgets man page more closely :-) > > "Reading stops after an EOF or a newline." > > Sorry for the noise. No worries, thanks for reviewing. cheers