2012/1/22 Jérémie Koenig <firstname.lastname@example.org>
The usual trick for "%d" is to use the constant "sizeof (int) * 3 +
1". I included + 1 for the sign, but it's not really necessary if we
exepect sizeof(int) >= 2, which we probably should.
Why '*3'? Do you expect PID to be in a certain range? Or is it C-voodoo?!
Also, I think there are some problems with your pointer arithmetic.
if (fgets(buf+last,size,f) == NULL)
will overwrite the last character read from the previous iteration (if
there was one).
According to the 'gets' page, each "read" returns a '\0' terminated string. Each time I get rid of this '\0' when concatenating.
I would say the "first unused byte" convention is more common and
I'll rewrite a more consistent code...
buf[last+1] will always be '\0' (the terminating null character of the
string). I also think you mean to return when the last character _is_
a newline (fortunately the two mistakes cancel each other out in the
usual case of no reallocation needed :-).
Last, but not least, you should be careful with whitespace. Your patch
mixes tabs and spaces for indentation,
... which is perfectly consistent with the original code! ;-)
Is a mix (maybe with a logic... I haven't figured it out yet) of spaces and tabs. I can try to reproduce the same "pattern" but not sure what the rule is!
Thanks again, hope next iteration will be better!