Hello,
Just saw your fix. I believe it will still trigger the spurious message when
NANOTINY is defined, and also it would flush the stdio buffer for FIFOs
when NANOTINY isn't defined.
Also, the content of st would be undefined if the file doesn't exist:
#include <stdio.h>
#include <string.h>
#include <sys/stat.h>
int main() {
struct stat st;
memset(&st, 3, sizeof(struct stat));
stat("non_existing_file", &st);
fwrite(&st, sizeof(struct stat), 1, stdout);
return 0;
}
% ./a.out | hexdump
0000000 0303 0303 0303 0303 0303 0303 0303 0303
*
0000090
I was thinking: the only error fflush can set is EBADF, so if errno == EINVAL,
it must have been set by the fsync call. So why not set errno = 0 before the if block,
and then add an inner if block with errno != EINVAL:
/* Ensure the data has reached the disk before reporting it as written. */
errno = 0;
if (fflush(thefile) != 0 || fsync(fileno(thefile)) != 0) {
/* fsync will trigger EINVAL if the file is a pipe, a socket or a FIFO,
so let's just ignore it. */
if (errno != EINVAL) {
statusline(ALERT, _("Error writing %s: %s"), realname, strerror(errno));
fclose(thefile);
goto cleanup_and_exit;
}
}
This would also work when NANOTINY is defined.
The other option would be moving the variables st and is_existing_file, and also setting them,
outside the #ifndef NANOTINY block, and then testing for is_existing_file and S_ISFIFO.
André Kugland