问题描述
我想在AIX上构建Python-的Kerberos。 kerberospw.c用来asprintf一个电话,但是从谷歌告诉我,asprintf不AIX上存在。
I'm trying to build python-kerberos on AIX. kerberospw.c uses a call to asprintf, but from what Google is telling me, asprintf does not exist on AIX.
我看了<一个href=\"http://www.koders.com/c/fidAA9B130D588302673A28B568430A83131B7734C0.aspx?s=windows.h\">http://www.koders.com/c/fidAA9B130D588302673A28B568430A83131B7734C0.aspx?s=windows.h,它看起来像我可以创建一个替身asprintf,但我不知道这会去还是我怎么会#包括它kerberospw.c。
I saw http://www.koders.com/c/fidAA9B130D588302673A28B568430A83131B7734C0.aspx?s=windows.h, which looks like I could create a stand-in asprintf, but I don't know where this would go or how I would #include it in kerberospw.c.
有没有一种方法我可以使用koders.com例子或其他一些code到假asprintf?可我只是包括asprintf功能,如图kerberospw.c?我不是一个C codeR,但
Is there a way I can use the koders.com example or some other code to "fake" asprintf? Can I just include the asprintf function as shown in kerberospw.c? I am not a C coder, but
asprintf(字符** resultp,为const char *格式,...)
看起来并不像一个有效的签名我在最后的点。从kerberospw.c相关线路低于
doesn't look like a valid signature to me with the dots at the end. The relevant line from kerberospw.c is below
asprintf(安培;消息时,%* S:%*的,
(INT)result_ code_string.length,结果
(字符*)result_ code_string.data,结果
(INT)result_string.length,结果
(字符*)result_string.data);
我知道我可以联系的python-的Kerberos的作者,但)我认为这将是有帮助的一个潜在的补丁,如果我这样做了,并且b)有可能是其他的软件我碰到一个使用asprintf运行,这将是很好有一个解决办法。
I realize I could contact the author of python-kerberos, but a) I think it would be helpful to have a potential patch if I did so, and b) there might be other software I run across that uses asprintf, and it would be nice to have a workaround.
推荐答案
的 asprintf
是一个变化的的printf
系列的分配缓冲区,以保持格式化字符串内存,并返回它的功能。它与参数数量可变的(因此 ...
在有效C code中的声明)的函数。你可以在这里找到描述。
The asprintf
is a variation of the printf
family of function that allocate a buffer to hold the memory for the formatted string and return it. It is a function with a variable number of argument (hence the ...
in the declaration that is valid C code). You can find a description here.
可以相对容易地重新实现,如果 vsnprintf
运行正常(即返回一个错误,如果缓冲区太小,无法容纳格式的字符串)。
It can be reimplemented relatively easily if the vsnprintf
is functioning correctly (ie, return an error if the buffer is too small to hold the formatted string).
下面就是这样实现:
#include <stdarg.h>
int asprintf(char **ret, const char *format, ...)
{
va_list ap;
*ret = NULL; /* Ensure value can be passed to free() */
va_start(ap, format);
int count = vsnprintf(NULL, 0, format, ap);
va_end(ap);
if (count >= 0)
{
char* buffer = malloc(count + 1);
if (buffer == NULL)
return -1;
va_start(ap, format);
count = vsnprintf(buffer, count + 1, format, ap);
va_end(ap);
if (count < 0)
{
free(buffer);
return count;
}
*ret = buffer;
}
return count;
}
这篇关于替代或解决方法AIX上asprintf的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!