bsamuels
10-26-2003, 11:35 PM
This simple routine to create a new file and write a short entry, doesn't do what I expected. On running it, the character string that is supposedly written is output to the screen and nothing seems to be written to the file. (The . designation is for a purpose)
void create_file()
{
int out_fd, n_chars,i,len;
char buf[BUFFERSIZE];
char * b = "logmesg: ";
len = strlen(b) ;
for( i =0;i < len;i++)
buf[i] = * b++;
buf[len] = '\0';
if ( out_fd = open("/home/Bruce/.logmesg",O_CREAT|O_RDWR|O_TRUNC, 0666 )== -1 )
perror("Cannot open logmesg");
if ( write( out_fd, buf, len ) != len)
oops("Write error ","");
if (close(out_fd) == -1 )
perror("Error closing files");
}
void create_file()
{
int out_fd, n_chars,i,len;
char buf[BUFFERSIZE];
char * b = "logmesg: ";
len = strlen(b) ;
for( i =0;i < len;i++)
buf[i] = * b++;
buf[len] = '\0';
if ( out_fd = open("/home/Bruce/.logmesg",O_CREAT|O_RDWR|O_TRUNC, 0666 )== -1 )
perror("Cannot open logmesg");
if ( write( out_fd, buf, len ) != len)
oops("Write error ","");
if (close(out_fd) == -1 )
perror("Error closing files");
}