Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/c/59.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用C查找文件权限_C_File_Permissions_Copy_Posix - Fatal编程技术网

使用C查找文件权限

使用C查找文件权限,c,file,permissions,copy,posix,C,File,Permissions,Copy,Posix,如何使用C查找文件的权限 我正在制作一个文件复制程序,除了它不会复制新文件上的文件权限外,一切都正常 现在我正在使用fcntl.h和open()和create()打开文件并生成目标文件,但它正在丢失权限 我希望有一个命令可以将文件权限读入0644或0777这样的数字,然后在creat()中使用该数字生成该文件。有这样的命令吗 编辑 谢谢你的帮助,我用下面的代码得到了它 struct stat status; mode_t permissions; stat("path_to_file", &am

如何使用C查找文件的权限

我正在制作一个文件复制程序,除了它不会复制新文件上的文件权限外,一切都正常

现在我正在使用fcntl.h和open()和create()打开文件并生成目标文件,但它正在丢失权限

我希望有一个命令可以将文件权限读入0644或0777这样的数字,然后在creat()中使用该数字生成该文件。有这样的命令吗

编辑 谢谢你的帮助,我用下面的代码得到了它

struct stat status;
mode_t permissions;
stat("path_to_file", &status);
permissions = status.st_mode;' 
然后在create()中使用权限

使用

上面的链接还将为您提供示例代码

/* Print out type, permissions, and number of links. */
printf("%10.10s", sperm (statbuf.st_mode));
printf("%4d", statbuf.st_nlink);
stat()

请注意,您的
umask()
()将对实际使用的权限产生影响。

Look


或者呢?谢谢,我用你的例子使用了下面的代码结构状态;模式权限;统计(argV[i]、&状态);权限=状态。st_模式;'然后在create()中使用权限;
   struct stat sb;
   mode_t file_permision; // read file permission before copy

   if (stat("source_file_name", &sb) == -1) {
        exit(EXIT_FAILURE);
    }

 file_permision = sb.st_mode;

//Then create new file

 creat("destination_file_name", file_permision );