asprintf

Section: C Library Functions (3)
Updated: 2026-02-08
Index JM Home Page roff page
 

名前

asprintf, vasprintf - 文字列を割り当ててそれに出力する  

ライブラリ

標準 C ライブラリ (libc,~-lc)  

書式

#define _GNU_SOURCE         /* feature_test_macros(7) 参照 */
#include <stdio.h>

int asprintf(char **restrict strp, const char *restrict fmt, ...);
int vasprintf(char **restrict strp, const char *restrict fmt,
              va_list ap);
 

説明

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 ('\0'), 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.  

返り値

When successful, these functions return the number of bytes printed, just like sprintf(3). On error, -1 is returned, errno is set to indicate the error, and the contents of strp are undefined.  

エラー

See sprintf(3) and malloc(3).  

属性

この節で使用されている用語の説明については、 attributes(7) を参照。
インターフェース属性値
asprintf(), vasprintf() Thread safetyMT-Safe locale
 

バージョン

The FreeBSD implementation sets strp to NULL on error.  

標準規格

GNU, BSD.  

関連項目

free(3), malloc(3), printf(3)


 

Index

名前
ライブラリ
書式
説明
返り値
エラー
属性
バージョン
標準規格
関連項目

This document was created by man2html, using the manual pages.