summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorHeiko Carstens <heiko.carstens@de.ibm.com>2011-09-15 08:52:30 +0200
committerKarel Zak <kzak@redhat.com>2011-09-27 13:36:54 +0200
commit9bc2b4b1852f549e8d4ff446e85f8bc5239eb26d (patch)
tree455c8b7db8dd3612063a19b059092e99b8b48913 /lib
parent8148217b5bfc9a84ffc7b2936ea2dfecd87e723c (diff)
downloadutil-linux-9bc2b4b1852f549e8d4ff446e85f8bc5239eb26d.tar.gz
chcpu: convert to use lib/path.c
Use the common path access functions. In order to simplify chcpu also implement and use path_writestr() which writes a string to the path specified. Signed-off-by: Heiko Carstens <heiko.carstens@de.ibm.com>
Diffstat (limited to 'lib')
-rw-r--r--lib/path.c26
1 files changed, 26 insertions, 0 deletions
diff --git a/lib/path.c b/lib/path.c
index 219eed67..e2bb3980 100644
--- a/lib/path.c
+++ b/lib/path.c
@@ -58,6 +58,18 @@ path_vfopen(const char *mode, int exit_on_error, const char *path, va_list ap)
return f;
}
+static int
+path_vopen(int flags, const char *path, va_list ap)
+{
+ int fd;
+ const char *p = path_vcreate(path, ap);
+
+ fd = open(p, flags);
+ if (fd == -1)
+ err(EXIT_FAILURE, _("error: cannot open %s"), p);
+ return fd;
+}
+
FILE *
path_fopen(const char *mode, int exit_on_error, const char *path, ...)
{
@@ -112,6 +124,20 @@ path_getnum(const char *path, ...)
}
int
+path_writestr(const char *str, const char *path, ...)
+{
+ int fd, result;
+ va_list ap;
+
+ va_start(ap, path);
+ fd = path_vopen(O_WRONLY, path, ap);
+ va_end(ap);
+ result = write(fd, str, strlen(str));
+ close(fd);
+ return result;
+}
+
+int
path_exist(const char *path, ...)
{
va_list ap;