shishira
shishira

Reputation: 59

Why can't I open my txt file in Ubuntu?

I have created a txt file (named "output.txt") using c socket program. Its been created but i dont have the permission to open that txt file. while 2 days back when i executed my program i could open the output.txt file. why cant i open it now?

Permission for my output.txt file is

-r----x--t 1 root root 12288 Oct 19 10:24 output.txt

Code for creating it:

  new_sockfd = accept(sockfd,(struct sockaddr *)&client_address, &client_len);
     if (new_sockfd==-1) { perror("Connection Not Accepted!!"); return(1);}
     else 
         {
           printf("client is connected\n");
           log=open("output.txt",O_CREAT|O_RDWR|O_APPEND,777);

           do
              { 
                x1=read(new_sockfd, buffer1, 1024);
                x2=write(log,buffer1,x1);
              }
           while (x1>0);
           close(log);   
         }

      close(new_sockfd);  

Upvotes: 0

Views: 1624

Answers (2)

Iłya Bursov
Iłya Bursov

Reputation: 24146

looks like you've created file under root, but trying to read under ordinary user account, chmod to 0666 under root

this was because you have incorrect flags in open function, you have to set them as 0777 or 0666, 0 is obligatory

Upvotes: 1

Jim Balter
Jim Balter

Reputation: 16406

777

That's decimal. Change it to 0777 (octal).

Upvotes: 2

Related Questions