问题描述
我移植的C语言库到OSX它没有给我太大的头痛直到现在。在接下来的功能:
I'm porting a C library to OSX which haven't given me much of a headache until now. In the next function:
int createDirectory( char *directory ){
int error;
error = mkdir(directory, S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH);
if( error < 0 ){
if( errno != EEXIST ){
return errno;
}
}
return error;
}
不管是什么目录
是的mkdir()
总是失败, EPERM
(不允许操作)。我不知道如果X code可执行程序是沙箱或者如果我失去了一些东西,但我每次传递给函数路径发生故障。
No matter what directory
is, mkdir()
always fails with EPERM
(Operation not permitted). I'm not sure if the xcode executable is sandboxed or if I'm missing something, but every path I pass to the function fails.
我试着从终端到MKDIR并没有问题正在创建的文件夹,所以我不知道问题出在哪里。此功能在Linux和Solaris正常工作。
I've tried to mkdir from the terminal and the folders are created without a problem, so I'm not sure where the problem is. This function works fine in Linux and Solaris.
示例路径:
"~/Library/Application\\ Support/myApp"
"~/Desktop/myApp"
第一个是一个目录图书馆应营造一个实际的例子。
The first one is an actual example of a directory the library should create.
推荐答案
OSX不展开'〜'
字符作为庆典
做(尽管它使用庆典
)。
OSX does not expand the '~'
character as bash
does (although it uses bash
).
由于这一方案,在运行 / tmp目录
:
Given this program, running in /tmp
:
#include <stdlib.h>
#include <sys/stat.h>
#include <stdio.h>
int main(void)
{
char *given = "~/Library";
char result[1024];
char *s;
mkdir("~", 0755);
mkdir("~/Library", 0755);
if ((s = realpath(given, result)) != 0) {
printf ("%s\n", s);
} else {
perror("realpath");
}
return 0;
}
我得到OSX这个结果:
I get this result on OSX:
/private/tmp/~/Library
我得到的Linux(Debian的),这样的结果,以及从Solaris 10:
I get this result on Linux (Debian) as well as with Solaris 10:
/tmp/~/Library
作为的 Why不波浪号(〜)双引号内扩大? 的,这本来是一个 CSH
的壳的功能, 庆典
前不久(1994年援引页)。它没有在任何给定系统的运行时库的实施
As noted in Why doesn't the tilde (~) expand inside double quotes?, this was originally a csh
shell feature which bash
incorporated long ago (citing a page from 1994). It is not implemented in any of the given systems' runtime libraries.
这篇关于在OSX的mkdir失败EPERM的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!