简体   繁体   中英

Using crypt_r on OS X

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

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM