asprintf

Substitute or workaround for asprintf on AIX

眉间皱痕 提交于 2019-12-21 03:43:10
问题 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. 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. Is there a way I can use the koders.com example or some other code to "fake" asprintf? Can I just include the asprintf

Is `asprintf` thread-safe?

情到浓时终转凉″ 提交于 2019-12-07 03:28:46
问题 Is the GNU function asprintf (print to allocated string) thread-safe? (IIC, basically, this boils down to the question whether malloc is thread-safe.) Consider the example code: #define _GNU_SOURCE #include <stdio.h> #include "getValue.h" char * getValue(int key) { char * value; asprintf(&value, "%d", key); // TODO: No error handling! // If memory allocation wasn't possible, or some other error occurs, these functions will // return -1, and the contents of strp is undefined. return value; }

Is `asprintf` thread-safe?

倾然丶 夕夏残阳落幕 提交于 2019-12-05 07:47:15
Is the GNU function asprintf (print to allocated string) thread-safe? (IIC, basically, this boils down to the question whether malloc is thread-safe.) Consider the example code: #define _GNU_SOURCE #include <stdio.h> #include "getValue.h" char * getValue(int key) { char * value; asprintf(&value, "%d", key); // TODO: No error handling! // If memory allocation wasn't possible, or some other error occurs, these functions will // return -1, and the contents of strp is undefined. return value; } Here, I do not touch any global variables. What if my getValue gets called in concurrent threads? No bad

Substitute or workaround for asprintf on AIX

有些话、适合烂在心里 提交于 2019-12-03 11:11:20
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. 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. 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 (char **resultp, const char *format,

Using asprintf() on windows

时光怂恿深爱的人放手 提交于 2019-11-30 15:45:57
问题 I have written a C program which works perfectly on linux, but when I compile it on windows, it gives me an error saying that asprintf() is undefined. It should be a part of the stdio library but it seems that many compilers do not include it. Which compiler can I use for windows which will allow me to use the asprintf() function? I have tried multiple compilers and none seem to define it so far. 回答1: The asprintf() function is not part of the C language and it is not available on all

Using asprintf() on windows

陌路散爱 提交于 2019-11-30 14:40:35
I have written a C program which works perfectly on linux, but when I compile it on windows, it gives me an error saying that asprintf() is undefined. It should be a part of the stdio library but it seems that many compilers do not include it. Which compiler can I use for windows which will allow me to use the asprintf() function? I have tried multiple compilers and none seem to define it so far. The asprintf() function is not part of the C language and it is not available on all platforms. The fact that Linux has it is unusual . You can write your own using _vscprintf and _vsprintf_s . int

Why use asprintf() instead of sprintf()?

空扰寡人 提交于 2019-11-27 17:12:50
I'm having a hard time understanding why you would need asprintf. Here in the manual it says The functions asprintf() and vasprintf() are analogs of sprintf(3) and vsprintf(3) , except that they allocate a string large enough to hold the output including the terminating null byte, and return a pointer to it via the first argument. This pointer should be passed to free(3) to release the allocated storage when it is no longer needed. So here is the example that I'm trying to understand: asprintf(&buffer, "/bin/echo %s is cool", getenv("USER")); What's the difference if the buffer allocates a

Why use asprintf() instead of sprintf()?

安稳与你 提交于 2019-11-26 18:52:58
问题 I'm having a hard time understanding why you would need asprintf. Here in the manual it says The functions asprintf() and vasprintf() are analogs of sprintf(3) and vsprintf(3) , except that they allocate a string large enough to hold the output including the terminating null byte, and return a pointer to it via the first argument. This pointer should be passed to free(3) to release the allocated storage when it is no longer needed. So here is the example that I'm trying to understand: