Using crypt_r on OS X

ぃ、小莉子 提交于 2019-12-11 10:36:52

问题


I want to use the crypt_r function on Mac OS X 10.8.2

#define _GNU_SOURCE
#include <crypt.h>

produces

crypt.h: No such file or directory

Where can I get the crypt.h file from? Or am I including it wrong?

Edited question - concrete example

#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;
}

produces

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:


Edit: crypt_r() is not available on OS X.

Original answer:

The contents of <crypt.h> on OS X is handled by <unistd.h>. So, instead of

#define _GNU_SOURCE
#include <crypt.h>

simply write

#include <unistd.h>

in order to access the crypt() function.



来源:https://stackoverflow.com/questions/14045543/using-crypt-r-on-os-x

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!