[Subject Prev][Subject Next][Thread Prev][Thread Next][Subject Index][Thread Index]

RE: writing struct to disk with write()



#fd = open("aaa.info", O_APPEND);
#printf("error 1 = %d\n", errno);
#
#perror ("after open");
#//fd = open("/dev/pts/0",0);
#printf("fd = %d\n",fd);
#
#ret = write(fd, &file_info, sizeof(file_info));
#
#printf("write = %d\n",ret);
#printf("error 2 = %d\n", errno);
#perror("write error");
#close(fd);
#


are you checking the file for the output after the program stops ? what say
that ?
keep in mind that the extern int errno variable is NOT reset if a syscall
performs OK. So errno could have a value left over from program
startup/previous error and perror (if unconditional) will still show an
error message.

I would reccomend :

if ((fd=open(..))== -1)
{
	perror("Failed open");
}


if ((nbytes=write(fd,..))== -1)
{
	perror("Failed write");
}


Regards
Shourya