According to Len Budney:
>
> I recommend safecat, which you can find at
> <http://www.pobox.com/~lbudney/linux/software/safecat.html>. Using the
> embedded script `maildir', your rule would be rewritten as:
I'm trying to use safecat on a very busy email server, and noticed
while lookin at the output of truss(1) that all writes to the file are
being done a single character at the time:
% cat writefile.c
...del...
/* ****************************************************************** */
void writefile(int fd) {
char membuf[512];
int n = 0;
int m = 0;
int count = 0;
char *bufptr;
/* Copy stdin to the output file, watching the return values each time. */
while(1) {
/* Read stdin into the buffer. */
n = read(STDIN_FILENO, membuf, 512);
if(n<0 && errno == EINTR) continue;
if(n<0) {
perror("Error reading input");
exit(-1);
}
if(n == 0) break;
/* Write the buffer to our file. */
bufptr = membuf;
for(count=0; count < n; count++) {
****>> do{m = write(fd, bufptr, 1);} while( m==0 || (m<0 && errno == EINTR));
if(m<0) {
perror("Error writing output");
exit(-1);
}
bufptr++;
}
}
Is there some special reason why large size write can't/shouldn't be done?
If there isn't, does anyone have an updated version of this routine (I'm not a C
programmer :-(
Thanks,
--curtis