# 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
#include <string.h> /* for index */
#include <ctype.h> /* for isdigit */
#include <sys/stat.h> /* 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) {
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