Previously, Alain Magloire wrote in qdn.public.qnxrtp.os:
Andrew Thomas <> Andrew@cogent.ca> > wrote:
: I have a couple of large programs that call strtok(). Strtok() is
: always returning NULL, regardless of the input. When I try to create
: a small test application, the test works correctly, but the large apps
: continue to fail. The same large apps calling strtok_r() work
: correctly. Both apps work correctly under QNX4 and Linux.
: This happens with Patch A. Has anybody else seen this behaviour?
strtok (char *s1, const char *s2)
static char *word;
return strtok (s1, s2, &word);
if you say strtok_r () works and not strtok () maybe there is more to it.
I put this in a common library that both programs use:
#define strtok(c,d) strtok_ok(c,d)
extern char* strtok_ok (char* c, const char* d);
char* strtok_ok (char* str, const char* delim)
static char *last;
out = strtok_r (str, delim, &last);
… and it works perfectly. I reported a case where GCC is producing
erroneous code in qdn.public.qnxrtp.devtools that actually might cause
strtok() to fail but strtok_r() to succeed. It appears that with -O
specified, GCC can produce code that trashes registers, and neither
the caller nor the receiver takes reponsibility for PUSHing and POPing
them. Want to see some code?