在OS X上使用crypt_r [英] Using crypt_r on OS X
本文介绍了在OS X上使用crypt_r的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想使用在Mac OS X 10.8.2
的 crypt_r
功能 的#define _GNU_SOURCE
#包括LT&;&crypt.h GT;
产生
crypt.h:没有这样的文件或目录
我在哪里可以得到从crypt.h文件?还是我,包括错了?
编辑的问题 - 具体的例子
的#include<&unistd.h中GT;
#包括LT&;&stdlib.h中GT;诠释主(){
结构crypt_data *数据=(结构crypt_data *)malloc的(的sizeof(结构crypt_data));
字符* testhash;
testhash = crypt_r(字符串,SA,数据);
免费的(数据);
返回0;
}
产生
GCC test.c的-Wall
test.c的:在函数'主':
test.c的:5:错误:sizeof的不完全型'结构crypt_data无效申请
test.c的:7:警告:函数'crypt_r'的隐式声明
test.c的:7:警告:赋值时将整数指针,未作投
解决方案
编辑: crypt_r()
不可用在OS X
原来的答复:
中的内容< crypt.h>
在OS X上被处理< unistd.h中>
。所以,与其
的#define _GNU_SOURCE
#包括LT&;&crypt.h GT;
简单地写
的#include<&unistd.h中GT;
为了访问的crypt()
功能。
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.
这篇关于在OS X上使用crypt_r的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文