[LCP]creating files with open()

Madhav M. madhav3333 at lycos.com
Mon Oct 1 15:37:33 UTC 2001


> Andy Zivkovic wrote:

>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. 

 open() function should be invoked with one of two modes 1. O_WRONLY Or 2. O_RDWR.

These modes are required when file is to be opened for writing.

I don't know about Solaris, but you can refer its man page on Solaris.


>Additionally, the permissions on the file is
>really strange.

In open() call, setting 'mode' which is a third parameter, you can set specific permission to the file.
You can find those symoblic constant values from its man page.

Madhav.

--

On Sat, 29 Sep 2001 19:47:11  
 Andy Zivkovic wrote:
>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
>


Make a difference, help support the relief efforts in the U.S.
http://clubs.lycos.com/live/events/september11.asp



More information about the linuxCprogramming mailing list