1

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

#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
4

1 回答 1

3

编辑:crypt_r()在 OS X 上不可用。

原答案:

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

#define _GNU_SOURCE
#include <crypt.h>

简单地写

#include <unistd.h>

为了访问该crypt()功能。

于 2012-12-26T20:04:12.167 回答