From d0f2bb89f01a26310f1b0a51690c2acb4a72446e Mon Sep 17 00:00:00 2001 From: Karel Zak Date: Thu, 11 Mar 2010 00:27:35 +0100 Subject: [PATCH] mount: use unmangle/mangle() from lib Signed-off-by: Karel Zak --- mount/Makefile.am | 2 +- mount/mount_mntent.c | 55 ++------------------------------------------ 2 files changed, 3 insertions(+), 54 deletions(-) diff --git a/mount/Makefile.am b/mount/Makefile.am index 76940306..8ae87129 100644 --- a/mount/Makefile.am +++ b/mount/Makefile.am @@ -16,7 +16,7 @@ hdrs_mount = fstab.h mount_mntent.h mount_constants.h \ # generic sources for mount and umount srcs_mount = fstab.c mount_mntent.c getusername.c lomount.c devname.c devname.h \ $(srcs_common) $(hdrs_mount) ../lib/env.c ../lib/linux_version.c \ - ../lib/blkdev.c ../lib/fsprobe.c + ../lib/blkdev.c ../lib/fsprobe.c ../lib/mangle.c # generic flags for all programs (except losetup) # -- note that pkg-config autoconf macros (pkg.m4) does not differentiate diff --git a/mount/mount_mntent.c b/mount/mount_mntent.c index f2623fd5..08e5bf48 100644 --- a/mount/mount_mntent.c +++ b/mount/mount_mntent.c @@ -9,42 +9,11 @@ #include /* for index */ #include /* for isdigit */ #include /* for umask */ + #include "mount_mntent.h" #include "sundries.h" /* for xmalloc */ #include "nls.h" - -/* Unfortunately the classical Unix /etc/mtab and /etc/fstab - do not handle directory names containing spaces. - Here we mangle them, replacing a space by \040. - What do other Unices do? */ - -static unsigned char need_escaping[] = { ' ', '\t', '\n', '\\' }; - -static char * -mangle(const char *s) { - char *ss, *sp; - int n; - - n = strlen(s); - ss = sp = xmalloc(4*n+1); - while(1) { - for (n = 0; n < sizeof(need_escaping); n++) { - if (*s == need_escaping[n]) { - *sp++ = '\\'; - *sp++ = '0' + ((*s & 0300) >> 6); - *sp++ = '0' + ((*s & 070) >> 3); - *sp++ = '0' + (*s & 07); - goto next; - } - } - *sp++ = *s; - if (*s == 0) - break; - next: - s++; - } - return ss; -} +#include "mangle.h" static int is_space_or_tab (char c) { @@ -65,26 +34,6 @@ skip_nonspaces(char *s) { return s; } -#define isoctal(a) (((a) & ~7) == '0') - -/* returns malloced pointer - no more strdup required */ -static char * -unmangle(char *s) { - char *ret, *ss, *sp; - - ss = skip_nonspaces(s); - ret = sp = xmalloc(ss-s+1); - while(s != ss) { - if (*s == '\\' && isoctal(s[1]) && isoctal(s[2]) && isoctal(s[3])) { - *sp++ = 64*(s[1] & 7) + 8*(s[2] & 7) + (s[3] & 7); - s += 4; - } else - *sp++ = *s++; - } - *sp = 0; - return ret; -} - /* * fstat'ing the file and allocating a buffer holding all of it * may be a bad idea: if the file is /proc/mounts, the stat -- 2.39.5