confstrのヘルプ・マニュアル
日本語 英語
confstr --help
man confstr
CONFSTR(3) Linux Programmer’s Manual CONFSTR(3)
名前
confstr - コンフィグレーションに依存した文字列変数の取得
書式
#include
size_t confstr(int name, char *buf, size_t len);
glibc 向けの機能検査マクロの要件 (feature_test_macros(7) 参照):
getcwd(): _POSIX_C_SOURCE >= 2 || _XOPEN_SOURCE || _POSIX_SOURCE
説明
confstr() はコンフィグレーションに依存した文字列変数の値を取得する。
引 き数 name は、問い合わせ内容を表すシステム変数である。以下の変数がサ
ポートされている。
_CS_GNU_LIBC_VERSION (GNU C library 限定; glibc 2.3.2 以降)
そのシステムの GNU C ライブラリのバージョンを示す文字列 (例え ば
"glibc 2.3.4")。
_CS_GNU_LIBPTHREAD_VERSION (GNU C library 限定; glibc 2.3.2 以降)
そ の C ライブラリが提供している POSIX 実装を示す文字列 (例えば
"NPTL 2.3.4" や "linuxthreads-0.10")。
_CS_PATH
すべての POSIX.2 標準ユーティリティが見つかるような PATH の値。
buf が NULL でなく、かつ len が 0 でなければ confstr() は取得した文字列
の 内容を buf にコピーする。必要ならば長さは len - 1 文字に切り捨てられ
て、NULL バイト ('\0') で終端される。末尾が切り捨てられたかどうかを判定
するには、 confstr() の返り値を len と比較すればよい。
len が 0 で buf が NULL ならば、 confstr() は以下で定義された値 (訳注:
切り捨てる前の、取得した文字列の長さ) を返す。
返り値
name が有効なコンフィギュレーション変数の場合、 confstr() はその変数 の
値 全体を保持するのに必要であったバイト数を返す (文字列終端のヌルバイト
も含む)。この値は len より大きいこともある。この場合には、 buf に格納さ
れた値の末尾が切り詰められたことを意味する。
name が有効なコンフィギュレーション変数だが、変数が値を持っていない場合
、 confstr() は 0 を返す。 name が有効なコンフィグレーション変数に対 応
していなければ、 confstr() は 0 を返し、 errno に EINVAL を設定する。
エラー
EINVAL name の値が不正である。
準拠
POSIX.1-2001.
例
次の部分的なコードは、 POSIX.2 システムのユーティリティがあるパスを取得
するものである。
char *pathbuf;
size_t n;
n = confstr(_CS_PATH,NULL,(size_t) 0);
pathbuf = malloc(n);
if (pathbuf == NULL)
abort();
confstr(_CS_PATH, pathbuf, n);
関連項目
sh(1), exec(3), system(3)
GNU 2008-08-29 CONFSTR(3)
CONFSTR(3) Linux Programmer’s Manual CONFSTR(3)
NAME
confstr - get configuration dependent string variables
SYNOPSIS
#include
size_t confstr(int name, char *buf, size_t len);
Feature Test Macro Requirements for glibc (see feature_test_macros(7)):
getcwd(): _POSIX_C_SOURCE >= 2 || _XOPEN_SOURCE || _POSIX_SOURCE
DESCRIPTION
confstr() gets the value of configuration-dependent string variables.
The name argument is the system variable to be queried. The following
variables are supported:
_CS_GNU_LIBC_VERSION (GNU C library only; since glibc 2.3.2)
A string which identifies the GNU C library version on this sys-
tem (e.g, "glibc 2.3.4").
_CS_GNU_LIBPTHREAD_VERSION (GNU C library only; since glibc 2.3.2)
A string which identifies the POSIX implementation supplied by
this C library (e.g, "NPTL 2.3.4" or "linuxthreads-0.10").
_CS_PATH
A value for the PATH variable which indicates where all the
POSIX.2 standard utilities can be found.
If buf is not NULL and len is not zero, confstr() copies the value of
the string to buf truncated to len - 1 characters if necessary, with a
null byte ('\0') as terminator. This can be detected by comparing the
return value of confstr() against len.
If len is zero and buf is NULL, confstr() just returns the value as
defined below.
RETURN VALUE
If name is a valid configuration variable, confstr() returns the number
of bytes (including the terminating null byte) that would be required
to hold the entire value of that variable. This value may be greater
than len, which means that the value in buf is truncated.
If name is a valid configuration variable, but that variable does not
have a value, then confstr() returns 0. If name does not correspond to
a valid configuration variable, confstr() returns 0, and errno is set
to EINVAL.
ERRORS
EINVAL If the value of name is invalid.
CONFORMING TO
POSIX.1-2001.
EXAMPLE
The following code fragment determines the path where to find the
POSIX.2 system utilities:
char *pathbuf;
size_t n;
n = confstr(_CS_PATH,NULL,(size_t) 0);
pathbuf = malloc(n);
if (pathbuf == NULL)
abort();
confstr(_CS_PATH, pathbuf, n);
SEE ALSO
sh(1), exec(3), system(3)
COLOPHON
This page is part of release 3.22 of the Linux man-pages project. A
description of the project, and information about reporting bugs, can
be found at http://www.kernel.org/doc/man-pages/.
GNU 2008-08-29 CONFSTR(3)