I've investigated in this annoying bug, and found that it was a bad interaction between sscanf() code and errno : the problem arises in sscanf() when it's called with errno set to EINTR. I've updated the testcase accordingly, it's joined to this e-mail.
The problem doesn't exist in Woody, appeared in Sarge, exists in Etch but seems fixed in Lenny/Sid, I've tested it on a Sid with libc6 2.6-2. Fred.
/* Test case for a possible glibc bug. Frédéric Boiteux <[EMAIL PROTECTED]> Scan two times the same word with a sscanf(). Between them, set the errno to EINTR (instead of a real fonction, to simplify testcase) ; The second scan fails, the '%n' converter isn't honoured ! Tested on i386 architecture : O.K. on Debian GNU/Linux 3.0 (Woody), libc6 version 2.2.5-11.8 Problem on Debian GNU/Linux 3.1 (Sarge), libc6 version 2.3.2.ds1-22sarge6 Problem on Debian GNU/Linux 3.0 (Etch), libc6 version 2.3.6.ds1-13 Sample output : string='Hello', res=1, word='Hello', n=5 string='Hello', res=1, word='Hello', n=-1 *Problem!* */ #include <errno.h> #include <stdio.h> void scan(char *string) { int n, res; char word[100]; n = -1; res = sscanf(string, "%s %n", word, &n); printf("string='%s', res=%d, word='%s', n=%d", string, res, word, n); if ((res == 1) && (n < 0)) printf(" *Problem!*\n"); else putchar('\n'); } int main(void) { scan("Hello"); // success // success, expected result : // string='Hello', res=1, word='Hello', n=5 // a function call would set the errno to EINTR... errno = EINTR; // uncomment following line to get correct behaviour : // errno = 0; scan("Hello"); // fails, 'n' isn't set... return 0; }