aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorErik Andersen <andersen@codepoet.org>2000-01-16 01:30:52 +0000
committerErik Andersen <andersen@codepoet.org>2000-01-16 01:30:52 +0000
commit05100cd4776d9900c6c12def21eae8cec2cab766 (patch)
tree504f5f30277b8017557235230ddeadd8cf797852
parent83865e3e90c7f67b65d1310c7f51ec4d908f7dac (diff)
downloadbusybox-w32-05100cd4776d9900c6c12def21eae8cec2cab766.tar.gz
busybox-w32-05100cd4776d9900c6c12def21eae8cec2cab766.tar.bz2
busybox-w32-05100cd4776d9900c6c12def21eae8cec2cab766.zip
tar creation support is now optional.
-Erik
-rw-r--r--Changelog5
-rw-r--r--archival/tar.c212
-rw-r--r--busybox.def.h3
-rw-r--r--busybox.spec6
-rw-r--r--examples/busybox.spec6
-rw-r--r--tar.c212
6 files changed, 262 insertions, 182 deletions
diff --git a/Changelog b/Changelog
index 81d4f11e0..453a69b00 100644
--- a/Changelog
+++ b/Changelog
@@ -1,3 +1,8 @@
10.42
2 * Made tar creation support in busybox tar optional.
3
4 -Erik Andersen
5
10.41 60.41
2 * New Apps: wc, hostid, logname, tty, whoami, yes -- all contributed 7 * New Apps: wc, hostid, logname, tty, whoami, yes -- all contributed
3 by Edward Betts <edward@debian.org> 8 by Edward Betts <edward@debian.org>
diff --git a/archival/tar.c b/archival/tar.c
index a53370e85..5c407864f 100644
--- a/archival/tar.c
+++ b/archival/tar.c
@@ -42,13 +42,26 @@
42#include <sys/sysmacros.h> 42#include <sys/sysmacros.h>
43 43
44 44
45#ifdef BB_FEATURE_TAR_CREATE
46
45static const char tar_usage[] = 47static const char tar_usage[] =
46"tar -[cxtvOf] [tarFileName] [FILE] ...\n\n" 48"tar -[cxtvOf] [tarFileName] [FILE] ...\n\n"
47"Create, extract, or list files from a tar file\n\n" 49"Create, extract, or list files from a tar file.\n\n"
48"Options:\n" 50"Options:\n"
49"\tc=create, x=extract, t=list contents, v=verbose,\n" 51"\tc=create, x=extract, t=list contents, v=verbose,\n"
50"\tO=extract to stdout, f=tarfile or \"-\" for stdin\n"; 52"\tO=extract to stdout, f=tarfile or \"-\" for stdin\n";
51 53
54#else
55
56static const char tar_usage[] =
57"tar -[cxtvOf] [tarFileName] [FILE] ...\n\n"
58"Extract, or list files stored in a tar file. This\n"
59"version of tar does not support creation of tar files.\n\n"
60"Options:\n"
61"\tx=extract, t=list contents, v=verbose,\n"
62"\tO=extract to stdout, f=tarfile or \"-\" for stdin\n";
63
64#endif
52 65
53 66
54/* 67/*
@@ -95,7 +108,9 @@ typedef struct {
95 */ 108 */
96static int listFlag; 109static int listFlag;
97static int extractFlag; 110static int extractFlag;
111#ifdef BB_FEATURE_TAR_CREATE
98static int createFlag; 112static int createFlag;
113#endif
99static int verboseFlag; 114static int verboseFlag;
100static int tostdoutFlag; 115static int tostdoutFlag;
101 116
@@ -133,7 +148,10 @@ static long getOctal (const char *cp, int len);
133static void readHeader (const TarHeader * hp, 148static void readHeader (const TarHeader * hp,
134 int fileCount, char **fileTable); 149 int fileCount, char **fileTable);
135 150
151static int wantFileName (const char *fileName,
152 int fileCount, char **fileTable);
136 153
154#ifdef BB_FEATURE_TAR_CREATE
137/* 155/*
138 * Local procedures to save files into a tar file. 156 * Local procedures to save files into a tar file.
139 */ 157 */
@@ -145,15 +163,14 @@ static void saveRegularFile (const char *fileName,
145static void saveDirectory (const char *fileName, 163static void saveDirectory (const char *fileName,
146 const struct stat *statbuf); 164 const struct stat *statbuf);
147 165
148static int wantFileName (const char *fileName,
149 int fileCount, char **fileTable);
150
151static void writeHeader (const char *fileName, const struct stat *statbuf); 166static void writeHeader (const char *fileName, const struct stat *statbuf);
152 167
153static void writeTarFile (int fileCount, char **fileTable); 168static void writeTarFile (int fileCount, char **fileTable);
154static void writeTarBlock (const char *buf, int len); 169static void writeTarBlock (const char *buf, int len);
155static int putOctal (char *cp, int len, long value); 170static int putOctal (char *cp, int len, long value);
156 171
172#endif
173
157 174
158extern int tar_main (int argc, char **argv) 175extern int tar_main (int argc, char **argv)
159{ 176{
@@ -168,7 +185,9 @@ extern int tar_main (int argc, char **argv)
168 185
169 errorFlag = FALSE; 186 errorFlag = FALSE;
170 extractFlag = FALSE; 187 extractFlag = FALSE;
188#ifdef BB_FEATURE_TAR_CREATE
171 createFlag = FALSE; 189 createFlag = FALSE;
190#endif
172 listFlag = FALSE; 191 listFlag = FALSE;
173 verboseFlag = FALSE; 192 verboseFlag = FALSE;
174 tostdoutFlag = FALSE; 193 tostdoutFlag = FALSE;
@@ -204,10 +223,16 @@ extern int tar_main (int argc, char **argv)
204 case 'x': 223 case 'x':
205 extractFlag = TRUE; 224 extractFlag = TRUE;
206 break; 225 break;
207 226#ifdef BB_FEATURE_TAR_CREATE
208 case 'c': 227 case 'c':
209 createFlag = TRUE; 228 createFlag = TRUE;
210 break; 229 break;
230#else
231 case 'c':
232 fprintf (stderr, "This version of tar was not compiled with tar creation support.\n" );
233
234 exit (FALSE);
235#endif
211 236
212 case 'v': 237 case 'v':
213 verboseFlag = TRUE; 238 verboseFlag = TRUE;
@@ -234,7 +259,11 @@ extern int tar_main (int argc, char **argv)
234 /* 259 /*
235 * Validate the options. 260 * Validate the options.
236 */ 261 */
237 if (extractFlag + listFlag + createFlag != (TRUE+FALSE+FALSE)) { 262 if (extractFlag + listFlag
263#ifdef BB_FEATURE_TAR_CREATE
264 + createFlag
265#endif
266 != (TRUE+FALSE+FALSE)) {
238 fprintf (stderr, 267 fprintf (stderr,
239 "Exactly one of 'c', 'x' or 't' must be specified\n"); 268 "Exactly one of 'c', 'x' or 't' must be specified\n");
240 269
@@ -245,9 +274,11 @@ extern int tar_main (int argc, char **argv)
245 * Do the correct type of action supplying the rest of the 274 * Do the correct type of action supplying the rest of the
246 * command line arguments as the list of files to process. 275 * command line arguments as the list of files to process.
247 */ 276 */
277#ifdef BB_FEATURE_TAR_CREATE
248 if (createFlag==TRUE) 278 if (createFlag==TRUE)
249 writeTarFile (argc, argv); 279 writeTarFile (argc, argv);
250 else 280 else
281#endif
251 readTarFile (argc, argv); 282 readTarFile (argc, argv);
252 if (errorFlag==TRUE) 283 if (errorFlag==TRUE)
253 fprintf (stderr, "\n"); 284 fprintf (stderr, "\n");
@@ -678,6 +709,92 @@ static void readData (const char *cp, int count)
678 709
679 710
680/* 711/*
712 * See if the specified file name belongs to one of the specified list
713 * of path prefixes. An empty list implies that all files are wanted.
714 * Returns TRUE if the file is selected.
715 */
716static int
717wantFileName (const char *fileName, int fileCount, char **fileTable)
718{
719 const char *pathName;
720 int fileLength;
721 int pathLength;
722
723 /*
724 * If there are no files in the list, then the file is wanted.
725 */
726 if (fileCount == 0)
727 return TRUE;
728
729 fileLength = strlen (fileName);
730
731 /*
732 * Check each of the test paths.
733 */
734 while (fileCount-- > 0) {
735 pathName = *fileTable++;
736
737 pathLength = strlen (pathName);
738
739 if (fileLength < pathLength)
740 continue;
741
742 if (memcmp (fileName, pathName, pathLength) != 0)
743 continue;
744
745 if ((fileLength == pathLength) || (fileName[pathLength] == '/')) {
746 return TRUE;
747 }
748 }
749
750 return FALSE;
751}
752
753/*
754 * Read an octal value in a field of the specified width, with optional
755 * spaces on both sides of the number and with an optional null character
756 * at the end. Returns -1 on an illegal format.
757 */
758static long getOctal (const char *cp, int len)
759{
760 long val;
761
762 while ((len > 0) && (*cp == ' ')) {
763 cp++;
764 len--;
765 }
766
767 if ((len == 0) || !isOctal (*cp))
768 return -1;
769
770 val = 0;
771
772 while ((len > 0) && isOctal (*cp)) {
773 val = val * 8 + *cp++ - '0';
774 len--;
775 }
776
777 while ((len > 0) && (*cp == ' ')) {
778 cp++;
779 len--;
780 }
781
782 if ((len > 0) && *cp)
783 return -1;
784
785 return val;
786}
787
788
789
790
791/* From here to the end of the file is the tar writing stuff.
792 * If you do not have BB_FEATURE_TAR_CREATE defined, this will
793 * not be built.
794 * */
795#ifdef BB_FEATURE_TAR_CREATE
796
797/*
681 * Write a tar file containing the specified files. 798 * Write a tar file containing the specified files.
682 */ 799 */
683static void writeTarFile (int fileCount, char **fileTable) 800static void writeTarFile (int fileCount, char **fileTable)
@@ -741,7 +858,6 @@ static void writeTarFile (int fileCount, char **fileTable)
741 perror (tarName); 858 perror (tarName);
742} 859}
743 860
744
745/* 861/*
746 * Save one file into the tar file. 862 * Save one file into the tar file.
747 * If the file is a directory, then this will recursively save all of 863 * If the file is a directory, then this will recursively save all of
@@ -1107,42 +1223,6 @@ static void writeTarBlock (const char *buf, int len)
1107 1223
1108 1224
1109/* 1225/*
1110 * Read an octal value in a field of the specified width, with optional
1111 * spaces on both sides of the number and with an optional null character
1112 * at the end. Returns -1 on an illegal format.
1113 */
1114static long getOctal (const char *cp, int len)
1115{
1116 long val;
1117
1118 while ((len > 0) && (*cp == ' ')) {
1119 cp++;
1120 len--;
1121 }
1122
1123 if ((len == 0) || !isOctal (*cp))
1124 return -1;
1125
1126 val = 0;
1127
1128 while ((len > 0) && isOctal (*cp)) {
1129 val = val * 8 + *cp++ - '0';
1130 len--;
1131 }
1132
1133 while ((len > 0) && (*cp == ' ')) {
1134 cp++;
1135 len--;
1136 }
1137
1138 if ((len > 0) && *cp)
1139 return -1;
1140
1141 return val;
1142}
1143
1144
1145/*
1146 * Put an octal string into the specified buffer. 1226 * Put an octal string into the specified buffer.
1147 * The number is zero and space padded and possibly null padded. 1227 * The number is zero and space padded and possibly null padded.
1148 * Returns TRUE if successful. 1228 * Returns TRUE if successful.
@@ -1190,50 +1270,6 @@ static int putOctal (char *cp, int len, long value)
1190 1270
1191 return TRUE; 1271 return TRUE;
1192} 1272}
1193 1273#endif
1194
1195/*
1196 * See if the specified file name belongs to one of the specified list
1197 * of path prefixes. An empty list implies that all files are wanted.
1198 * Returns TRUE if the file is selected.
1199 */
1200static int
1201wantFileName (const char *fileName, int fileCount, char **fileTable)
1202{
1203 const char *pathName;
1204 int fileLength;
1205 int pathLength;
1206
1207 /*
1208 * If there are no files in the list, then the file is wanted.
1209 */
1210 if (fileCount == 0)
1211 return TRUE;
1212
1213 fileLength = strlen (fileName);
1214
1215 /*
1216 * Check each of the test paths.
1217 */
1218 while (fileCount-- > 0) {
1219 pathName = *fileTable++;
1220
1221 pathLength = strlen (pathName);
1222
1223 if (fileLength < pathLength)
1224 continue;
1225
1226 if (memcmp (fileName, pathName, pathLength) != 0)
1227 continue;
1228
1229 if ((fileLength == pathLength) || (fileName[pathLength] == '/')) {
1230 return TRUE;
1231 }
1232 }
1233
1234 return FALSE;
1235}
1236
1237
1238 1274
1239/* END CODE */ 1275/* END CODE */
diff --git a/busybox.def.h b/busybox.def.h
index b8d7b9730..871b152d3 100644
--- a/busybox.def.h
+++ b/busybox.def.h
@@ -136,3 +136,6 @@
136// Enable support for loop devices in mount 136// Enable support for loop devices in mount
137#define BB_FEATURE_MOUNT_LOOP 137#define BB_FEATURE_MOUNT_LOOP
138// 138//
139// Enable support for creation of tar files.
140//#define BB_FEATURE_TAR_CREATE
141//
diff --git a/busybox.spec b/busybox.spec
index ae7010186..73f47e191 100644
--- a/busybox.spec
+++ b/busybox.spec
@@ -6,8 +6,8 @@ Summary: BusyBox is a tiny suite of Unix utilities in a multi-call binary.
6Copyright: GPL 6Copyright: GPL
7Packager : Erik Andersen <andersen@lineo.com> 7Packager : Erik Andersen <andersen@lineo.com>
8Conflicts: fileutils grep shellutils 8Conflicts: fileutils grep shellutils
9Buildroot: /tmp/%{Name}-%{Version} 9Buildroot: /tmp/%{name}-%{version}
10Source: %{Name}-%{Version}.tar.gz 10Source: %{name}-%{version}.tar.gz
11 11
12%Description 12%Description
13BusyBox is a suite of "tiny" Unix utilities in a multi-call binary. It 13BusyBox is a suite of "tiny" Unix utilities in a multi-call binary. It
@@ -18,7 +18,7 @@ is makes an excellent environment for a "rescue" disk or any small or
18embedded system. 18embedded system.
19 19
20%Prep 20%Prep
21%setup -q -n %{Name}-%{Version} 21%setup -q -n %{name}-%{version}
22 22
23%Build 23%Build
24make 24make
diff --git a/examples/busybox.spec b/examples/busybox.spec
index ae7010186..73f47e191 100644
--- a/examples/busybox.spec
+++ b/examples/busybox.spec
@@ -6,8 +6,8 @@ Summary: BusyBox is a tiny suite of Unix utilities in a multi-call binary.
6Copyright: GPL 6Copyright: GPL
7Packager : Erik Andersen <andersen@lineo.com> 7Packager : Erik Andersen <andersen@lineo.com>
8Conflicts: fileutils grep shellutils 8Conflicts: fileutils grep shellutils
9Buildroot: /tmp/%{Name}-%{Version} 9Buildroot: /tmp/%{name}-%{version}
10Source: %{Name}-%{Version}.tar.gz 10Source: %{name}-%{version}.tar.gz
11 11
12%Description 12%Description
13BusyBox is a suite of "tiny" Unix utilities in a multi-call binary. It 13BusyBox is a suite of "tiny" Unix utilities in a multi-call binary. It
@@ -18,7 +18,7 @@ is makes an excellent environment for a "rescue" disk or any small or
18embedded system. 18embedded system.
19 19
20%Prep 20%Prep
21%setup -q -n %{Name}-%{Version} 21%setup -q -n %{name}-%{version}
22 22
23%Build 23%Build
24make 24make
diff --git a/tar.c b/tar.c
index a53370e85..5c407864f 100644
--- a/tar.c
+++ b/tar.c
@@ -42,13 +42,26 @@
42#include <sys/sysmacros.h> 42#include <sys/sysmacros.h>
43 43
44 44
45#ifdef BB_FEATURE_TAR_CREATE
46
45static const char tar_usage[] = 47static const char tar_usage[] =
46"tar -[cxtvOf] [tarFileName] [FILE] ...\n\n" 48"tar -[cxtvOf] [tarFileName] [FILE] ...\n\n"
47"Create, extract, or list files from a tar file\n\n" 49"Create, extract, or list files from a tar file.\n\n"
48"Options:\n" 50"Options:\n"
49"\tc=create, x=extract, t=list contents, v=verbose,\n" 51"\tc=create, x=extract, t=list contents, v=verbose,\n"
50"\tO=extract to stdout, f=tarfile or \"-\" for stdin\n"; 52"\tO=extract to stdout, f=tarfile or \"-\" for stdin\n";
51 53
54#else
55
56static const char tar_usage[] =
57"tar -[cxtvOf] [tarFileName] [FILE] ...\n\n"
58"Extract, or list files stored in a tar file. This\n"
59"version of tar does not support creation of tar files.\n\n"
60"Options:\n"
61"\tx=extract, t=list contents, v=verbose,\n"
62"\tO=extract to stdout, f=tarfile or \"-\" for stdin\n";
63
64#endif
52 65
53 66
54/* 67/*
@@ -95,7 +108,9 @@ typedef struct {
95 */ 108 */
96static int listFlag; 109static int listFlag;
97static int extractFlag; 110static int extractFlag;
111#ifdef BB_FEATURE_TAR_CREATE
98static int createFlag; 112static int createFlag;
113#endif
99static int verboseFlag; 114static int verboseFlag;
100static int tostdoutFlag; 115static int tostdoutFlag;
101 116
@@ -133,7 +148,10 @@ static long getOctal (const char *cp, int len);
133static void readHeader (const TarHeader * hp, 148static void readHeader (const TarHeader * hp,
134 int fileCount, char **fileTable); 149 int fileCount, char **fileTable);
135 150
151static int wantFileName (const char *fileName,
152 int fileCount, char **fileTable);
136 153
154#ifdef BB_FEATURE_TAR_CREATE
137/* 155/*
138 * Local procedures to save files into a tar file. 156 * Local procedures to save files into a tar file.
139 */ 157 */
@@ -145,15 +163,14 @@ static void saveRegularFile (const char *fileName,
145static void saveDirectory (const char *fileName, 163static void saveDirectory (const char *fileName,
146 const struct stat *statbuf); 164 const struct stat *statbuf);
147 165
148static int wantFileName (const char *fileName,
149 int fileCount, char **fileTable);
150
151static void writeHeader (const char *fileName, const struct stat *statbuf); 166static void writeHeader (const char *fileName, const struct stat *statbuf);
152 167
153static void writeTarFile (int fileCount, char **fileTable); 168static void writeTarFile (int fileCount, char **fileTable);
154static void writeTarBlock (const char *buf, int len); 169static void writeTarBlock (const char *buf, int len);
155static int putOctal (char *cp, int len, long value); 170static int putOctal (char *cp, int len, long value);
156 171
172#endif
173
157 174
158extern int tar_main (int argc, char **argv) 175extern int tar_main (int argc, char **argv)
159{ 176{
@@ -168,7 +185,9 @@ extern int tar_main (int argc, char **argv)
168 185
169 errorFlag = FALSE; 186 errorFlag = FALSE;
170 extractFlag = FALSE; 187 extractFlag = FALSE;
188#ifdef BB_FEATURE_TAR_CREATE
171 createFlag = FALSE; 189 createFlag = FALSE;
190#endif
172 listFlag = FALSE; 191 listFlag = FALSE;
173 verboseFlag = FALSE; 192 verboseFlag = FALSE;
174 tostdoutFlag = FALSE; 193 tostdoutFlag = FALSE;
@@ -204,10 +223,16 @@ extern int tar_main (int argc, char **argv)
204 case 'x': 223 case 'x':
205 extractFlag = TRUE; 224 extractFlag = TRUE;
206 break; 225 break;
207 226#ifdef BB_FEATURE_TAR_CREATE
208 case 'c': 227 case 'c':
209 createFlag = TRUE; 228 createFlag = TRUE;
210 break; 229 break;
230#else
231 case 'c':
232 fprintf (stderr, "This version of tar was not compiled with tar creation support.\n" );
233
234 exit (FALSE);
235#endif
211 236
212 case 'v': 237 case 'v':
213 verboseFlag = TRUE; 238 verboseFlag = TRUE;
@@ -234,7 +259,11 @@ extern int tar_main (int argc, char **argv)
234 /* 259 /*
235 * Validate the options. 260 * Validate the options.
236 */ 261 */
237 if (extractFlag + listFlag + createFlag != (TRUE+FALSE+FALSE)) { 262 if (extractFlag + listFlag
263#ifdef BB_FEATURE_TAR_CREATE
264 + createFlag
265#endif
266 != (TRUE+FALSE+FALSE)) {
238 fprintf (stderr, 267 fprintf (stderr,
239 "Exactly one of 'c', 'x' or 't' must be specified\n"); 268 "Exactly one of 'c', 'x' or 't' must be specified\n");
240 269
@@ -245,9 +274,11 @@ extern int tar_main (int argc, char **argv)
245 * Do the correct type of action supplying the rest of the 274 * Do the correct type of action supplying the rest of the
246 * command line arguments as the list of files to process. 275 * command line arguments as the list of files to process.
247 */ 276 */
277#ifdef BB_FEATURE_TAR_CREATE
248 if (createFlag==TRUE) 278 if (createFlag==TRUE)
249 writeTarFile (argc, argv); 279 writeTarFile (argc, argv);
250 else 280 else
281#endif
251 readTarFile (argc, argv); 282 readTarFile (argc, argv);
252 if (errorFlag==TRUE) 283 if (errorFlag==TRUE)
253 fprintf (stderr, "\n"); 284 fprintf (stderr, "\n");
@@ -678,6 +709,92 @@ static void readData (const char *cp, int count)
678 709
679 710
680/* 711/*
712 * See if the specified file name belongs to one of the specified list
713 * of path prefixes. An empty list implies that all files are wanted.
714 * Returns TRUE if the file is selected.
715 */
716static int
717wantFileName (const char *fileName, int fileCount, char **fileTable)
718{
719 const char *pathName;
720 int fileLength;
721 int pathLength;
722
723 /*
724 * If there are no files in the list, then the file is wanted.
725 */
726 if (fileCount == 0)
727 return TRUE;
728
729 fileLength = strlen (fileName);
730
731 /*
732 * Check each of the test paths.
733 */
734 while (fileCount-- > 0) {
735 pathName = *fileTable++;
736
737 pathLength = strlen (pathName);
738
739 if (fileLength < pathLength)
740 continue;
741
742 if (memcmp (fileName, pathName, pathLength) != 0)
743 continue;
744
745 if ((fileLength == pathLength) || (fileName[pathLength] == '/')) {
746 return TRUE;
747 }
748 }
749
750 return FALSE;
751}
752
753/*
754 * Read an octal value in a field of the specified width, with optional
755 * spaces on both sides of the number and with an optional null character
756 * at the end. Returns -1 on an illegal format.
757 */
758static long getOctal (const char *cp, int len)
759{
760 long val;
761
762 while ((len > 0) && (*cp == ' ')) {
763 cp++;
764 len--;
765 }
766
767 if ((len == 0) || !isOctal (*cp))
768 return -1;
769
770 val = 0;
771
772 while ((len > 0) && isOctal (*cp)) {
773 val = val * 8 + *cp++ - '0';
774 len--;
775 }
776
777 while ((len > 0) && (*cp == ' ')) {
778 cp++;
779 len--;
780 }
781
782 if ((len > 0) && *cp)
783 return -1;
784
785 return val;
786}
787
788
789
790
791/* From here to the end of the file is the tar writing stuff.
792 * If you do not have BB_FEATURE_TAR_CREATE defined, this will
793 * not be built.
794 * */
795#ifdef BB_FEATURE_TAR_CREATE
796
797/*
681 * Write a tar file containing the specified files. 798 * Write a tar file containing the specified files.
682 */ 799 */
683static void writeTarFile (int fileCount, char **fileTable) 800static void writeTarFile (int fileCount, char **fileTable)
@@ -741,7 +858,6 @@ static void writeTarFile (int fileCount, char **fileTable)
741 perror (tarName); 858 perror (tarName);
742} 859}
743 860
744
745/* 861/*
746 * Save one file into the tar file. 862 * Save one file into the tar file.
747 * If the file is a directory, then this will recursively save all of 863 * If the file is a directory, then this will recursively save all of
@@ -1107,42 +1223,6 @@ static void writeTarBlock (const char *buf, int len)
1107 1223
1108 1224
1109/* 1225/*
1110 * Read an octal value in a field of the specified width, with optional
1111 * spaces on both sides of the number and with an optional null character
1112 * at the end. Returns -1 on an illegal format.
1113 */
1114static long getOctal (const char *cp, int len)
1115{
1116 long val;
1117
1118 while ((len > 0) && (*cp == ' ')) {
1119 cp++;
1120 len--;
1121 }
1122
1123 if ((len == 0) || !isOctal (*cp))
1124 return -1;
1125
1126 val = 0;
1127
1128 while ((len > 0) && isOctal (*cp)) {
1129 val = val * 8 + *cp++ - '0';
1130 len--;
1131 }
1132
1133 while ((len > 0) && (*cp == ' ')) {
1134 cp++;
1135 len--;
1136 }
1137
1138 if ((len > 0) && *cp)
1139 return -1;
1140
1141 return val;
1142}
1143
1144
1145/*
1146 * Put an octal string into the specified buffer. 1226 * Put an octal string into the specified buffer.
1147 * The number is zero and space padded and possibly null padded. 1227 * The number is zero and space padded and possibly null padded.
1148 * Returns TRUE if successful. 1228 * Returns TRUE if successful.
@@ -1190,50 +1270,6 @@ static int putOctal (char *cp, int len, long value)
1190 1270
1191 return TRUE; 1271 return TRUE;
1192} 1272}
1193 1273#endif
1194
1195/*
1196 * See if the specified file name belongs to one of the specified list
1197 * of path prefixes. An empty list implies that all files are wanted.
1198 * Returns TRUE if the file is selected.
1199 */
1200static int
1201wantFileName (const char *fileName, int fileCount, char **fileTable)
1202{
1203 const char *pathName;
1204 int fileLength;
1205 int pathLength;
1206
1207 /*
1208 * If there are no files in the list, then the file is wanted.
1209 */
1210 if (fileCount == 0)
1211 return TRUE;
1212
1213 fileLength = strlen (fileName);
1214
1215 /*
1216 * Check each of the test paths.
1217 */
1218 while (fileCount-- > 0) {
1219 pathName = *fileTable++;
1220
1221 pathLength = strlen (pathName);
1222
1223 if (fileLength < pathLength)
1224 continue;
1225
1226 if (memcmp (fileName, pathName, pathLength) != 0)
1227 continue;
1228
1229 if ((fileLength == pathLength) || (fileName[pathLength] == '/')) {
1230 return TRUE;
1231 }
1232 }
1233
1234 return FALSE;
1235}
1236
1237
1238 1274
1239/* END CODE */ 1275/* END CODE */