[Mimedefang] putc failed: Error 0 line 848

Steffen Kaiser skmimedefang at smail.inf.fh-bonn-rhein-sieg.de
Tue Nov 12 05:26:01 EST 2002


On Mon, 11 Nov 2002, David F. Skoll wrote:

> On Mon, 11 Nov 2002, Steffen Kaiser wrote:
>
> > This is very unlikely, there is about 10GB unused space and there is no
> > other sign except these log entries.
>
> OK; then Solaris's putc implementation has a bug. :-)
>
> The code in question is:
>
> 	if (putc(*s, data->fp) == EOF) {
> 		syslog(LOG_WARNING, "putc failed: %m line %d", __LINE__);
> 	}
>
> "putc" should return EOF only on failure, and should then set errno.  It's
> returning EOF, but not setting errno (that's the "Error 0").
>
> Now, "s" is a pointer to unsigned char, and should never be cast to EOF
> as the result of a putc(), but that could be what's happening.

I've tried this program:
===
#include <stdio.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>

char buf[256];

main(void)
{	unsigned char *s;
	int i;
	FILE *fp;

	/* That's how you open the file? */
	if((i = open("/tmp/q.out", O_CREAT | O_EXCL | O_APPEND | O_RDWR, 0600)) < 0 ||
	 (fp = fdopen(i, "w+")) == NULL) {
		perror("Failed to open /tmp/q.out: ");
		return 1;
	}

	for(i = 0; i < 256; ++i)
		buf[i] = i;

	for(i = 0, s = buf; i < 256; ++i, ++s)
		if(putc(*s, fp) == EOF)
			fprintf(stderr, "failed at %u\n", i);

	return 0;
}
====

The created file is 256 bytes long and contains exactly the bytes 0..255;
no error is displayed.
There is no problem, too, when you execute the second for() loop 1000
times (in order to have the buffer flushed during putc()).

On Mon, 11 Nov 2002 Alberto.daSilva at rmb.co.za wrote:

> > This is very unlikely, there is about 10GB unused space and there is no
> > other sign except these log entries.
>
> Run fsck on /var

No errors found.

Bye,

-- 

Steffen Kaiser






More information about the MIMEDefang mailing list