[Frugalware-git] fw32: fw32.c: add xstrdup & xmalloc
James Buren
ryuo at frugalware.org
Thu Nov 3 06:54:26 CET 2011
Git-Url: http://git.frugalware.org/gitweb/gitweb.cgi?p=fw32.git;a=commitdiff;h=650a1ae73c6ffa76bf45f0a83c768926b5c148ab
commit 650a1ae73c6ffa76bf45f0a83c768926b5c148ab
Author: James Buren <ryuo at frugalware.org>
Date: Thu Nov 3 00:55:13 2011 -0500
fw32.c: add xstrdup & xmalloc
diff --git a/fw32.c b/fw32.c
index 3e8cc89..a8f36ab 100644
--- a/fw32.c
+++ b/fw32.c
@@ -7,6 +7,7 @@
#include <sys/mount.h>
#include <limits.h>
#include <errno.h>
+#include <unistd.h>
#include <assert.h>
static const char *FW32_ROOT = "/usr/lib/fw32";
@@ -48,6 +49,34 @@ error(const char *fmt,...)
exit(EXIT_FAILURE);
}
+static void *
+xmalloc(size_t n)
+{
+ void *p;
+
+ assert(n);
+
+ p = malloc(n);
+
+ if(!p)
+ error("malloc: %s\n",strerror(errno));
+
+ return p;
+}
+
+static char *
+xstrdup(const char *s)
+{
+ char *p;
+
+ p = strdup(s);
+
+ if(!p)
+ error("strdup: %s\n",strerror(errno));
+
+ return p;
+}
+
static void
mkdir_parents(const char *s)
{
@@ -118,12 +147,12 @@ mount_directory(const char *src)
char dst[PATH_MAX];
assert(src);
-
+
snprintf(dst,sizeof dst,"%s%s",FW32_ROOT,src);
if(ismounted(dst))
return;
-
+
if(mount(src,dst,"",MS_BIND,""))
error("Failed to mount directory: %s: %s\n",dst,strerror(errno));
}
@@ -151,7 +180,7 @@ umount_all(void)
{
FILE *f;
char line[LINE_MAX], *s, *e;
-
+
f = fopen("/proc/mounts","rb");
if(!f)
@@ -174,7 +203,7 @@ umount_all(void)
if(strncmp(s,FW32_ROOT,strlen(FW32_ROOT)))
umount_directory(s);
}
-
+
fclose(f);
}
More information about the Frugalware-git
mailing list