Linux系统调用函数vasprintf

版权声明:欢迎转载,不必客气。 https://blog.csdn.net/CSDN_FengXingwei/article/details/83749369

Name

asprintf, vasprintf - print to allocated string
打印到分配的字符串

Synopsis

#include <stdio.h>
int asprintf(char **strp, const char *fmt, ...);
int vasprintf(char **strp, const char *fmt, va_list ap);

Description

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.

函数asprintf()和vasprintf()是sprintf(3)和vsprintf(3)的类似函数,除了它们分配一个足够大的字符串来保存包括终止空字节的输出,并通过第一个参数返回指向它的指针。 应该将此指针传递给free(3)以在不再需要时释放已分配的存储。

Return Value

When successful, these functions return the number of bytes printed, just like sprintf(3). If memory allocation wasn’t possible, or some other error occurs, these functions will return -1, and the contents of strp is undefined.

成功时,这些函数返回打印的字节数,就像sprintf(3)一样。 如果无法进行内存分配或发生其他错误,则这些函数将返回-1,并且strp的内容未定义。

Conforming to

These functions are GNU extensions, not in C or POSIX. They are also available under *BSD. The FreeBSD implementation sets strp to NULL on error.

这些函数是GNU扩展,而不是C或POSIX。 它们也可以在* BSD下获得。 FreeBSD实现在出错时将strp设置为NULL。

猜你喜欢

转载自blog.csdn.net/CSDN_FengXingwei/article/details/83749369
今日推荐