| delorie.com/archives/browse.cgi | search |
| X-Authentication-Warning: | delorie.com: mail set sender to djgpp-bounces using -f |
| X-Recipient: | djgpp AT delorie DOT com |
| Message-ID: | <51E200D7.1050800@gmx.de> |
| Date: | Sun, 14 Jul 2013 03:37:27 +0200 |
| From: | Juan Manuel Guerrero <juan DOT guerrero AT gmx DOT de> |
| User-Agent: | Mozilla/5.0 (X11; Linux x86_64; rv:16.0) Gecko/20121025 Thunderbird/16.0.2 |
| MIME-Version: | 1.0 |
| To: | djgpp AT delorie DOT com |
| Subject: | A question about the ferror behavior |
| X-Provags-ID: | V03:K0:+kqXfyP+U2go716x6faZd46qU0EcU29vtLDQeoWbgSWRYjPo58U |
| cMDdoyfDuZcQZytENlgc1H7c5PPlRR6yL1+yZJ0iBSTT0VRw+osEV0gTHGcHg3v94cElk0n | |
| 9Y7hDqi288o823NFolo5mo6JqeLlOCdw3gzzHs7C8aRgSr4zXnMu6NVR/MHaDx/9ZrKERm5 | |
| ujBNFpjJyf311NiDObfnw== | |
| Reply-To: | djgpp AT delorie DOT com |
Please inspect the code snippet below:
#include <stdio.h>
int main(void)
{
char buffer[1024];
FILE *f = fopen("foobar.txt", "w");
clearerr(f);
if (fgets(buffer, sizeof(buffer), f) == NULL)
printf("EOF encountered before data\n");
printf("ferror = %s\n", ferror(f) ? "TRUE" : "FALSE");
printf("feof = %s\n", feof(f) ? "TRUE" : "FALSE");
return 0;
}
If this code is compiled with djdev203 or djdev204 I get
the following output:
EOF encountered before data
ferror = FALSE
feof = FALSE
If I compile the code on linux I get the following
output:
EOF encountered before data
ferror = TRUE
feof = FALSE
With the write mode passed to fopen, the file is created
and truncated to zero length. As it can be seen fgets
returns a NULL pointer because EOF is reached without
reading data from file. Is the deference in behavior
compared with linux intentional or is it a bug? I do not
have neither working installations of cygwin nor mingw nor
the time to check if this behavior is the same or
different there.
This behavior difference makes pass tests under linux
and makes fail the same tests under djgpp.
Some clarification would be appreciated if this is a bug
or a feature.
Regards,
Juan M. Guerrero
| webmaster | delorie software privacy |
| Copyright © 2019 by DJ Delorie | Updated Jul 2019 |