]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
lib/path: rename functions to be more explicit
authorKarel Zak <kzak@redhat.com>
Mon, 5 Nov 2012 11:23:55 +0000 (12:23 +0100)
committerKarel Zak <kzak@redhat.com>
Fri, 23 Nov 2012 13:58:21 +0000 (14:58 +0100)
 ... and to have names compatible with lib/sysfs.c

Signed-off-by: Karel Zak <kzak@redhat.com>
include/path.h
lib/path.c
sys-utils/chcpu.c
sys-utils/lscpu.c

index 3dfd5179423b57d400d7ca0e62a36aa6e3a5bebc..cefaaa0a469787fc26d0997dc456c3dd67e36790 100644 (file)
@@ -5,11 +5,11 @@
 
 extern FILE *path_fopen(const char *mode, int exit_on_err, const char *path, ...)
                        __attribute__ ((__format__ (__printf__, 3, 4)));
-extern void path_getstr(char *result, size_t len, const char *path, ...)
+extern void path_read_str(char *result, size_t len, const char *path, ...)
                        __attribute__ ((__format__ (__printf__, 3, 4)));
-extern int path_writestr(const char *str, const char *path, ...)
+extern int path_write_str(const char *str, const char *path, ...)
                         __attribute__ ((__format__ (__printf__, 2, 3)));
-extern int path_getnum(const char *path, ...)
+extern int path_read_s32(const char *path, ...)
                       __attribute__ ((__format__ (__printf__, 1, 2)));
 extern int path_exist(const char *path, ...)
                      __attribute__ ((__format__ (__printf__, 1, 2)));
@@ -17,11 +17,11 @@ extern int path_exist(const char *path, ...)
 #ifdef HAVE_CPU_SET_T
 # include "cpuset.h"
 
-extern cpu_set_t *path_cpuset(int, const char *path, ...)
+extern cpu_set_t *path_read_cpuset(int, const char *path, ...)
                              __attribute__ ((__format__ (__printf__, 2, 3)));
-extern cpu_set_t *path_cpulist(int, const char *path, ...)
+extern cpu_set_t *path_read_cpulist(int, const char *path, ...)
                               __attribute__ ((__format__ (__printf__, 2, 3)));
-extern void path_setprefix(const char *);
+extern void path_set_prefix(const char *);
 #endif /* HAVE_CPU_SET_T */
 
 #endif /* UTIL_LINUX_PATH_H */
index 404eeeb240d176c73a4cfd5e04b42c7ac451e419..f4118ccd3c3ab693752012c9454eeb54b5f9455c 100644 (file)
@@ -1,10 +1,12 @@
 /*
- * Simple functions to access files.
+ * Simple functions to access files, paths maybe be globally prefixed by a
+ * global prefix to read data from alternative destination (e.g. /proc dump for
+ * regression tests).
  *
  * Taken from lscpu.c
  *
  * Copyright (C) 2008 Cai Qian <qcai@redhat.com>
- * Copyright (C) 2008 Karel Zak <kzak@redhat.com>
+ * Copyright (C) 2008-2012 Karel Zak <kzak@redhat.com>
  *
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
@@ -84,7 +86,7 @@ path_fopen(const char *mode, int exit_on_error, const char *path, ...)
 }
 
 void
-path_getstr(char *result, size_t len, const char *path, ...)
+path_read_str(char *result, size_t len, const char *path, ...)
 {
        FILE *fd;
        va_list ap;
@@ -103,7 +105,7 @@ path_getstr(char *result, size_t len, const char *path, ...)
 }
 
 int
-path_getnum(const char *path, ...)
+path_read_s32(const char *path, ...)
 {
        FILE *fd;
        va_list ap;
@@ -124,7 +126,7 @@ path_getnum(const char *path, ...)
 }
 
 int
-path_writestr(const char *str, const char *path, ...)
+path_write_str(const char *str, const char *path, ...)
 {
        int fd, result;
        va_list ap;
@@ -185,7 +187,7 @@ path_cpuparse(int maxcpus, int islist, const char *path, va_list ap)
 }
 
 cpu_set_t *
-path_cpuset(int maxcpus, const char *path, ...)
+path_read_cpuset(int maxcpus, const char *path, ...)
 {
        va_list ap;
        cpu_set_t *set;
@@ -198,7 +200,7 @@ path_cpuset(int maxcpus, const char *path, ...)
 }
 
 cpu_set_t *
-path_cpulist(int maxcpus, const char *path, ...)
+path_read_cpulist(int maxcpus, const char *path, ...)
 {
        va_list ap;
        cpu_set_t *set;
@@ -213,7 +215,7 @@ path_cpulist(int maxcpus, const char *path, ...)
 #endif /* HAVE_CPU_SET_T */
 
 void
-path_setprefix(const char *prefix)
+path_set_prefix(const char *prefix)
 {
        prefixlen = strlen(prefix);
        strncpy(pathbuf, prefix, sizeof(pathbuf));
index 0209fe9bf441b0c4641035ec2477e13cdd368ddb..da6f65887b26c9ab31cabc3c55110b37cf50e738 100644 (file)
@@ -83,7 +83,7 @@ static int cpu_enable(cpu_set_t *cpu_set, size_t setsize, int enable)
                        printf(_("CPU %d is not hot pluggable\n"), cpu);
                        continue;
                }
-               online = path_getnum(_PATH_SYS_CPU "/cpu%d/online", cpu);
+               online = path_read_s32(_PATH_SYS_CPU "/cpu%d/online", cpu);
                if ((online == 1) && (enable == 1)) {
                        printf(_("CPU %d is already enabled\n"), cpu);
                        continue;
@@ -93,9 +93,9 @@ static int cpu_enable(cpu_set_t *cpu_set, size_t setsize, int enable)
                        continue;
                }
                if (path_exist(_PATH_SYS_CPU "/cpu%d/configure", cpu))
-                       configured = path_getnum(_PATH_SYS_CPU "/cpu%d/configure", cpu);
+                       configured = path_read_s32(_PATH_SYS_CPU "/cpu%d/configure", cpu);
                if (enable) {
-                       rc = path_writestr("1", _PATH_SYS_CPU "/cpu%d/online", cpu);
+                       rc = path_write_str("1", _PATH_SYS_CPU "/cpu%d/online", cpu);
                        if ((rc == -1) && (configured == 0))
                                printf(_("CPU %d enable failed "
                                         "(CPU is deconfigured)\n"), cpu);
@@ -109,7 +109,7 @@ static int cpu_enable(cpu_set_t *cpu_set, size_t setsize, int enable)
                                         "(last enabled CPU)\n"), cpu);
                                continue;
                        }
-                       rc = path_writestr("0", _PATH_SYS_CPU "/cpu%d/online", cpu);
+                       rc = path_write_str("0", _PATH_SYS_CPU "/cpu%d/online", cpu);
                        if (rc == -1)
                                printf(_("CPU %d disable failed (%m)\n"), cpu);
                        else {
@@ -126,7 +126,7 @@ static int cpu_rescan(void)
 {
        if (!path_exist(_PATH_SYS_CPU_RESCAN))
                errx(EXIT_FAILURE, _("This system does not support rescanning of CPUs"));
-       if (path_writestr("1", _PATH_SYS_CPU_RESCAN) == -1)
+       if (path_write_str("1", _PATH_SYS_CPU_RESCAN) == -1)
                err(EXIT_FAILURE, _("Failed to trigger rescan of CPUs"));
        printf(_("Triggered rescan of CPUs\n"));
        return EXIT_SUCCESS;
@@ -138,11 +138,11 @@ static int cpu_set_dispatch(int mode)
                errx(EXIT_FAILURE, _("This system does not support setting "
                                     "the dispatching mode of CPUs"));
        if (mode == 0) {
-               if (path_writestr("0", _PATH_SYS_CPU_DISPATCH) == -1)
+               if (path_write_str("0", _PATH_SYS_CPU_DISPATCH) == -1)
                        err(EXIT_FAILURE, _("Failed to set horizontal dispatch mode"));
                printf(_("Successfully set horizontal dispatching mode\n"));
        } else {
-               if (path_writestr("1", _PATH_SYS_CPU_DISPATCH) == -1)
+               if (path_write_str("1", _PATH_SYS_CPU_DISPATCH) == -1)
                        err(EXIT_FAILURE, _("Failed to set vertical dispatch mode"));
                printf(_("Successfully set vertical dispatching mode\n"));
        }
@@ -165,7 +165,7 @@ static int cpu_configure(cpu_set_t *cpu_set, size_t setsize, int configure)
                        printf(_("CPU %d is not configurable\n"), cpu);
                        continue;
                }
-               current = path_getnum(_PATH_SYS_CPU "/cpu%d/configure", cpu);
+               current = path_read_s32(_PATH_SYS_CPU "/cpu%d/configure", cpu);
                if ((current == 1) && (configure == 1)) {
                        printf(_("CPU %d is already configured\n"), cpu);
                        continue;
@@ -181,13 +181,13 @@ static int cpu_configure(cpu_set_t *cpu_set, size_t setsize, int configure)
                        continue;
                }
                if (configure) {
-                       rc = path_writestr("1", _PATH_SYS_CPU "/cpu%d/configure", cpu);
+                       rc = path_write_str("1", _PATH_SYS_CPU "/cpu%d/configure", cpu);
                        if (rc == -1)
                                printf(_("CPU %d configure failed (%m)\n"), cpu);
                        else
                                printf(_("CPU %d configured\n"), cpu);
                } else {
-                       rc = path_writestr("0", _PATH_SYS_CPU "/cpu%d/configure", cpu);
+                       rc = path_write_str("0", _PATH_SYS_CPU "/cpu%d/configure", cpu);
                        if (rc == -1)
                                printf(_("CPU %d deconfigure failed (%m)\n"), cpu);
                        else
@@ -262,7 +262,7 @@ int main(int argc, char *argv[])
        if (maxcpus < 1)
                errx(EXIT_FAILURE, _("cannot determine NR_CPUS; aborting"));
        if (path_exist(_PATH_SYS_CPU_ONLINE))
-               onlinecpus = path_cpulist(maxcpus, _PATH_SYS_CPU_ONLINE);
+               onlinecpus = path_read_cpulist(maxcpus, _PATH_SYS_CPU_ONLINE);
        setsize = CPU_ALLOC_SIZE(maxcpus);
        cpu_set = CPU_ALLOC(maxcpus);
        if (!cpu_set)
index a111561dcb4830b0b53120220cf4526c34eb6a4d..a840548c0c752c9f744f82d71f1ea42f294c923c 100644 (file)
@@ -384,7 +384,7 @@ read_basicinfo(struct lscpu_desc *desc, struct lscpu_modifier *mod)
 
        if (path_exist(_PATH_SYS_SYSTEM "/cpu/kernel_max"))
                /* note that kernel_max is maximum index [NR_CPUS-1] */
-               maxcpus = path_getnum(_PATH_SYS_SYSTEM "/cpu/kernel_max") + 1;
+               maxcpus = path_read_s32(_PATH_SYS_SYSTEM "/cpu/kernel_max") + 1;
 
        else if (mod->system == SYSTEM_LIVE)
                /* the root is '/' so we are working with data from the current kernel */
@@ -398,7 +398,7 @@ read_basicinfo(struct lscpu_desc *desc, struct lscpu_modifier *mod)
        setsize = CPU_ALLOC_SIZE(maxcpus);
 
        if (path_exist(_PATH_SYS_SYSTEM "/cpu/possible")) {
-               cpu_set_t *tmp = path_cpulist(maxcpus, _PATH_SYS_SYSTEM "/cpu/possible");
+               cpu_set_t *tmp = path_read_cpulist(maxcpus, _PATH_SYS_SYSTEM "/cpu/possible");
                desc->ncpuspos = CPU_COUNT_S(setsize, tmp);
                cpuset_free(tmp);
        } else
@@ -408,19 +408,20 @@ read_basicinfo(struct lscpu_desc *desc, struct lscpu_modifier *mod)
 
        /* get mask for present CPUs */
        if (path_exist(_PATH_SYS_SYSTEM "/cpu/present")) {
-               desc->present = path_cpulist(maxcpus, _PATH_SYS_SYSTEM "/cpu/present");
+               desc->present = path_read_cpulist(maxcpus, _PATH_SYS_SYSTEM "/cpu/present");
                desc->ncpus = CPU_COUNT_S(setsize, desc->present);
        }
 
        /* get mask for online CPUs */
        if (path_exist(_PATH_SYS_SYSTEM "/cpu/online")) {
-               desc->online = path_cpulist(maxcpus, _PATH_SYS_SYSTEM "/cpu/online");
+               size_t setsize = CPU_ALLOC_SIZE(maxcpus);
+               desc->online = path_read_cpulist(maxcpus, _PATH_SYS_SYSTEM "/cpu/online");
                desc->nthreads = CPU_COUNT_S(setsize, desc->online);
        }
 
        /* get dispatching mode */
        if (path_exist(_PATH_SYS_SYSTEM "/cpu/dispatching"))
-               desc->dispatching = path_getnum(_PATH_SYS_SYSTEM "/cpu/dispatching");
+               desc->dispatching = path_read_s32(_PATH_SYS_SYSTEM "/cpu/dispatching");
        else
                desc->dispatching = -1;
 }
@@ -611,13 +612,13 @@ read_topology(struct lscpu_desc *desc, int num)
        if (!path_exist(_PATH_SYS_CPU "/cpu%d/topology/thread_siblings", num))
                return;
 
-       thread_siblings = path_cpuset(maxcpus, _PATH_SYS_CPU
+       thread_siblings = path_read_cpuset(maxcpus, _PATH_SYS_CPU
                                        "/cpu%d/topology/thread_siblings", num);
-       core_siblings = path_cpuset(maxcpus, _PATH_SYS_CPU
+       core_siblings = path_read_cpuset(maxcpus, _PATH_SYS_CPU
                                        "/cpu%d/topology/core_siblings", num);
        book_siblings = NULL;
        if (path_exist(_PATH_SYS_CPU "/cpu%d/topology/book_siblings", num)) {
-               book_siblings = path_cpuset(maxcpus, _PATH_SYS_CPU
+               book_siblings = path_read_cpuset(maxcpus, _PATH_SYS_CPU
                                            "/cpu%d/topology/book_siblings", num);
        }
 
@@ -683,7 +684,7 @@ read_polarization(struct lscpu_desc *desc, int num)
                return;
        if (!desc->polarization)
                desc->polarization = xcalloc(desc->ncpuspos, sizeof(int));
-       path_getstr(mode, sizeof(mode), _PATH_SYS_CPU "/cpu%d/polarization", num);
+       path_read_str(mode, sizeof(mode), _PATH_SYS_CPU "/cpu%d/polarization", num);
        if (strncmp(mode, "vertical:low", sizeof(mode)) == 0)
                desc->polarization[num] = POLAR_VLOW;
        else if (strncmp(mode, "vertical:medium", sizeof(mode)) == 0)
@@ -703,7 +704,7 @@ read_address(struct lscpu_desc *desc, int num)
                return;
        if (!desc->addresses)
                desc->addresses = xcalloc(desc->ncpuspos, sizeof(int));
-       desc->addresses[num] = path_getnum(_PATH_SYS_CPU "/cpu%d/address", num);
+       desc->addresses[num] = path_read_s32(_PATH_SYS_CPU "/cpu%d/address", num);
 }
 
 static void
@@ -713,7 +714,7 @@ read_configured(struct lscpu_desc *desc, int num)
                return;
        if (!desc->configured)
                desc->configured = xcalloc(desc->ncpuspos, sizeof(int));
-       desc->configured[num] = path_getnum(_PATH_SYS_CPU "/cpu%d/configure", num);
+       desc->configured[num] = path_read_s32(_PATH_SYS_CPU "/cpu%d/configure", num);
 }
 
 static int
@@ -752,7 +753,7 @@ read_cache(struct lscpu_desc *desc, int num)
                        int type, level;
 
                        /* cache type */
-                       path_getstr(buf, sizeof(buf),
+                       path_read_str(buf, sizeof(buf),
                                        _PATH_SYS_CPU "/cpu%d/cache/index%d/type",
                                        num, i);
                        if (!strcmp(buf, "Data"))
@@ -763,7 +764,7 @@ read_cache(struct lscpu_desc *desc, int num)
                                type = 0;
 
                        /* cache level */
-                       level = path_getnum(_PATH_SYS_CPU "/cpu%d/cache/index%d/level",
+                       level = path_read_s32(_PATH_SYS_CPU "/cpu%d/cache/index%d/level",
                                        num, i);
                        if (type)
                                snprintf(buf, sizeof(buf), "L%d%c", level, type);
@@ -773,14 +774,14 @@ read_cache(struct lscpu_desc *desc, int num)
                        ca->name = xstrdup(buf);
 
                        /* cache size */
-                       path_getstr(buf, sizeof(buf),
+                       path_read_str(buf, sizeof(buf),
                                        _PATH_SYS_CPU "/cpu%d/cache/index%d/size",
                                        num, i);
                        ca->size = xstrdup(buf);
                }
 
                /* information about how CPUs share different caches */
-               map = path_cpuset(maxcpus,
+               map = path_read_cpuset(maxcpus,
                                  _PATH_SYS_CPU "/cpu%d/cache/index%d/shared_cpu_map",
                                  num, i);
 
@@ -806,7 +807,7 @@ read_nodes(struct lscpu_desc *desc)
 
        /* information about how nodes share different CPUs */
        for (i = 0; i < desc->nnodes; i++)
-               desc->nodemaps[i] = path_cpuset(maxcpus,
+               desc->nodemaps[i] = path_read_cpuset(maxcpus,
                                        _PATH_SYS_SYSTEM "/node/node%d/cpumap",
                                        i);
 }
@@ -1338,7 +1339,7 @@ int main(int argc, char *argv[])
                        mod->mode = c == 'p' ? OUTPUT_PARSABLE : OUTPUT_READABLE;
                        break;
                case 's':
-                       path_setprefix(optarg);
+                       path_set_prefix(optarg);
                        mod->system = SYSTEM_SNAPSHOT;
                        break;
                case 'x':