gpt4 book ai didi

c++ - 来自 OSX 应用程序的 Mkdir

转载 作者:太空宇宙 更新时间:2023-11-04 12:00:32 25 4
gpt4 key购买 nike

我是 OSX 开发的新手,我需要你的帮助。

我正在尝试使用我用 C++ 编写的 OSX 应用程序中的 mkdir 在/private/var/tmp 上创建文件夹。我在 OSX 10.6 上使用 XCode 3.2.6。该命令运行良好。该文件夹在路径/private/var/tmp 中创建。

这就是我在应用程序中所做的:mkdir(my_path, 0777);

但是我在文件夹的权限方面遇到了问题。用户可以修改文件夹(在里面创建另一个文件夹等),但不能修改“everyone”或“wheel”。

enter image description here

翻译:

  • 我 -> 我
  • Lecture et écriture -> Read and Write
  • 讲座系列 -> 只读

我尝试从终端创建文件夹,我输入 mkdir -m 777/private/var/tmp/test 并且文件夹 test 具有良好的权限:

enter image description here

翻译:

  • 我 -> 我
  • Lecture et écriture -> Read and Write

我的问题是,我怎样才能对文件夹和我的 OSX 应用程序授予写入权限。

谢谢。

最佳答案

根据 SUIS

The mkdir() function shall create a new directory with name path. The file permission bits of the new directory shall be initialized from mode. These file permission bits of the mode argument shall be modified by the process' file creation mask.

原因是默认umask为您的系统定义。

所以你只需要更新umask在调用 mkdir 或调用 chown 之前从您的进程更新已创建文件夹的属性。

关于c++ - 来自 OSX 应用程序的 Mkdir,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14315255/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com