gpt4 book ai didi

crypt_r() 例子?

转载 作者:行者123 更新时间:2023-12-04 11:14:36 24 4
gpt4 key购买 nike

谁能给我一个关于如何使用函数 crypt_r() 的例子吗?

在手册页中,不清楚返回的 char * 字符串是指向函数本身内部(在堆中)分配的内存块,还是仍然指向静态内存,如 crypt()?

最佳答案

来自GNU手册:

The crypt_r function does the same thing as crypt, but takes an extraparameter which includes space for its result (among other things), soit can be reentrant. data->initialized must be cleared to zero beforethe first time crypt_r is called.

Kernel.org提供更多细节:

crypt_r() is a reentrant version of crypt(). The structure pointed toby data is used to store result data and bookkeeping information.Other than allocating it, the only thing that the caller should dowith this structure is to set data->initialized to zero before thefirst call to crypt_r().

cryptcrypt_r 都返回指向加密密码的指针。当然,如果您使用 crypt_r,那么内存将位于您传递的 crypt_data 中。

根据要求编辑示例:

struct crypt_data data;
data.initialized = 0;

char *enc = crypt_r(key, salt, &data);
printf("EncryptedL %s\n", enc);

关于crypt_r() 例子?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9335777/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com