1

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
kadrian
  • 4,761
  • 8
  • 39
  • 61
  • even with both I get the file not found error. --Edit: Answer to who ever deleted the comment: "#define _XOPEN_SOURCE is also required". – kadrian Dec 26 '12 at 19:59
  • actually, not on OS X, sorry. See my answer. –  Dec 26 '12 at 20:05

1 Answers1

3

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.

  • Then I get: `warning: implicit declaration of function ‘crypt_r’` – kadrian Dec 26 '12 at 20:10
  • @kadrian You should not. What version of OS X and which compiler are you using? –  Dec 26 '12 at 20:11
  • gcc: `i686-apple-darwin11-llvm-gcc-4.2 (GCC) 4.2.1 (Based on Apple Inc. build 5658) (LLVM build 2336.11.00)` and Mac OS X 10.8.2 (should be up to date) – kadrian Dec 26 '12 at 20:18
  • @kadrian for me, the same compiler and OS X 10.7.5 doesn't produce any warning. –  Dec 26 '12 at 20:21
  • @kadrian Sorry, overseen that. I wrote `crypt()` and not `crypt_r()`. `crypt_r()` is unavailable on OS X. –  Dec 26 '12 at 20:37
  • Ok, and no way to get it? Damn OS X! ;-) – kadrian Dec 26 '12 at 20:44
  • @kadrian I think you can try compiling it from the GNU libc sources. (would you be as kind as to accept my answer?) –  Dec 26 '12 at 20:45