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

Re: writing struct to disk with write()



Actually, the probs been solved, but you're right about the style to use to
check errno. However, I was printing out the values of 'fd' and the ret val
of write() and checking them visually.

 Thanks for the reply anyhow.

--Arsalan.



----- Original Message -----
From: Sarcar, Shourya (MED) <Shourya.Sarcar@xxxxxxxxxxxx>
To: <linux-india-programmers@xxxxxxxxxxxxxxxxxxxxx>
Sent: Friday, October 27, 2000 9:45 AM
Subject: RE: [LIP] 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
>
> ---------------------------------------------
> An alpha version of a web based tool to manage
> your subscription with this mailing list is at
> http://lists.linux-india.org/cgi-bin/mj_wwwusr
>