Trouble Writing To File

This is a discussion on Trouble Writing To File within the C Programming forums, part of the General Programming Boards category; I am trying to write to a text file but I believe my permissions on the directory are incorrect and ...

  1. #1
    Registered User
    Join Date
    Nov 2007
    Posts
    96

    Trouble Writing To File

    I am trying to write to a text file but I believe my permissions on the directory are incorrect and so are not allowing me to do so. My return value that write() returns is a number greater than 0 and appears to be the number of bytes which I am trying to write and the file is successfully created. However, when I run "ls -l" on this file I see that there are no permissions set what so ever and there is no data in the file. My open call is using the flags O_RDWR | O_CREAT also

  2. #2
    spurious conceit MK27's Avatar
    Join Date
    Jul 2008
    Location
    segmentation fault
    Posts
    8,300
    Quote Originally Posted by NuNn View Post
    However, when I run "ls -l" on this file I see that there are no permissions set what so ever
    You mean the first part of ls -l output is "--------"? That would be a problem (and sort of strange).

    You can't directly set the mode with open (you can with fopen), so you have to use chmod()
    Code:
    chmod(file,O_IWRITE|O_IREAD);
    Maybe post your whole open line...
    C programming resources:
    GNU C Function and Macro Index -- glibc reference manual
    The C Book -- nice online learner guide
    Current ISO draft standard
    CCAN -- new CPAN like open source library repository
    3 (different) GNU debugger tutorials: #1 -- #2 -- #3
    cpwiki -- our wiki on sourceforge

  3. #3
    Registered User
    Join Date
    Nov 2007
    Posts
    96
    Yep, MK that is what the output is on the ls command. I am locking the server program itself to ensure there are no more than one copy of it running at a time but this shouldn't have any effect on the creation of this file would it?

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Trouble writing characters to a file.
    By themusician31 in forum C Programming
    Replies: 7
    Last Post: 08-10-2008, 05:50 AM
  2. help with text input
    By Alphawaves in forum C Programming
    Replies: 8
    Last Post: 04-08-2007, 04:54 PM
  3. Encryption program
    By zeiffelz in forum C Programming
    Replies: 1
    Last Post: 06-15-2005, 03:39 AM
  4. Unknown Memory Leak in Init() Function
    By CodeHacker in forum Windows Programming
    Replies: 3
    Last Post: 07-09-2004, 09:54 AM
  5. Trouble writing to file
    By Fyodorox in forum C++ Programming
    Replies: 7
    Last Post: 05-06-2002, 06:09 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21