[LCP]creating files with open()

Barry linuxc at nibelung.demon.co.uk
Tue Oct 9 03:12:42 UTC 2001


You should use FILE for buffered file operations (fopen, fwrite, etc) and as
you correctly used, int for low level operations like open() or close().  It
would be more efficient to use the buffered i/o operations.

Barry


-----Original Message-----
From: linuxcprogramming-admin at lists.linux.org.au
[mailto:linuxcprogramming-admin at lists.linux.org.au]On Behalf Of Andy
Zivkovic
Sent: 08 October 2001 09:23
To: linuxcprogramming at lists.linux.org.au
Subject: RE: [LCP]creating files with open()


Sorry for not replying earlier, I've been so busy doing work I forgot to
reply :(

Madhav M. was correct, I forgot to specify O_WRONLY. When I did that,
everything started to work. I was so busy trying to do the UDP/transfer
protocol stuff that I forgot the basics of file I/O. :(

Why do people keep saying "don't use int's, use FILEs"? As far as I know,
file descriptors (ints) are used internally by the OS, so a FILE is actually
a wrapper around a file descriptor.

Anyway, I am saving binary files, so I don't require the formatting of
fprintf, etc. I may as well use write instead of fwrite, and get to use one
less parameter that way too. But thanks for everyone's suggestions. Typical
the solution was something so easy/obvious :(

Andy

> -----Original Message-----
> From: linuxcprogramming-admin at lists.linux.org.au
> [mailto:linuxcprogramming-admin at lists.linux.org.au]On Behalf Of Andrew
> Weaver
> Sent: Monday, 8 October 2001 3:59 PM
> To: 'linuxcprogramming at lists.linux.org.au'
> Subject: RE: [LCP]creating files with open()
>
>
> First off, use FILE for the file, not int. What are your
> permissions in the
> directory you run your program and what is the umask setting?
>

_______________________________________________
This is the Linux C Programming List
:  http://lists.linux.org.au/listinfo/linuxcprogramming List




More information about the linuxCprogramming mailing list