fwrite(buf, sizeof(buf), 1, fp) if any error occurs such as ENOSPC or EIO, then also fwrite return value 1, but proper error code is set. but from the man page of fwrite: fwrite() return the number of items successfully read or written (i.e., not the number of characters). If an error occurs, or the end-of-file is reached, the return value is a short item count (or zero). But it can be seen with uclibc 0.9.33.2 the return value is 1 for the above use case in case of failure also. This issue was not observed with uClibc version 0.9.33. Also as seen from the code in libc/stdio/_WRITE.c the following part seems to be culpit * some hidden buffered crap in the buffer. */ if (errno != EINTR && errno != EAGAIN) { /* do we have other "soft" errors? */ break; } return bufsize; Apart from other these 2 error it breaks out of the loop and return bufsize .
fwrite does return the number of elements written. See libc/stdio/fwrite.c, return __stdio_fwrite()/size. can you please attach your .config (which STDIO_BUFF settings do you use) and it would help if you could also paste an strace -v of your failing test program. thanks,
(In reply to comment #1) > fwrite does return the number of elements written. See libc/stdio/fwrite.c, > return __stdio_fwrite()/size. > > can you please attach your .config (which STDIO_BUFF settings do you use) and > it would help if you could also paste an strace -v of your failing test > program. > > thanks, Hi Below are the STDIO_BUFF settings used in .config # UCLIBC_HAS_STDIO_BUFSIZ_NONE is not set # UCLIBC_HAS_STDIO_BUFSIZ_256 is not set # UCLIBC_HAS_STDIO_BUFSIZ_512 is not set # UCLIBC_HAS_STDIO_BUFSIZ_1024 is not set # UCLIBC_HAS_STDIO_BUFSIZ_2048 is not set UCLIBC_HAS_STDIO_BUFSIZ_4096=y # UCLIBC_HAS_STDIO_BUFSIZ_8192 is not set UCLIBC_HAS_STDIO_BUILTIN_BUFFER_NONE=y # UCLIBC_HAS_STDIO_BUILTIN_BUFFER_4 is not set # UCLIBC_HAS_STDIO_BUILTIN_BUFFER_8 is not set # UCLIBC_HAS_STDIO_SHUTDOWN_ON_ABORT is not set # UCLIBC_HAS_STDIO_GETC_MACRO is not set # UCLIBC_HAS_STDIO_PUTC_MACRO is not set UCLIBC_HAS_STDIO_AUTO_RW_TRANSITION=y UCLIBC_HAS_STDIO_FUTEXES=y the same settings work with uClibc09.33. version. But in uClibc 09.33.2 if i comment the following part in _WRITE.c if (errno != EINTR && errno != EAGAIN) { /* do we have other "soft" errors?*/ break; } code seems to work fine. i have just used a normal fwrite function call with following check if(fwrite(buf, sizeof(buf), 1, fp != 1) { printf("error %s\n", strerror(errno)); } this is the way i checked return value for fwrite. thanks.
(In reply to comment #2) > (In reply to comment #1) > > fwrite does return the number of elements written. See libc/stdio/fwrite.c, > > return __stdio_fwrite()/size. > > > > can you please attach your .config (which STDIO_BUFF settings do you use) and > > it would help if you could also paste an strace -v of your failing test > > program. > the same settings work with uClibc09.33. version. > But in uClibc 09.33.2 if i comment the following part in _WRITE.c > if (errno != EINTR && errno != EAGAIN) { > /* do we have other "soft" errors?*/ > break; > } > code seems to work fine. > i have just used a normal fwrite function call with following check > if(fwrite(buf, sizeof(buf), 1, fp != 1) { > printf("error %s\n", strerror(errno)); as you can see in the history, Denys did this to drain the buffer. what errno do you trip there (that was why i was asking for an strace)?
(In reply to comment #3) > (In reply to comment #2) > > (In reply to comment #1) > > > fwrite does return the number of elements written. See libc/stdio/fwrite.c, > > > return __stdio_fwrite()/size. > > > > > > can you please attach your .config (which STDIO_BUFF settings do you use) and > > > it would help if you could also paste an strace -v of your failing test > > > program. > > > the same settings work with uClibc09.33. version. > > But in uClibc 09.33.2 if i comment the following part in _WRITE.c > > if (errno != EINTR && errno != EAGAIN) { > > /* do we have other "soft" errors?*/ > > break; > > } > > code seems to work fine. > > i have just used a normal fwrite function call with following check > > if(fwrite(buf, sizeof(buf), 1, fp != 1) { > > printf("error %s\n", strerror(errno)); > > as you can see in the history, Denys did this to drain the buffer. > what errno do you trip there (that was why i was asking for an strace)? Thanks... Due to some official reasons i am not able to provide the trace.but i will write a simple code and provide you with the strace for this failure. The scenario was that I was writing data to sdcard and if i removed the sdcard from device then fwrite should fail but it returns 1. Err no was set to EIO.Same issue for if no space in sdcard ENOSPC also.
> Thanks... Due to some official reasons i am not able to provide the trace.but i > will write a simple code and provide you with the strace for this failure. > The scenario was that I was writing data to sdcard and if i removed the sdcard > from device then fwrite should fail but it returns 1. Err no was set to > EIO.Same issue for if no space in sdcard ENOSPC also. http://lists.uclibc.org/pipermail/uclibc/2013-February/047524.html and follow-ups. Comments?
(In reply to comment #5) > > Thanks... Due to some official reasons i am not able to provide the trace.but i > > will write a simple code and provide you with the strace for this failure. > > The scenario was that I was writing data to sdcard and if i removed the sdcard > > from device then fwrite should fail but it returns 1. Err no was set to > > EIO.Same issue for if no space in sdcard ENOSPC also. > > http://lists.uclibc.org/pipermail/uclibc/2013-February/047524.html > and follow-ups. > Comments? Thanks ...Yes it was the similar test case mentioned in the above link. i treid with the patch attached in the above link and it seems to be working fine.No issue is observed when I applied the patch mentioned in above link.