Mail Archives: djgpp-workers/1998/06/17/08:12:02
Hi, workers,
I don't know if this has been up here before (I'm only reading this
list since a month or so), but I've encountered a problem with the
latest 2.02-alpha (980101, can I get a newer one somewhere?). This
problem was *not* in v2.01.
When a file is opened "wt+" (or "wb+"), it is written to, rewinded
(whether with rewind() or fseek()) and read from, the latter doesn't
work. Take the following little program:
#include <stdio.h>
int main(void)
{
FILE *f;
char buf[100];
char *p;
f = fopen("__tmp__.$$$", "wt+");
fputs("abcdefghijklmnopqrstuvwxyz0123456789\n\n", f);
rewind(f);
p = fgets(buf, 10, f);
printf("p = 0x%08p\n", p);
if (p != NULL)
printf("buf = `%s'\n", buf);
fclose(f);
return 0;
}
It returns p = 0x0, where 2.01 would give "abcdefghi". An interesting
point: it doesn't seem to work on Solaris 5.5.1 either (also returns
NULL), and Linux.
Is this, uh, like, documented somewhere? The libc.inf specificially
says a file opened with "+" should set it's position (with rewind,
fseek or fsetpos) before reading/writing.
As I'm at it, why does `gcc -Wall' give this warning, as it is usual
practice:
testit.c: In function `main':
testit.c:14: warning: flag `0' used with type `p'
--
Groeten, Michel. http://www.cs.vu.nl/~mdruiter
____________
\ /====\ / "You know, Beavis, you need things that suck,
\/ \/ to have things that are cool", Butt-Head.
- Raw text -