0

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);  
4

2 に答える 2

2

777

それは10進数です。0777 (8 進数) に変更します。

于 2013-10-19T05:22:37.680 に答える
1

ルートの下にファイルを作成したように見えますが、通常のユーザー アカウントで読み込もうとすると、ルートの下で 0666 に chmod します

これは、open 関数に誤ったフラグがあるためです。それらを 0777 または 0666 として設定する必要があります。0 は必須です。

于 2013-10-19T05:23:36.080 に答える