[LCP]creating files with open()
Andrew Weaver
Andrew.Weaver at tecnomen.fi
Mon Oct 8 16:30:09 UTC 2001
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?
> -----Original Message-----
> From: Andy Zivkovic [SMTP:andy at zivkotech.net.au]
> Sent: Saturday, September 29, 2001 1:17 PM
> To: linuxcprogramming at lists.linux.org.au
> Subject: [LCP]creating files with open()
>
> Hi,
>
> I'm trying to open/create a file if it doesn't exist, then write to it,
> however writes are failing. Additionally, the permissions on the file is
> really strange. On linux (home) and windows (home) the function I've
> copied
> below creates the file, but the write fails, and the close succeeds. On
> Solaris (uni) the open fails.
>
> Is there anything immediately obvious with my program?
>
> The test program I'm using is:
>
> int main(int argc, char *argv[]) {
> int file, ret;
>
> file = open("file.txt", O_CREAT|O_EXCL);
>
> printf("file = %d\n", file);
>
> ret = write(file, "12345\n", 6);
>
> printf("ret = %d\n", ret);
> if (ret < 0) {
> printf("%s\n", strerror(errno));
> }
>
> ret = close(file);
> printf("ret = %d\n", ret);
> }
>
> _______________________________________________
> This is the Linux C Programming List
> : http://lists.linux.org.au/listinfo/linuxcprogramming List
More information about the linuxCprogramming
mailing list