]> git.pld-linux.org Git - projects/rc-scripts.git/blob - src/fstab-decode.c
- update from initscripts-8.54, except killing startDaemon() and adding deprecation...
[projects/rc-scripts.git] / src / fstab-decode.c
1 /* fstab-decode(8).
2
3 Copyright (c) 2006 Red Hat, Inc. All rights reserved.
4
5 This copyrighted material is made available to anyone wishing to use, modify,
6 copy, or redistribute it subject to the terms and conditions of the GNU General
7 Public License v.2.
8
9 This program is distributed in the hope that it will be useful, but WITHOUT ANY
10 WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
11 PARTICULAR PURPOSE. See the GNU General Public License for more details.
12
13 You should have received a copy of the GNU General Public License along with
14 this program; if not, write to the Free Software Foundation, Inc., 51 Franklin
15 Street, Fifth Floor, Boston, MA 02110-1301, USA.
16
17 Author: Miloslav Trmac <mitr@redhat.com> */
18
19 #include <errno.h>
20 #include <stdio.h>
21 #include <stdlib.h>
22 #include <string.h>
23 #include <unistd.h>
24
25 /* Decode the fstab-encoded string in place. */
26 static void
27 decode(char *s)
28 {
29         const char *src;
30         char *dest;
31
32         src = s;
33         dest = s;
34         while (*src != '\0') {
35                 if (*src != '\\')
36                         *dest = *src++;
37                 else {
38                         static const struct repl {
39                                 char orig[4];
40                                 size_t len;
41                                 char new;
42                         } repls[] = {
43 #define R(X, Y) { X, sizeof(X) - 1, Y }
44                                 R("\\", '\\'),
45                                 R("011", '\t'),
46                                 R("012", '\n'),
47                                 R("040", ' '),
48                                 R("134", '\\')
49 #undef R
50                         };
51
52                         size_t i;
53
54                         for (i = 0; i < sizeof (repls) / sizeof (repls[0]);
55                              i++) {
56                                 if (memcmp(src + 1, repls[i].orig,
57                                            repls[i].len) == 0) {
58                                         *dest = repls[i].new;
59                                         src += 1 + repls[i].len;
60                                         goto found;
61                                 }
62                         }
63                         *dest = *src++;
64                 found:
65                         ;
66                 }
67                 dest++;
68         }
69         *dest = '\0';
70 }
71
72 int
73 main (int argc, char *argv[])
74 {
75         size_t i;
76
77         if (argc < 2) {
78                 fprintf(stderr, "Usage: fstab-decode command [arguments]\n");
79                 return EXIT_FAILURE;
80         }
81         for (i = 2; i < (size_t)argc; i++)
82                 decode(argv[i]);
83         execvp(argv[1], argv + 1);
84         fprintf(stderr, "fstab-decode: %s: %s\n", argv[1], strerror(errno));
85         return 127;
86 }
This page took 0.043781 seconds and 3 git commands to generate.