diff options
author | Jim Meyering <jim@meyering.net> | 1999-07-20 18:41:58 +0000 |
---|---|---|
committer | Jim Meyering <jim@meyering.net> | 1999-07-20 18:41:58 +0000 |
commit | bca7546dcd2d68df2d0bc1abd7cefc1fe41a9010 (patch) | |
tree | a375c4f50044f260d8f6fb3c88047a96b5947755 /lib | |
parent | c7582bc4ab0173390314975008a27d8e10b4bf03 (diff) | |
download | coreutils-bca7546dcd2d68df2d0bc1abd7cefc1fe41a9010.tar.xz |
(translate_040_to_space) [MOUNTED_GETMNTENT1]: New function.
(read_filesystem_list) [MOUNTED_GETMNTENT1]: Use it.
Diffstat (limited to 'lib')
-rw-r--r-- | lib/mountlist.c | 62 |
1 files changed, 61 insertions, 1 deletions
diff --git a/lib/mountlist.c b/lib/mountlist.c index ac25ee189..c2c77b3f0 100644 --- a/lib/mountlist.c +++ b/lib/mountlist.c @@ -1,5 +1,5 @@ /* mountlist.c -- return a list of mounted filesystems - Copyright (C) 1991, 1992, 1997, 1998 Free Software Foundation, Inc. + Copyright (C) 1991, 1992, 1997, 1998, 1999 Free Software Foundation, Inc. This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -151,6 +151,46 @@ xatoi (char *cp) } return val; } + +/* Convert, in place, each unambiguous `\040' sequence in the NUL-terminated + string, STR, to a single space. `unambiguous' means that it must not be + immediately preceded by an odd number of backslash characters. */ + +static void +translate_040_to_space (char *str) +{ + while (1) + { + char *p; + char *backslash = strstr (str, "\\040"); + unsigned int backslash_count = 0; + + if (backslash == NULL) + break; + + /* Count preceding backslashes, going no further than str. */ + for (p = backslash - 1; p >= str && *p == '\\'; p--) + ++backslash_count; + + if (backslash_count % 2 == 1) + { + /* The backslash is escaped; advance past the 040 and + continue searching. */ + str = backslash + 4; + continue; + } + + /* We found an unambiguous `\040'. Replace it with a space + and move everything following it back by 3 bytes. + The source and destination regions may overlap, so we have + to use memmove. */ + *backslash = ' '; + str = backslash + 1; + /* Be sure to copy the trailing NUL byte, too. */ + memmove (str, backslash + 4, strlen (backslash + 4) + 1); + } +} + #endif /* MOUNTED_GETMNTENT1. */ #if MOUNTED_GETMNTINFO @@ -349,6 +389,11 @@ read_filesystem_list (int need_fs_type) else me->me_dev = (dev_t) -1; /* Magic; means not known yet. */ + /* FIXME: do the conversion only if we're using some version of + GNU libc -- which one? */ + /* Convert each `\040' string to a space. */ + translate_040_to_space (me->me_mountdir); + /* Add to the linked list. */ *mtail = me; mtail = &me->me_next; @@ -672,3 +717,18 @@ read_filesystem_list (int need_fs_type) return NULL; } } + +#ifdef TEST +int +main (int argc, char **argv) +{ + int i; + for (i = 1; i < argc; i++) + { + char *p = xstrdup (argv[i]); + translate_040_to_space (p); + printf ("%s: %s\n", argv[i], p); + } + exit (0); +} +#endif |