summaryrefslogtreecommitdiffstats
path: root/schedutils
diff options
context:
space:
mode:
authorDavidlohr Bueso2010-11-16 14:47:35 +0100
committerKarel Zak2010-11-23 21:06:49 +0100
commit8abcf2900297c6d53ead867c42f7c1688e8d52ca (patch)
tree77e2d666cd76d9d4c37e1c1864415c1e52d37926 /schedutils
parentlibblkid: cache is incorrectly revalidated (diff)
downloadkernel-qcow2-util-linux-8abcf2900297c6d53ead867c42f7c1688e8d52ca.tar.gz
kernel-qcow2-util-linux-8abcf2900297c6d53ead867c42f7c1688e8d52ca.tar.xz
kernel-qcow2-util-linux-8abcf2900297c6d53ead867c42f7c1688e8d52ca.zip
lib: [strutils] general purpose string handling functions
This patch replaces a few functions used throughout the source: * Renames getnum (from schedutils) to strtol_or_err * Moves strtosize (from lib/strtosize.c) * Moves xstrncpy (from include/xstrncpy.h) * Adds strnlen, strnchr and strndup if not available (remove it from libmount utils) A few Makefile.am files were modified to compile accordingly along with trivial renaming in schedutils source code. Signed-off-by: Davidlohr Bueso <dave@gnu.org>
Diffstat (limited to 'schedutils')
-rw-r--r--schedutils/Makefile.am2
-rw-r--r--schedutils/chrt.c6
-rw-r--r--schedutils/ionice.c12
-rw-r--r--schedutils/schedutils.c34
-rw-r--r--schedutils/schedutils.h7
-rw-r--r--schedutils/taskset.c4
6 files changed, 12 insertions, 53 deletions
diff --git a/schedutils/Makefile.am b/schedutils/Makefile.am
index c83e5eaff..dc3317537 100644
--- a/schedutils/Makefile.am
+++ b/schedutils/Makefile.am
@@ -2,7 +2,7 @@ include $(top_srcdir)/config/include-Makefile.am
if BUILD_SCHEDUTILS
-srcs_common = schedutils.c schedutils.h
+srcs_common = $(top_srcdir)/lib/strutils.c
usrbin_exec_PROGRAMS = chrt
dist_man_MANS = chrt.1
diff --git a/schedutils/chrt.c b/schedutils/chrt.c
index 811eb200e..bd7070cca 100644
--- a/schedutils/chrt.c
+++ b/schedutils/chrt.c
@@ -32,7 +32,7 @@
#include "c.h"
#include "nls.h"
-#include "schedutils.h"
+#include "strutils.h"
/* the SCHED_BATCH is supported since Linux 2.6.16
* -- temporary workaround for people with old glibc headers
@@ -240,7 +240,7 @@ int main(int argc, char *argv[])
break;
case 'p':
errno = 0;
- pid = getnum(argv[argc - 1], _("failed to parse pid"));
+ pid = strtol_or_err(argv[argc - 1], _("failed to parse pid"));
break;
case 'r':
policy = SCHED_RR;
@@ -268,7 +268,7 @@ int main(int argc, char *argv[])
}
errno = 0;
- priority = getnum(argv[optind], _("failed to parse priority"));
+ priority = strtol_or_err(argv[optind], _("failed to parse priority"));
#ifdef SCHED_RESET_ON_FORK
/* sanity check */
diff --git a/schedutils/ionice.c b/schedutils/ionice.c
index 34132f071..78c9f0d3c 100644
--- a/schedutils/ionice.c
+++ b/schedutils/ionice.c
@@ -18,7 +18,7 @@
#include "nls.h"
-#include "schedutils.h"
+#include "strutils.h"
static int tolerant;
@@ -105,15 +105,15 @@ int main(int argc, char *argv[])
while ((c = getopt(argc, argv, "+n:c:p:th")) != EOF) {
switch (c) {
case 'n':
- ioprio = getnum(optarg, _("failed to parse class data"));
+ ioprio = strtol_or_err(optarg, _("failed to parse class data"));
set |= 1;
break;
case 'c':
- ioclass = getnum(optarg, _("failed to parse class"));
+ ioclass = strtol_or_err(optarg, _("failed to parse class"));
set |= 2;
break;
case 'p':
- pid = getnum(optarg, _("failed to parse pid"));
+ pid = strtol_or_err(optarg, _("failed to parse pid"));
break;
case 't':
tolerant = 1;
@@ -147,7 +147,7 @@ int main(int argc, char *argv[])
ioprio_print(pid);
for(; argv[optind]; ++optind) {
- pid = getnum(argv[optind], _("failed to parse pid"));
+ pid = strtol_or_err(argv[optind], _("failed to parse pid"));
ioprio_print(pid);
}
} else {
@@ -156,7 +156,7 @@ int main(int argc, char *argv[])
for(; argv[optind]; ++optind)
{
- pid = getnum(argv[optind], _("failed to parse pid"));
+ pid = strtol_or_err(argv[optind], _("failed to parse pid"));
ioprio_setpid(pid, ioprio, ioclass);
}
}
diff --git a/schedutils/schedutils.c b/schedutils/schedutils.c
deleted file mode 100644
index 9d6051ba1..000000000
--- a/schedutils/schedutils.c
+++ /dev/null
@@ -1,34 +0,0 @@
-/*
- * Copyright (C) 2010 Karel Zak <kzak@redhat.com>
- *
- * Released under the terms of the GNU General Public License version 2
- *
- */
-#include <stdio.h>
-#include <stdlib.h>
-#include <errno.h>
-#include <err.h>
-
-#include "nls.h"
-
-long getnum(const char *str, const char *errmesg)
-{
- long num;
- char *end = NULL;
-
- if (str == NULL || *str == '\0')
- goto err;
- errno = 0;
- num = strtol(str, &end, 10);
-
- if (errno || (end && *end))
- goto err;
-
- return num;
-err:
- if (errno)
- err(EXIT_FAILURE, "%s: '%s'", errmesg, str);
- else
- errx(EXIT_FAILURE, "%s: '%s'", errmesg, str);
- return 0;
-}
diff --git a/schedutils/schedutils.h b/schedutils/schedutils.h
deleted file mode 100644
index 80e4f7bfe..000000000
--- a/schedutils/schedutils.h
+++ /dev/null
@@ -1,7 +0,0 @@
-#ifndef UTIL_LINUX_SCHED_UTILS
-#define UTIL_LINUX_SCHED_UTILS
-
-extern long getnum(const char *str, const char *errmesg);
-
-#endif
-
diff --git a/schedutils/taskset.c b/schedutils/taskset.c
index 201fc1589..5a7557c3a 100644
--- a/schedutils/taskset.c
+++ b/schedutils/taskset.c
@@ -32,7 +32,7 @@
#include "cpuset.h"
#include "nls.h"
-#include "schedutils.h"
+#include "strutils.h"
static void __attribute__((__noreturn__)) usage(FILE *out)
{
@@ -89,7 +89,7 @@ int main(int argc, char *argv[])
while ((opt = getopt_long(argc, argv, "+pchV", longopts, NULL)) != -1) {
switch (opt) {
case 'p':
- pid = getnum(argv[argc - 1], _("failed to parse pid"));
+ pid = strtol_or_err(argv[argc - 1], _("failed to parse pid"));
break;
case 'c':
c_opt = 1;