From: Karel Zak Date: Mon, 23 Oct 2017 13:45:01 +0000 (+0200) Subject: lib/path: make path_set_prefix() independent on cpu_set_t X-Git-Tag: v2.32-rc1~249 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=d182565be1515926c8eeda81452a4746d8b2a63d;p=thirdparty%2Futil-linux.git lib/path: make path_set_prefix() independent on cpu_set_t Signed-off-by: Karel Zak --- diff --git a/include/path.h b/include/path.h index ae36d7f4c9..4be01095cd 100644 --- a/include/path.h +++ b/include/path.h @@ -6,6 +6,10 @@ /* Returns a pointer to a static buffer which may be destroyed by any later path_* function call. NULL means error and errno will be set. */ +/* Returns: 0 on success, sets errno on error. */ +extern int path_set_prefix(const char *) + __attribute__((warn_unused_result)); + extern const char *path_get(const char *path, ...) __attribute__ ((__format__ (__printf__, 1, 2))); @@ -31,10 +35,5 @@ extern cpu_set_t *path_read_cpuset(int, const char *path, ...) extern cpu_set_t *path_read_cpulist(int, const char *path, ...) __attribute__ ((__format__ (__printf__, 2, 3))); -/* Returns: 0 on success, sets errno on error. */ -extern int path_set_prefix(const char *) - __attribute__((warn_unused_result)); - #endif /* HAVE_CPU_SET_T */ - #endif /* UTIL_LINUX_PATH_H */ diff --git a/lib/path.c b/lib/path.c index 79c1e7a681..e8cfa557af 100644 --- a/lib/path.c +++ b/lib/path.c @@ -35,6 +35,20 @@ static size_t prefixlen; static char pathbuf[PATH_MAX]; +int +path_set_prefix(const char *prefix) +{ + size_t len = strlen(prefix); + + if (len >= sizeof(pathbuf) - 1) { + errno = ENAMETOOLONG; + return -1; + } + prefixlen = len; + strcpy(pathbuf, prefix); + return 0; +} + static const char * path_vcreate(const char *path, va_list ap) { @@ -259,19 +273,4 @@ path_read_cpulist(int maxcpus, const char *path, ...) return set; } - -int -path_set_prefix(const char *prefix) -{ - size_t len = strlen(prefix); - - if (len >= sizeof(pathbuf) - 1) { - errno = ENAMETOOLONG; - return -1; - } - prefixlen = len; - strcpy(pathbuf, prefix); - return 0; -} - #endif /* HAVE_CPU_SET_T */