在OS X上使用crypt_r

时间:2012-12-26 19:56:03

标签: c multithreading gnu crypt

我想在Mac OS X 10.8.2上使用crypt_r功能

#define _GNU_SOURCE
#include <crypt.h>

生成

crypt.h: No such file or directory

我在哪里可以获取crypt.h文件?或者我错了吗?

编辑问题 - 具体示例

#include <unistd.h>
#include <stdlib.h>

int main(){
    struct crypt_data * data = (struct crypt_data *) malloc(sizeof(struct crypt_data));
    char * testhash;
    testhash = crypt_r("string", "sa", data);
    free(data);
    return 0;
}

产生

gcc test.c -Wall
test.c: In function ‘main’:
test.c:5: error: invalid application of ‘sizeof’ to incomplete type ‘struct crypt_data’ 
test.c:7: warning: implicit declaration of function ‘crypt_r’
test.c:7: warning: assignment makes pointer from integer without a cast

1 个答案:

答案 0 :(得分:2)

编辑:OS X上无法使用crypt_r()

原始答案:

OS X上<crypt.h>的内容由<unistd.h>处理。所以,而不是

#define _GNU_SOURCE
#include <crypt.h>

简单地写

#include <unistd.h>

以访问crypt()功能。