aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEric Andersen <andersen@codepoet.org>1999-10-13 21:12:06 +0000
committerEric Andersen <andersen@codepoet.org>1999-10-13 21:12:06 +0000
commitf6be944a6ae612c70ce010582d9c3cdd72f7144f (patch)
tree36ab89d86aad17d6922566cad8e49ba33c5ede81
parent305a73f5eacd94eefe2f2a5a00034d579ef6b1e7 (diff)
downloadbusybox-w32-f6be944a6ae612c70ce010582d9c3cdd72f7144f.tar.gz
busybox-w32-f6be944a6ae612c70ce010582d9c3cdd72f7144f.tar.bz2
busybox-w32-f6be944a6ae612c70ce010582d9c3cdd72f7144f.zip
More stuff
-rw-r--r--applets/busybox.c8
-rw-r--r--archival/tar.c31
-rw-r--r--busybox.c8
-rw-r--r--busybox.def.h12
-rw-r--r--chmod_chown_chgrp.c120
-rw-r--r--coreutils/ln.c114
-rw-r--r--coreutils/mkdir.c119
-rw-r--r--coreutils/rmdir.c44
-rw-r--r--fdflush.c67
-rw-r--r--internal.h7
-rw-r--r--ln.c114
-rw-r--r--math.c2
-rw-r--r--mkdir.c119
-rw-r--r--rmdir.c44
-rw-r--r--tar.c31
-rw-r--r--util-linux/fdflush.c67
-rw-r--r--utility.c123
17 files changed, 610 insertions, 420 deletions
diff --git a/applets/busybox.c b/applets/busybox.c
index 561aa01b5..45365b370 100644
--- a/applets/busybox.c
+++ b/applets/busybox.c
@@ -49,7 +49,7 @@ static const struct Applet applets[] = {
49 {"false", false_main}, 49 {"false", false_main},
50#endif 50#endif
51#ifdef BB_FDFLUSH //bin 51#ifdef BB_FDFLUSH //bin
52 {"fdflush", monadic_main}, 52 {"fdflush", fdflush_main},
53#endif 53#endif
54#ifdef BB_FIND //usr/bin 54#ifdef BB_FIND //usr/bin
55 {"find", find_main}, 55 {"find", find_main},
@@ -70,7 +70,7 @@ static const struct Applet applets[] = {
70 {"length", length_main}, 70 {"length", length_main},
71#endif 71#endif
72#ifdef BB_LN //bin 72#ifdef BB_LN //bin
73 {"ln", dyadic_main}, 73 {"ln", ln_main},
74#endif 74#endif
75#ifdef BB_LOADKMAP //sbin 75#ifdef BB_LOADKMAP //sbin
76 {"loadkmap", loadkmap_main}, 76 {"loadkmap", loadkmap_main},
@@ -88,7 +88,7 @@ static const struct Applet applets[] = {
88 {"math", math_main}, 88 {"math", math_main},
89#endif 89#endif
90#ifdef BB_MKDIR //bin 90#ifdef BB_MKDIR //bin
91 {"mkdir", monadic_main}, 91 {"mkdir", mkdir_main},
92#endif 92#endif
93#ifdef BB_MKNOD //bin 93#ifdef BB_MKNOD //bin
94 {"mknod", mknod_main}, 94 {"mknod", mknod_main},
@@ -124,7 +124,7 @@ static const struct Applet applets[] = {
124 {"rm", rm_main}, 124 {"rm", rm_main},
125#endif 125#endif
126#ifdef BB_RMDIR //bin 126#ifdef BB_RMDIR //bin
127 {"rmdir", monadic_main}, 127 {"rmdir", rmdir_main},
128#endif 128#endif
129#ifdef BB_SLEEP //bin 129#ifdef BB_SLEEP //bin
130 {"sleep", sleep_main}, 130 {"sleep", sleep_main},
diff --git a/archival/tar.c b/archival/tar.c
index ff60f0689..f222c3c9d 100644
--- a/archival/tar.c
+++ b/archival/tar.c
@@ -103,7 +103,6 @@ static ino_t tarInode;
103 */ 103 */
104static void readTarFile (int fileCount, char **fileTable); 104static void readTarFile (int fileCount, char **fileTable);
105static void readData (const char *cp, int count); 105static void readData (const char *cp, int count);
106static void createPath (const char *name, int mode);
107static long getOctal (const char *cp, int len); 106static long getOctal (const char *cp, int len);
108 107
109static void readHeader (const TarHeader * hp, 108static void readHeader (const TarHeader * hp,
@@ -1023,36 +1022,6 @@ static void writeTarBlock (const char *buf, int len)
1023 1022
1024 1023
1025/* 1024/*
1026 * Attempt to create the directories along the specified path, except for
1027 * the final component. The mode is given for the final directory only,
1028 * while all previous ones get default protections. Errors are not reported
1029 * here, as failures to restore files can be reported later.
1030 */
1031static void createPath (const char *name, int mode)
1032{
1033 char *cp;
1034 char *cpOld;
1035 char buf[TAR_NAME_SIZE];
1036
1037 strcpy (buf, name);
1038
1039 cp = strchr (buf, '/');
1040
1041 while (cp) {
1042 cpOld = cp;
1043 cp = strchr (cp + 1, '/');
1044
1045 *cpOld = '\0';
1046
1047 if (mkdir (buf, cp ? 0777 : mode) == 0)
1048 printf ("Directory \"%s\" created\n", buf);
1049
1050 *cpOld = '/';
1051 }
1052}
1053
1054
1055/*
1056 * Read an octal value in a field of the specified width, with optional 1025 * Read an octal value in a field of the specified width, with optional
1057 * spaces on both sides of the number and with an optional null character 1026 * spaces on both sides of the number and with an optional null character
1058 * at the end. Returns -1 on an illegal format. 1027 * at the end. Returns -1 on an illegal format.
diff --git a/busybox.c b/busybox.c
index 561aa01b5..45365b370 100644
--- a/busybox.c
+++ b/busybox.c
@@ -49,7 +49,7 @@ static const struct Applet applets[] = {
49 {"false", false_main}, 49 {"false", false_main},
50#endif 50#endif
51#ifdef BB_FDFLUSH //bin 51#ifdef BB_FDFLUSH //bin
52 {"fdflush", monadic_main}, 52 {"fdflush", fdflush_main},
53#endif 53#endif
54#ifdef BB_FIND //usr/bin 54#ifdef BB_FIND //usr/bin
55 {"find", find_main}, 55 {"find", find_main},
@@ -70,7 +70,7 @@ static const struct Applet applets[] = {
70 {"length", length_main}, 70 {"length", length_main},
71#endif 71#endif
72#ifdef BB_LN //bin 72#ifdef BB_LN //bin
73 {"ln", dyadic_main}, 73 {"ln", ln_main},
74#endif 74#endif
75#ifdef BB_LOADKMAP //sbin 75#ifdef BB_LOADKMAP //sbin
76 {"loadkmap", loadkmap_main}, 76 {"loadkmap", loadkmap_main},
@@ -88,7 +88,7 @@ static const struct Applet applets[] = {
88 {"math", math_main}, 88 {"math", math_main},
89#endif 89#endif
90#ifdef BB_MKDIR //bin 90#ifdef BB_MKDIR //bin
91 {"mkdir", monadic_main}, 91 {"mkdir", mkdir_main},
92#endif 92#endif
93#ifdef BB_MKNOD //bin 93#ifdef BB_MKNOD //bin
94 {"mknod", mknod_main}, 94 {"mknod", mknod_main},
@@ -124,7 +124,7 @@ static const struct Applet applets[] = {
124 {"rm", rm_main}, 124 {"rm", rm_main},
125#endif 125#endif
126#ifdef BB_RMDIR //bin 126#ifdef BB_RMDIR //bin
127 {"rmdir", monadic_main}, 127 {"rmdir", rmdir_main},
128#endif 128#endif
129#ifdef BB_SLEEP //bin 129#ifdef BB_SLEEP //bin
130 {"sleep", sleep_main}, 130 {"sleep", sleep_main},
diff --git a/busybox.def.h b/busybox.def.h
index ae9945d1b..e011bf9fc 100644
--- a/busybox.def.h
+++ b/busybox.def.h
@@ -3,7 +3,6 @@
3 * IE //#define BB_BLAH 3 * IE //#define BB_BLAH
4 */ 4 */
5 5
6//#define BB_BLOCK_DEVICE
7#define BB_BUSYBOX 6#define BB_BUSYBOX
8#define BB_CAT 7#define BB_CAT
9#define BB_CHMOD_CHOWN_CHGRP 8#define BB_CHMOD_CHOWN_CHGRP
@@ -16,20 +15,20 @@
16#define BB_DMESG 15#define BB_DMESG
17#define BB_DUTMP 16#define BB_DUTMP
18#define BB_FALSE 17#define BB_FALSE
19//#define BB_FDFLUSH 18#define BB_FDFLUSH
20#define BB_FIND 19#define BB_FIND
21#define BB_GREP 20#define BB_GREP
22////#define BB_HALT 21////#define BB_HALT
23//#define BB_INIT 22//#define BB_INIT
24#define BB_KILL 23#define BB_KILL
25////#define BB_LENGTH 24////#define BB_LENGTH
26//#define BB_LN 25#define BB_LN
27//#define BB_LOADKMAP 26//#define BB_LOADKMAP
28////#define BB_LOSETUP 27////#define BB_LOSETUP
29#define BB_LS 28#define BB_LS
30//#define BB_MAKEDEVS 29//#define BB_MAKEDEVS
31////#define BB_MATH 30#define BB_MATH
32//#define BB_MKDIR 31#define BB_MKDIR
33//#define BB_MKNOD 32//#define BB_MKNOD
34////#define BB_MKSWAP 33////#define BB_MKSWAP
35#define BB_MNC 34#define BB_MNC
@@ -37,12 +36,11 @@
37#define BB_MOUNT 36#define BB_MOUNT
38////#define BB_MT 37////#define BB_MT
39#define BB_MV 38#define BB_MV
40//#define BB_POSTPROCESS
41//#define BB_PRINTF 39//#define BB_PRINTF
42#define BB_PWD 40#define BB_PWD
43#define BB_REBOOT 41#define BB_REBOOT
44//#define BB_RM 42//#define BB_RM
45//#define BB_RMDIR 43#define BB_RMDIR
46#define BB_SLEEP 44#define BB_SLEEP
47////#define BB_SWAPOFF 45////#define BB_SWAPOFF
48//#define BB_SWAPON 46//#define BB_SWAPON
diff --git a/chmod_chown_chgrp.c b/chmod_chown_chgrp.c
index 37a52281c..5c2adab78 100644
--- a/chmod_chown_chgrp.c
+++ b/chmod_chown_chgrp.c
@@ -29,7 +29,7 @@ static int uid=-1;
29static int gid=0; 29static int gid=0;
30static int whichApp; 30static int whichApp;
31static char* invocationName=NULL; 31static char* invocationName=NULL;
32static mode_t mode=7777; 32static mode_t mode=0644;
33 33
34 34
35#define CHGRP_APP 1 35#define CHGRP_APP 1
@@ -59,6 +59,7 @@ static int fileAction(const char *fileName)
59 if (chown(fileName, ((whichApp==CHOWN_APP)? uid: statBuf.st_uid), gid) < 0) 59 if (chown(fileName, ((whichApp==CHOWN_APP)? uid: statBuf.st_uid), gid) < 0)
60 return( TRUE); 60 return( TRUE);
61 case CHMOD_APP: 61 case CHMOD_APP:
62 fprintf(stderr, "%s, %d\n", fileName, mode);
62 if (chmod(fileName, mode)) 63 if (chmod(fileName, mode))
63 return( TRUE); 64 return( TRUE);
64 } 65 }
@@ -67,118 +68,13 @@ static int fileAction(const char *fileName)
67 return( FALSE); 68 return( FALSE);
68} 69}
69 70
70/* [ugoa]{+|-|=}[rwxstl] */
71int parse_mode( const char* s, mode_t* or, mode_t* and, int* group_execute)
72{
73 mode_t mode = 0;
74 mode_t groups = S_ISVTX;
75 char type;
76 char c;
77
78 do {
79 for ( ; ; ) {
80 switch ( c = *s++ ) {
81 case '\0':
82 return (FALSE);
83 case 'u':
84 groups |= S_ISUID|S_IRWXU;
85 continue;
86 case 'g':
87 groups |= S_ISGID|S_IRWXG;
88 continue;
89 case 'o':
90 groups |= S_IRWXO;
91 continue;
92 case 'a':
93 groups |= S_ISUID|S_ISGID|S_IRWXU|S_IRWXG|S_IRWXO;
94 continue;
95 case '+':
96 case '=':
97 case '-':
98 type = c;
99 if ( groups == S_ISVTX ) /* The default is "all" */
100 groups |= S_ISUID|S_ISGID|S_IRWXU|S_IRWXG|S_IRWXO;
101 break;
102 default:
103 if ( c >= '0' && c <= '7' && mode == 0 && groups == S_ISVTX ) {
104 *and = 0;
105 *or = strtol(--s, 0, 010);
106 return (TRUE);
107 }
108 else
109 return (FALSE);
110 }
111 break;
112 }
113
114 while ( (c = *s++) != '\0' ) {
115 switch ( c ) {
116 case ',':
117 break;
118 case 'r':
119 mode |= S_IRUSR|S_IRGRP|S_IROTH;
120 continue;
121 case 'w':
122 mode |= S_IWUSR|S_IWGRP|S_IWOTH;
123 continue;
124 case 'x':
125 mode |= S_IXUSR|S_IXGRP|S_IXOTH;
126 continue;
127 case 's':
128 if ( group_execute != 0 && (groups & S_IRWXG) ) {
129 if ( *group_execute < 0 )
130 return (FALSE);
131 if ( type != '-' ) {
132 mode |= S_IXGRP;
133 *group_execute = 1;
134 }
135 }
136 mode |= S_ISUID|S_ISGID;
137 continue;
138 case 'l':
139 if ( *group_execute > 0 )
140 return (FALSE);
141 if ( type != '-' ) {
142 *and &= ~S_IXGRP;
143 *group_execute = -1;
144 }
145 mode |= S_ISGID;
146 groups |= S_ISGID;
147 continue;
148 case 't':
149 mode |= S_ISVTX;
150 continue;
151 default:
152 return (FALSE);
153 }
154 break;
155 }
156 switch ( type ) {
157 case '=':
158 *and &= ~(groups);
159 /* fall through */
160 case '+':
161 *or |= mode & groups;
162 break;
163 case '-':
164 *and &= ~(mode & groups);
165 *or &= *and;
166 break;
167 }
168 } while ( c == ',' );
169 return (TRUE);
170}
171
172
173int chmod_chown_chgrp_main(int argc, char **argv) 71int chmod_chown_chgrp_main(int argc, char **argv)
174{ 72{
175 struct group *grp; 73 struct group *grp;
176 struct passwd *pwd; 74 struct passwd *pwd;
177 int recursiveFlag=FALSE; 75 int recursiveFlag=FALSE;
178 char *groupName; 76 char *groupName;
179 mode_t andWithMode = S_ISVTX|S_ISUID|S_ISGID|S_IRWXU|S_IRWXG|S_IRWXO; 77 mode_t andWithMode= S_ISVTX|S_ISUID|S_ISGID|S_IRWXU|S_IRWXG|S_IRWXO;
180 mode_t orWithMode = 0;
181
182 78
183 whichApp = (strcmp(*argv, "chown")==0)? CHOWN_APP : (strcmp(*argv, "chmod")==0)? CHMOD_APP : CHGRP_APP; 79 whichApp = (strcmp(*argv, "chown")==0)? CHOWN_APP : (strcmp(*argv, "chmod")==0)? CHMOD_APP : CHGRP_APP;
184 80
@@ -207,12 +103,12 @@ int chmod_chown_chgrp_main(int argc, char **argv)
207 103
208 if ( whichApp == CHMOD_APP ) { 104 if ( whichApp == CHMOD_APP ) {
209 /* Find the specified modes */ 105 /* Find the specified modes */
210 if ( parse_mode(*argv, &orWithMode, &andWithMode, 0) == FALSE ) { 106 if ( parse_mode(*argv, &mode) == FALSE ) {
211 fprintf(stderr, "%s: Unknown mode: %s\n", invocationName, *argv); 107 fprintf(stderr, "%s: Unknown mode: %s\n", invocationName, *argv);
212 exit( FALSE); 108 exit( FALSE);
213 } 109 }
214 mode &= andWithMode; 110 //mode &= andWithMode;
215 mode |= orWithMode; 111 fprintf(stderr, "mode %d\n", mode);
216 } else { 112 } else {
217 113
218 /* Find the selected group */ 114 /* Find the selected group */
@@ -245,8 +141,8 @@ int chmod_chown_chgrp_main(int argc, char **argv)
245 exit( FALSE); 141 exit( FALSE);
246 } 142 }
247 while (argc-- > 1) { 143 while (argc-- > 1) {
248 argv++; 144 if (recursiveAction( *(++argv), recursiveFlag, TRUE, fileAction, fileAction)==FALSE)
249 recursiveAction( *argv, recursiveFlag, TRUE, fileAction, fileAction); 145 exit( FALSE);
250 } 146 }
251 exit(TRUE); 147 exit(TRUE);
252} 148}
diff --git a/coreutils/ln.c b/coreutils/ln.c
index 3e87b579e..cd3cb4e45 100644
--- a/coreutils/ln.c
+++ b/coreutils/ln.c
@@ -1,52 +1,100 @@
1/*
2 * Mini ln implementation for busybox
3 *
4 * Copyright (C) 1998 by Erik Andersen <andersee@debian.org>
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 *
20 */
21
1#include "internal.h" 22#include "internal.h"
2#include <stdio.h> 23#include <stdio.h>
3#include <sys/stat.h> 24#include <dirent.h>
4#include <sys/param.h>
5#include <errno.h> 25#include <errno.h>
6 26
7const char ln_usage[] = "ln [-s] [-f] original-name additional-name\n" 27
28static const char ln_usage[] = "ln [-s] [-f] original-name additional-name\n"
8"\n" 29"\n"
9"\tAdd a new name that refers to the same file as \"original-name\"\n" 30"\tAdd a new name that refers to the same file as \"original-name\"\n"
10"\n" 31"\n"
11"\t-s:\tUse a \"symbolic\" link, instead of a \"hard\" link.\n" 32"\t-s:\tUse a \"symbolic\" link, instead of a \"hard\" link.\n"
12"\t-f:\tRemove existing destination files.\n"; 33"\t-f:\tRemove existing destination files.\n";
13 34
14int 35
15ln_fn(const struct FileInfo * i) 36static int symlinkFlag = FALSE;
37static int removeoldFlag = FALSE;
38static const char *destName;
39
40
41extern int ln_main(int argc, char **argv)
16{ 42{
17 int status = 0; 43 int status;
18 char d[PATH_MAX]; 44 char newdestName[NAME_MAX];
19 const char * destination = i->destination;
20 45
21 if ( !i->makeSymbolicLink && (i->stat.st_mode & S_IFMT) == S_IFDIR ) { 46 if (argc < 3) {
22 fprintf(stderr, "Please use \"ln -s\" to link directories.\n"); 47 fprintf(stderr, "Usage: %s", ln_usage);
23 return 1; 48 exit (FALSE);
24 } 49 }
50 argc--;
51 argv++;
25 52
26 /* 53 /* Parse any options */
27 * If the destination is a directory, create a file within it. 54 while (**argv == '-') {
28 */ 55 while (*++(*argv))
29 if ( is_a_directory(i->destination) ) { 56 switch (**argv) {
30 destination = join_paths( 57 case 's':
31 d 58 symlinkFlag = TRUE;
32 ,i->destination 59 break;
33 ,&i->source[i->directoryLength]); 60 case 'f':
34 } 61 removeoldFlag = TRUE;
62 break;
63 default:
64 fprintf(stderr, "Usage: %s\n", ln_usage);
65 exit(FALSE);
66 }
67 argc--;
68 argv++;
69 }
35 70
36 if ( i->force )
37 status = ( unlink(destination) && errno != ENOENT );
38 71
39 if ( status == 0 ) { 72 destName = argv[argc - 1];
40 if ( i->makeSymbolicLink )
41 status = symlink(i->source, destination);
42 else
43 status = link(i->source, destination);
44 }
45 73
46 if ( status != 0 ) { 74 if ((argc > 3) && !(isDirectory(destName))) {
47 name_and_error(destination); 75 fprintf(stderr, "%s: not a directory\n", destName);
48 return 1; 76 exit (FALSE);
77 }
78
79 while (argc-- >= 2) {
80 strcpy(newdestName, destName);
81 strcat(newdestName, (*argv)+(strlen(*(++argv))));
82
83 if (removeoldFlag==TRUE ) {
84 status = ( unlink(newdestName) && errno != ENOENT );
85 if ( status != 0 ) {
86 perror(newdestName);
87 exit( FALSE);
88 }
49 } 89 }
90 if ( symlinkFlag==TRUE)
91 status = symlink(*argv, newdestName);
50 else 92 else
51 return 0; 93 status = link(*argv, newdestName);
94 if ( status != 0 ) {
95 perror(newdestName);
96 exit( FALSE);
97 }
98 }
99 exit( TRUE);
52} 100}
diff --git a/coreutils/mkdir.c b/coreutils/mkdir.c
index 8f1fa04db..61d35d5cd 100644
--- a/coreutils/mkdir.c
+++ b/coreutils/mkdir.c
@@ -1,58 +1,85 @@
1/*
2 * Mini mkdir implementation for busybox
3 *
4 * Copyright (C) 1998 by Erik Andersen <andersee@debian.org>
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 *
20 */
21
1#include "internal.h" 22#include "internal.h"
23#include <stdio.h>
2#include <errno.h> 24#include <errno.h>
3#include <sys/param.h> 25#include <sys/param.h>
4 26
5const char mkdir_usage[] = "mkdir [-m mode] directory [directory ...]\n" 27const char mkdir_usage[] = "Usage: mkdir [OPTION] DIRECTORY...\n"
6"\tCreate directories.\n" 28"Create the DIRECTORY(ies), if they do not already exist\n\n"
7"\n" 29"-m\tset permission mode (as in chmod), not rwxrwxrwx - umask\n"
8"\t-m mode:\tSpecifiy the mode for the new directory\n" 30"-p\tno error if existing, make parent directories as needed\n";
9"\t\tunder the argument directory.";
10 31
11/*make directories skipping the last part of the path. Used here and by untar*/
12int mkdir_until(const char *fpath, const struct FileInfo * fi)
13{
14 char path[PATH_MAX];
15 char * s = path;
16 32
17 strcpy(path, fpath); 33static int parentFlag = FALSE;
18 if ( s[0] == '\0' && s[1] == '\0' ) { 34static int permFlag = FALSE;
19 usage(mkdir_usage); 35static mode_t mode = 0777;
20 return 1; 36
21 }
22 s++;
23 while ( *s != '\0' ) {
24 if ( *s == '/' ) {
25 int status;
26
27 *s = '\0';
28 status = mkdir(path, (fi?fi->orWithMode:0700) );
29 *s = '/';
30
31 if ( status != 0 ) {
32 if ( errno != EEXIST ) {
33 name_and_error(fpath);
34 return 1;
35 }
36 }
37
38 }
39 s++;
40 }
41 return 0;
42}
43 37
44int 38extern int mkdir_main(int argc, char **argv)
45mkdir_fn(const struct FileInfo * i)
46{ 39{
47 if ( i->makeParentDirectories ) { 40 argc--;
48 if(mkdir_until(i->source, i)) return 1; 41 argv++;
49 } 42
43 /* Parse any options */
44 while (argc > 1 && **argv == '-') {
45 while (*++(*argv))
46 switch (**argv) {
47 case 'm':
48 permFlag = TRUE;
49 break;
50 case 'p':
51 parentFlag = TRUE;
52 break;
53 default:
54 fprintf(stderr, "%s\n", mkdir_usage);
55 exit(FALSE);
56 }
57 argc--;
58 argv++;
59 }
60
50 61
51 if ( mkdir(i->source, i->orWithMode) != 0 && errno != EEXIST ) { 62 if (argc < 1) {
52 name_and_error(i->source); 63 fprintf(stderr, "%s\n", mkdir_usage);
53 return 1; 64 exit (FALSE);
65 }
66
67 while (--argc > 0) {
68 struct stat statBuf;
69 if (stat(*(++argv), &statBuf) != ENOENT) {
70 fprintf(stderr, "%s: File exists\n", *argv);
71 return( FALSE);
72 }
73 if (parentFlag == TRUE)
74 createPath(*argv, mode);
75 else {
76 if (mkdir (*argv, mode) != 0) {
77 perror(*argv);
78 exit( FALSE);
79 }
54 } 80 }
55 else 81 }
56 return 0; 82 exit( TRUE);
57} 83}
58 84
85
diff --git a/coreutils/rmdir.c b/coreutils/rmdir.c
index 069e68546..b4da03f12 100644
--- a/coreutils/rmdir.c
+++ b/coreutils/rmdir.c
@@ -1,17 +1,41 @@
1/*
2 * Mini rmdir implementation for busybox
3 *
4 * Copyright (C) 1998 by Erik Andersen <andersee@debian.org>
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 *
20 */
21
1#include "internal.h" 22#include "internal.h"
23#include <stdio.h>
2#include <errno.h> 24#include <errno.h>
3 25
4const char rmdir_usage[] = "rmdir directory [directory ...]\n"
5"\n"
6"\tDelete directories.\n";
7 26
8extern int 27extern int rmdir_main(int argc, char **argv)
9rmdir_fn(const struct FileInfo * i)
10{ 28{
11 if ( rmdir(i->source) != 0 && errno != ENOENT && !i->force ) { 29 if ( argc==1 || **(argv+1) == '-' ) {
12 name_and_error(i->source); 30 fprintf(stderr, "Usage: rmdir [OPTION]... DIRECTORY...\nRemove the DIRECTORY(ies), if they are empty.");
13 return 1; 31 exit(FALSE);
32 }
33
34 while (--argc > 0) {
35 if ( rmdir(*(++argv)) == -1 ) {
36 fprintf(stderr, "%s: %s\n", *argv, strerror(errno));
37 exit(FALSE);
14 } 38 }
15 else 39 }
16 return 0; 40 exit(TRUE);
17} 41}
diff --git a/fdflush.c b/fdflush.c
index a15e9b3f7..ce6870cd1 100644
--- a/fdflush.c
+++ b/fdflush.c
@@ -1,36 +1,53 @@
1
2/*
3 * Mini fdflush implementation for busybox
4 *
5 * Copyright (C) 1998 by Erik Andersen <andersee@debian.org>
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 *
21 */
22
1#include "internal.h" 23#include "internal.h"
24#include <stdio.h>
2#include <sys/ioctl.h> 25#include <sys/ioctl.h>
3#include <linux/fd.h> 26#include <linux/fd.h>
4#include <sys/types.h>
5#include <sys/stat.h>
6#include <fcntl.h> 27#include <fcntl.h>
7 28
8const char fdflush_usage[] = "fdflush device";
9 29
10int 30extern int fdflush_main(int argc, char **argv)
11fdflush(const char *filename)
12{ 31{
13 int status; 32 int value;
14 int fd = open(filename, 0); 33 int fd;
15 34 if ( **(argv+1) == '-' ) {
16 if ( fd < 0 ) { 35 fprintf(stderr, "Usage: fdflush device\n");
17 name_and_error(filename); 36 exit(FALSE);
18 return 1; 37 }
19 }
20 38
21 status = ioctl(fd, FDFLUSH, 0); 39 fd = open(*argv, 0);
22 close(fd); 40 if ( fd < 0 ) {
23 41 perror(*argv);
24 if ( status != 0 ) { 42 exit(FALSE);
25 name_and_error(filename); 43 }
26 return 1;
27 }
28 return 0;
29}
30 44
45 value = ioctl(fd, FDFLUSH, 0);
46 close(fd);
31 47
32int 48 if ( value ) {
33fdflush_fn(const struct FileInfo * i) 49 perror(*argv);
34{ 50 exit(FALSE);
35 return fdflush(i->source); 51 }
52 exit (TRUE);
36} 53}
diff --git a/internal.h b/internal.h
index f095091fc..397eca48a 100644
--- a/internal.h
+++ b/internal.h
@@ -66,9 +66,9 @@ extern int date_main(int argc, char** argv);
66extern int dd_main(int argc, char** argv); 66extern int dd_main(int argc, char** argv);
67extern int df_main(int argc, char** argv); 67extern int df_main(int argc, char** argv);
68extern int dmesg_main(int argc, char** argv); 68extern int dmesg_main(int argc, char** argv);
69extern int dyadic_main(int argc, char** argv);
70extern int false_main(int argc, char** argv); 69extern int false_main(int argc, char** argv);
71extern int fdisk_main(int argc, char** argv); 70extern int fdisk_main(int argc, char** argv);
71extern int fdflush_main(int argc, char **argv);
72extern int find_main(int argc, char** argv); 72extern int find_main(int argc, char** argv);
73extern int grep_main(int argc, char** argv); 73extern int grep_main(int argc, char** argv);
74extern int halt_main(int argc, char** argv); 74extern int halt_main(int argc, char** argv);
@@ -81,16 +81,17 @@ extern int losetup_main(int argc, char** argv);
81extern int ls_main(int argc, char** argv); 81extern int ls_main(int argc, char** argv);
82extern int makedevs_main(int argc, char** argv); 82extern int makedevs_main(int argc, char** argv);
83extern int math_main(int argc, char** argv); 83extern int math_main(int argc, char** argv);
84extern int mkdir_main(int argc, char** argv);
84extern int mknod_main(int argc, char** argv); 85extern int mknod_main(int argc, char** argv);
85extern int mkswap_main(int argc, char** argv); 86extern int mkswap_main(int argc, char** argv);
86extern int mnc_main(int argc, char** argv); 87extern int mnc_main(int argc, char** argv);
87extern int monadic_main(int argc, char** argv);
88extern int mount_main(int argc, char** argv); 88extern int mount_main(int argc, char** argv);
89extern int mt_main(int argc, char** argv); 89extern int mt_main(int argc, char** argv);
90extern int mv_main(int argc, char** argv); 90extern int mv_main(int argc, char** argv);
91extern int printf_main(int argc, char** argv); 91extern int printf_main(int argc, char** argv);
92extern int pwd_main(int argc, char** argv); 92extern int pwd_main(int argc, char** argv);
93extern int reboot_main(int argc, char** argv); 93extern int reboot_main(int argc, char** argv);
94extern int rmdir_main(int argc, char **argv);
94extern int rm_main(int argc, char** argv); 95extern int rm_main(int argc, char** argv);
95extern int scan_partitions_main(int argc, char** argv); 96extern int scan_partitions_main(int argc, char** argv);
96extern int sh_main(int argc, char** argv); 97extern int sh_main(int argc, char** argv);
@@ -126,6 +127,8 @@ int recursiveAction(const char *fileName, int recurse, int followLinks,
126int match(const char* text, const char * pattern); 127int match(const char* text, const char * pattern);
127const char* timeString(time_t timeVal); 128const char* timeString(time_t timeVal);
128 129
130extern void createPath (const char *name, int mode);
131extern int parse_mode( const char* s, mode_t* theMode);
129 132
130#endif 133#endif
131 134
diff --git a/ln.c b/ln.c
index 3e87b579e..cd3cb4e45 100644
--- a/ln.c
+++ b/ln.c
@@ -1,52 +1,100 @@
1/*
2 * Mini ln implementation for busybox
3 *
4 * Copyright (C) 1998 by Erik Andersen <andersee@debian.org>
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 *
20 */
21
1#include "internal.h" 22#include "internal.h"
2#include <stdio.h> 23#include <stdio.h>
3#include <sys/stat.h> 24#include <dirent.h>
4#include <sys/param.h>
5#include <errno.h> 25#include <errno.h>
6 26
7const char ln_usage[] = "ln [-s] [-f] original-name additional-name\n" 27
28static const char ln_usage[] = "ln [-s] [-f] original-name additional-name\n"
8"\n" 29"\n"
9"\tAdd a new name that refers to the same file as \"original-name\"\n" 30"\tAdd a new name that refers to the same file as \"original-name\"\n"
10"\n" 31"\n"
11"\t-s:\tUse a \"symbolic\" link, instead of a \"hard\" link.\n" 32"\t-s:\tUse a \"symbolic\" link, instead of a \"hard\" link.\n"
12"\t-f:\tRemove existing destination files.\n"; 33"\t-f:\tRemove existing destination files.\n";
13 34
14int 35
15ln_fn(const struct FileInfo * i) 36static int symlinkFlag = FALSE;
37static int removeoldFlag = FALSE;
38static const char *destName;
39
40
41extern int ln_main(int argc, char **argv)
16{ 42{
17 int status = 0; 43 int status;
18 char d[PATH_MAX]; 44 char newdestName[NAME_MAX];
19 const char * destination = i->destination;
20 45
21 if ( !i->makeSymbolicLink && (i->stat.st_mode & S_IFMT) == S_IFDIR ) { 46 if (argc < 3) {
22 fprintf(stderr, "Please use \"ln -s\" to link directories.\n"); 47 fprintf(stderr, "Usage: %s", ln_usage);
23 return 1; 48 exit (FALSE);
24 } 49 }
50 argc--;
51 argv++;
25 52
26 /* 53 /* Parse any options */
27 * If the destination is a directory, create a file within it. 54 while (**argv == '-') {
28 */ 55 while (*++(*argv))
29 if ( is_a_directory(i->destination) ) { 56 switch (**argv) {
30 destination = join_paths( 57 case 's':
31 d 58 symlinkFlag = TRUE;
32 ,i->destination 59 break;
33 ,&i->source[i->directoryLength]); 60 case 'f':
34 } 61 removeoldFlag = TRUE;
62 break;
63 default:
64 fprintf(stderr, "Usage: %s\n", ln_usage);
65 exit(FALSE);
66 }
67 argc--;
68 argv++;
69 }
35 70
36 if ( i->force )
37 status = ( unlink(destination) && errno != ENOENT );
38 71
39 if ( status == 0 ) { 72 destName = argv[argc - 1];
40 if ( i->makeSymbolicLink )
41 status = symlink(i->source, destination);
42 else
43 status = link(i->source, destination);
44 }
45 73
46 if ( status != 0 ) { 74 if ((argc > 3) && !(isDirectory(destName))) {
47 name_and_error(destination); 75 fprintf(stderr, "%s: not a directory\n", destName);
48 return 1; 76 exit (FALSE);
77 }
78
79 while (argc-- >= 2) {
80 strcpy(newdestName, destName);
81 strcat(newdestName, (*argv)+(strlen(*(++argv))));
82
83 if (removeoldFlag==TRUE ) {
84 status = ( unlink(newdestName) && errno != ENOENT );
85 if ( status != 0 ) {
86 perror(newdestName);
87 exit( FALSE);
88 }
49 } 89 }
90 if ( symlinkFlag==TRUE)
91 status = symlink(*argv, newdestName);
50 else 92 else
51 return 0; 93 status = link(*argv, newdestName);
94 if ( status != 0 ) {
95 perror(newdestName);
96 exit( FALSE);
97 }
98 }
99 exit( TRUE);
52} 100}
diff --git a/math.c b/math.c
index 5c1560a4e..29962a873 100644
--- a/math.c
+++ b/math.c
@@ -137,7 +137,7 @@ stack_machine(const char * argument)
137} 137}
138 138
139int 139int
140math_main(struct FileInfo * i, int argc, char * * argv) 140math_main(int argc, char * * argv)
141{ 141{
142 while ( argc >= 2 ) { 142 while ( argc >= 2 ) {
143 stack_machine(argv[1]); 143 stack_machine(argv[1]);
diff --git a/mkdir.c b/mkdir.c
index 8f1fa04db..61d35d5cd 100644
--- a/mkdir.c
+++ b/mkdir.c
@@ -1,58 +1,85 @@
1/*
2 * Mini mkdir implementation for busybox
3 *
4 * Copyright (C) 1998 by Erik Andersen <andersee@debian.org>
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 *
20 */
21
1#include "internal.h" 22#include "internal.h"
23#include <stdio.h>
2#include <errno.h> 24#include <errno.h>
3#include <sys/param.h> 25#include <sys/param.h>
4 26
5const char mkdir_usage[] = "mkdir [-m mode] directory [directory ...]\n" 27const char mkdir_usage[] = "Usage: mkdir [OPTION] DIRECTORY...\n"
6"\tCreate directories.\n" 28"Create the DIRECTORY(ies), if they do not already exist\n\n"
7"\n" 29"-m\tset permission mode (as in chmod), not rwxrwxrwx - umask\n"
8"\t-m mode:\tSpecifiy the mode for the new directory\n" 30"-p\tno error if existing, make parent directories as needed\n";
9"\t\tunder the argument directory.";
10 31
11/*make directories skipping the last part of the path. Used here and by untar*/
12int mkdir_until(const char *fpath, const struct FileInfo * fi)
13{
14 char path[PATH_MAX];
15 char * s = path;
16 32
17 strcpy(path, fpath); 33static int parentFlag = FALSE;
18 if ( s[0] == '\0' && s[1] == '\0' ) { 34static int permFlag = FALSE;
19 usage(mkdir_usage); 35static mode_t mode = 0777;
20 return 1; 36
21 }
22 s++;
23 while ( *s != '\0' ) {
24 if ( *s == '/' ) {
25 int status;
26
27 *s = '\0';
28 status = mkdir(path, (fi?fi->orWithMode:0700) );
29 *s = '/';
30
31 if ( status != 0 ) {
32 if ( errno != EEXIST ) {
33 name_and_error(fpath);
34 return 1;
35 }
36 }
37
38 }
39 s++;
40 }
41 return 0;
42}
43 37
44int 38extern int mkdir_main(int argc, char **argv)
45mkdir_fn(const struct FileInfo * i)
46{ 39{
47 if ( i->makeParentDirectories ) { 40 argc--;
48 if(mkdir_until(i->source, i)) return 1; 41 argv++;
49 } 42
43 /* Parse any options */
44 while (argc > 1 && **argv == '-') {
45 while (*++(*argv))
46 switch (**argv) {
47 case 'm':
48 permFlag = TRUE;
49 break;
50 case 'p':
51 parentFlag = TRUE;
52 break;
53 default:
54 fprintf(stderr, "%s\n", mkdir_usage);
55 exit(FALSE);
56 }
57 argc--;
58 argv++;
59 }
60
50 61
51 if ( mkdir(i->source, i->orWithMode) != 0 && errno != EEXIST ) { 62 if (argc < 1) {
52 name_and_error(i->source); 63 fprintf(stderr, "%s\n", mkdir_usage);
53 return 1; 64 exit (FALSE);
65 }
66
67 while (--argc > 0) {
68 struct stat statBuf;
69 if (stat(*(++argv), &statBuf) != ENOENT) {
70 fprintf(stderr, "%s: File exists\n", *argv);
71 return( FALSE);
72 }
73 if (parentFlag == TRUE)
74 createPath(*argv, mode);
75 else {
76 if (mkdir (*argv, mode) != 0) {
77 perror(*argv);
78 exit( FALSE);
79 }
54 } 80 }
55 else 81 }
56 return 0; 82 exit( TRUE);
57} 83}
58 84
85
diff --git a/rmdir.c b/rmdir.c
index 069e68546..b4da03f12 100644
--- a/rmdir.c
+++ b/rmdir.c
@@ -1,17 +1,41 @@
1/*
2 * Mini rmdir implementation for busybox
3 *
4 * Copyright (C) 1998 by Erik Andersen <andersee@debian.org>
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 *
20 */
21
1#include "internal.h" 22#include "internal.h"
23#include <stdio.h>
2#include <errno.h> 24#include <errno.h>
3 25
4const char rmdir_usage[] = "rmdir directory [directory ...]\n"
5"\n"
6"\tDelete directories.\n";
7 26
8extern int 27extern int rmdir_main(int argc, char **argv)
9rmdir_fn(const struct FileInfo * i)
10{ 28{
11 if ( rmdir(i->source) != 0 && errno != ENOENT && !i->force ) { 29 if ( argc==1 || **(argv+1) == '-' ) {
12 name_and_error(i->source); 30 fprintf(stderr, "Usage: rmdir [OPTION]... DIRECTORY...\nRemove the DIRECTORY(ies), if they are empty.");
13 return 1; 31 exit(FALSE);
32 }
33
34 while (--argc > 0) {
35 if ( rmdir(*(++argv)) == -1 ) {
36 fprintf(stderr, "%s: %s\n", *argv, strerror(errno));
37 exit(FALSE);
14 } 38 }
15 else 39 }
16 return 0; 40 exit(TRUE);
17} 41}
diff --git a/tar.c b/tar.c
index ff60f0689..f222c3c9d 100644
--- a/tar.c
+++ b/tar.c
@@ -103,7 +103,6 @@ static ino_t tarInode;
103 */ 103 */
104static void readTarFile (int fileCount, char **fileTable); 104static void readTarFile (int fileCount, char **fileTable);
105static void readData (const char *cp, int count); 105static void readData (const char *cp, int count);
106static void createPath (const char *name, int mode);
107static long getOctal (const char *cp, int len); 106static long getOctal (const char *cp, int len);
108 107
109static void readHeader (const TarHeader * hp, 108static void readHeader (const TarHeader * hp,
@@ -1023,36 +1022,6 @@ static void writeTarBlock (const char *buf, int len)
1023 1022
1024 1023
1025/* 1024/*
1026 * Attempt to create the directories along the specified path, except for
1027 * the final component. The mode is given for the final directory only,
1028 * while all previous ones get default protections. Errors are not reported
1029 * here, as failures to restore files can be reported later.
1030 */
1031static void createPath (const char *name, int mode)
1032{
1033 char *cp;
1034 char *cpOld;
1035 char buf[TAR_NAME_SIZE];
1036
1037 strcpy (buf, name);
1038
1039 cp = strchr (buf, '/');
1040
1041 while (cp) {
1042 cpOld = cp;
1043 cp = strchr (cp + 1, '/');
1044
1045 *cpOld = '\0';
1046
1047 if (mkdir (buf, cp ? 0777 : mode) == 0)
1048 printf ("Directory \"%s\" created\n", buf);
1049
1050 *cpOld = '/';
1051 }
1052}
1053
1054
1055/*
1056 * Read an octal value in a field of the specified width, with optional 1025 * Read an octal value in a field of the specified width, with optional
1057 * spaces on both sides of the number and with an optional null character 1026 * spaces on both sides of the number and with an optional null character
1058 * at the end. Returns -1 on an illegal format. 1027 * at the end. Returns -1 on an illegal format.
diff --git a/util-linux/fdflush.c b/util-linux/fdflush.c
index a15e9b3f7..ce6870cd1 100644
--- a/util-linux/fdflush.c
+++ b/util-linux/fdflush.c
@@ -1,36 +1,53 @@
1
2/*
3 * Mini fdflush implementation for busybox
4 *
5 * Copyright (C) 1998 by Erik Andersen <andersee@debian.org>
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 *
21 */
22
1#include "internal.h" 23#include "internal.h"
24#include <stdio.h>
2#include <sys/ioctl.h> 25#include <sys/ioctl.h>
3#include <linux/fd.h> 26#include <linux/fd.h>
4#include <sys/types.h>
5#include <sys/stat.h>
6#include <fcntl.h> 27#include <fcntl.h>
7 28
8const char fdflush_usage[] = "fdflush device";
9 29
10int 30extern int fdflush_main(int argc, char **argv)
11fdflush(const char *filename)
12{ 31{
13 int status; 32 int value;
14 int fd = open(filename, 0); 33 int fd;
15 34 if ( **(argv+1) == '-' ) {
16 if ( fd < 0 ) { 35 fprintf(stderr, "Usage: fdflush device\n");
17 name_and_error(filename); 36 exit(FALSE);
18 return 1; 37 }
19 }
20 38
21 status = ioctl(fd, FDFLUSH, 0); 39 fd = open(*argv, 0);
22 close(fd); 40 if ( fd < 0 ) {
23 41 perror(*argv);
24 if ( status != 0 ) { 42 exit(FALSE);
25 name_and_error(filename); 43 }
26 return 1;
27 }
28 return 0;
29}
30 44
45 value = ioctl(fd, FDFLUSH, 0);
46 close(fd);
31 47
32int 48 if ( value ) {
33fdflush_fn(const struct FileInfo * i) 49 perror(*argv);
34{ 50 exit(FALSE);
35 return fdflush(i->source); 51 }
52 exit (TRUE);
36} 53}
diff --git a/utility.c b/utility.c
index 21d69b6e8..b2228f0cb 100644
--- a/utility.c
+++ b/utility.c
@@ -544,4 +544,127 @@ recursiveAction(const char *fileName, int recurse, int followLinks,
544 544
545#endif 545#endif
546 546
547
548
549#if defined (BB_TAR) || defined (BB_MKDIR)
550/*
551 * Attempt to create the directories along the specified path, except for
552 * the final component. The mode is given for the final directory only,
553 * while all previous ones get default protections. Errors are not reported
554 * here, as failures to restore files can be reported later.
555 */
556extern void createPath (const char *name, int mode)
557{
558 char *cp;
559 char *cpOld;
560 char buf[NAME_MAX];
561
562 strcpy (buf, name);
563
564 cp = strchr (buf, '/');
565
566 while (cp) {
567 cpOld = cp;
568 cp = strchr (cp + 1, '/');
569
570 *cpOld = '\0';
571
572 if (mkdir (buf, cp ? 0777 : mode) == 0)
573 printf ("Directory \"%s\" created\n", buf);
574
575 *cpOld = '/';
576 }
577}
578#endif
579
580
581
582#if defined (BB_CHMOD_CHOWN_CHGRP) || defined (BB_MKDIR)
583/* [ugoa]{+|-|=}[rwxstl] */
584extern int parse_mode( const char* s, mode_t* theMode)
585{
586 mode_t or;
587 mode_t and;
588 mode_t mode = 0;
589 mode_t groups = S_ISVTX;
590 char type;
591 char c;
592
593 do {
594 for ( ; ; ) {
595 switch ( c = *s++ ) {
596 case '\0':
597 return (FALSE);
598 case 'u':
599 groups |= S_ISUID|S_IRWXU;
600 continue;
601 case 'g':
602 groups |= S_ISGID|S_IRWXG;
603 continue;
604 case 'o':
605 groups |= S_IRWXO;
606 continue;
607 case 'a':
608 groups |= S_ISUID|S_ISGID|S_IRWXU|S_IRWXG|S_IRWXO;
609 continue;
610 case '+':
611 case '=':
612 case '-':
613 type = c;
614 if ( groups == S_ISVTX ) /* The default is "all" */
615 groups |= S_ISUID|S_ISGID|S_IRWXU|S_IRWXG|S_IRWXO;
616 break;
617 default:
618 if ( c >= '0' && c <= '7' && mode == 0 && groups == S_ISVTX ) {
619 and = 0;
620 or = strtol(--s, 0, 010);
621 return (TRUE);
622 }
623 else
624 return (FALSE);
625 }
626 break;
627 }
628
629 while ( (c = *s++) != '\0' ) {
630 switch ( c ) {
631 case ',':
632 break;
633 case 'r':
634 mode |= S_IRUSR|S_IRGRP|S_IROTH;
635 continue;
636 case 'w':
637 mode |= S_IWUSR|S_IWGRP|S_IWOTH;
638 continue;
639 case 'x':
640 mode |= S_IXUSR|S_IXGRP|S_IXOTH;
641 continue;
642 case 's':
643 mode |= S_IXGRP|S_ISUID|S_ISGID;
644 continue;
645 case 't':
646 mode |= S_ISVTX;
647 continue;
648 default:
649 return (FALSE);
650 }
651 break;
652 }
653 switch ( type ) {
654 case '=':
655 and &= ~(groups);
656 /* fall through */
657 case '+':
658 or |= mode & groups;
659 break;
660 case '-':
661 and &= ~(mode & groups);
662 or &= and;
663 break;
664 }
665 } while ( c == ',' );
666 return (TRUE);
667}
668#endif
669
547/* END CODE */ 670/* END CODE */