在OSX的mkdir失败EPERM [英] mkdir on OSX fails with EPERM

查看:174
本文介绍了在OSX的mkdir失败EPERM的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我移植的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

作为的 <著名href=\"http://unix.stackexchange.com/questions/151850/why-doesnt-the-tilde-expand-inside-double-quotes\">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的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆