|
Document of c-modernization-kit (funcman) 1.0.0
|
共有ライブラリ自身 (.so/.dll) の絶対パスと basename (パスなし・拡張子なし) を取得します。 More...
#include <funcman.h>#include <dlfcn.h>#include <limits.h>#include <stddef.h>#include <stdint.h>#include <stdio.h>#include <stdlib.h>#include <string.h>#include <unistd.h>Go to the source code of this file.
Typedefs | |
| typedef enum get_lib_info_status_t | get_lib_info_status_t |
| 内部関数の戻り値(ステータス)。 | |
Enumerations | |
| enum | get_lib_info_status_t { MYLIB_OK = 0 , MYLIB_EINVAL = -1 , MYLIB_ENOBUFS = -2 , MYLIB_EFAIL = -3 } |
| 内部関数の戻り値(ステータス)。 More... | |
Functions | |
| static get_lib_info_status_t | copy_str (char *dst, size_t dst_sz, const char *src) |
| 文字列を安全にコピーします (UTF-8 想定だが単なる byte 列として扱う)。 | |
| static const char * | get_ilename_part (const char *path) |
| パス文字列からファイル名部分 (最後の区切り文字以降) を返します。 | |
| static void | strip_extension_inplace (char *s) |
| 拡張子を取り除きます (その場で書き換え)。 | |
| static get_lib_info_status_t | get_self_path_posix (char *out_path, size_t out_path_sz, const void *func_addr) |
| .so 自身の絶対パスを取得します (Linux/Unix)。 | |
| int | get_lib_path (char *out_path, const size_t out_path_sz, const void *func_addr) |
| 指定した関数が所属する共有ライブラリ (.so/.dll) の絶対パスを取得します。 | |
| int | get_lib_basename (char *out_basename, const size_t out_basename_sz, const void *func_addr) |
| 指定した関数が所属する共有ライブラリ (.so/.dll) の basename (パスなし・拡張子なし) を取得します。 | |
共有ライブラリ自身 (.so/.dll) の絶対パスと basename (パスなし・拡張子なし) を取得します。
Linux(gcc) では dladdr() で共有オブジェクトを特定し、realpath() で可能な限り正規化 (絶対化・symlink 解決) します。 Windows(MSVC) では GetModuleHandleEx() で DLL の HMODULE を得て、GetModuleFileNameW() でパスを取得します。
Definition in file get_lib_info.c.
| typedef enum get_lib_info_status_t get_lib_info_status_t |
内部関数の戻り値(ステータス)。
内部関数の戻り値(ステータス)。
| Enumerator | ||
|---|---|---|
| MYLIB_OK | 0 | 成功 |
| MYLIB_EINVAL | -1 | 引数不正 (NULL、サイズ0など) |
| MYLIB_ENOBUFS | -2 | バッファ不足 (出力が収まらない) |
| MYLIB_EFAIL | -3 | その他の失敗 (取得不能、OS API 失敗など) |
Definition at line 47 of file get_lib_info.c.
|
static |
文字列を安全にコピーします (UTF-8 想定だが単なる byte 列として扱う)。
| [out] | dst | 出力バッファ。 |
| [in] | dst_sz | 出力バッファサイズ[byte]。 |
| [in] | src | 入力文字列 (NULL 終端)。 |
Definition at line 69 of file get_lib_info.c.
References MYLIB_EINVAL, MYLIB_ENOBUFS, and MYLIB_OK.
Referenced by get_lib_basename(), and get_self_path_posix().
|
static |
パス文字列からファイル名部分 (最後の区切り文字以降) を返します。
| [in] | path | パス。 |
Definition at line 94 of file get_lib_info.c.
Referenced by get_lib_basename().
|
static |
拡張子を取り除きます (その場で書き換え)。
| [in,out] | s | 対象文字列 (NULL 終端)。 |
Definition at line 120 of file get_lib_info.c.
Referenced by get_lib_basename().
|
static |
.so 自身の絶対パスを取得します (Linux/Unix)。
dladdr() に指定された関数アドレスを渡して所属共有オブジェクトを取得し、
realpath() で可能な限り絶対化・正規化します。
| [out] | out_path | 出力 (UTF-8、NULL 終端)。 |
| [in] | out_path_sz | 出力バッファサイズ[byte]。 |
| [in] | func_addr | 所属モジュールを特定するための関数アドレス。 |
Definition at line 258 of file get_lib_info.c.
References copy_str(), MYLIB_EFAIL, and MYLIB_EINVAL.
Referenced by get_lib_path().
| int get_lib_path | ( | char * | out_path, |
| const size_t | out_path_sz, | ||
| const void * | func_addr ) |
指定した関数が所属する共有ライブラリ (.so/.dll) の絶対パスを取得します。
| [out] | out_path | 出力バッファ。 |
| [in] | out_path_sz | 出力バッファサイズ[byte]。 |
| [in] | func_addr | 所属モジュールを特定するための関数アドレス。 |
Definition at line 313 of file get_lib_info.c.
References get_self_path_posix(), and MYLIB_OK.
Referenced by get_lib_basename().
| int get_lib_basename | ( | char * | out_basename, |
| const size_t | out_basename_sz, | ||
| const void * | func_addr ) |
指定した関数が所属する共有ライブラリ (.so/.dll) の basename (パスなし・拡張子なし) を取得します。
Linux の .so.1.2.3 のようなバージョン付きは ".so." より前を basename とみなします。
| [out] | out_basename | 出力バッファ。 |
| [in] | out_basename_sz | 出力バッファサイズ[byte]。 |
| [in] | func_addr | 所属モジュールを特定するための関数アドレス。 |
Definition at line 331 of file get_lib_info.c.
References copy_str(), get_ilename_part(), get_lib_path(), MYLIB_EFAIL, MYLIB_EINVAL, MYLIB_OK, and strip_extension_inplace().