#define cpio_full_usage \
"Extract or list files from a cpio archive\n" \
"Main operation mode:\n" \
- "\td\t\tmake directories (assumed)\n" \
+ "\td\t\tmake leading directories\n" \
"\ti\t\textract\n" \
- "\tm\t\tpreserve time\n" \
+ "\tm\t\tpreserve mtime\n" \
"\tt\t\tlist\n" \
- "\tu\t\tunconditional (assumed)\t" \
+ "\tu\t\tunconditional overwrite\t" \
"\tF\t\tinput from file\t"
#define cut_trivial_usage \
* Limitations:
* Doesn't check CRC's
* Only supports new ASCII and CRC formats
- * Doesnt support hard links
*
*/
#include <fcntl.h>
case 'i': // extract
extract_function |= extract_all_to_fs;
break;
- case 'd': // create directories
- extract_function |= extract_create_dirs;
- oldmask = umask(077); /* Make create_path act like GNU cpio */
+ case 'd': // create _leading_ directories
+ extract_function |= extract_create_leading_dirs;
+ oldmask = umask(077); /* Make make_directory act like GNU cpio */
break;
case 'm': // preserve modification time
extract_function |= extract_preserve_date;
char *output_buffer = NULL;
int opt = 0;
int arg_type = 0;
- int deb_extract_funct = extract_create_dirs | extract_unconditional;
+ int deb_extract_funct = extract_create_leading_dirs | extract_unconditional;
const int arg_type_prefix = 1;
const int arg_type_field = 2;
* Limitations:
* Doesn't check CRC's
* Only supports new ASCII and CRC formats
- * Doesnt support hard links
*
*/
#include <fcntl.h>
case 'i': // extract
extract_function |= extract_all_to_fs;
break;
- case 'd': // create directories
- extract_function |= extract_create_dirs;
- oldmask = umask(077); /* Make create_path act like GNU cpio */
+ case 'd': // create _leading_ directories
+ extract_function |= extract_create_leading_dirs;
+ oldmask = umask(077); /* Make make_directory act like GNU cpio */
break;
case 'm': // preserve modification time
extract_function |= extract_preserve_date;
directory and make your program compliant.
-Some Words on utility.c
------------------------
+Some Words on libbb
+-------------------
As you are writing your applet, please be aware of the body of pre-existing
-useful functions in utility.c. Use these instead of reinventing the wheel.
-
-If you use functions from utility.c, you may need to add to the preprocessor
-conditionals in that file, to make sure the routines you need are included.
-So, since your mu implementation used safe_read(), append "|| defined BB_MU" to
-the #if instruction that precedes the safe_read() function in utility.c .
+useful functions in libbb. Use these instead of reinventing the wheel.
Additionally, if you have any useful, general-purpose functions in your
program that could be useful in another program, consider putting them in
-utility.c.
+libbb.
Usage String(s)
---------------
-Next, add usage information for you applet to usage.c. This should look like
+Next, add usage information for you applet to usage.h. This should look like
the following:
- #if defined BB_MU
- const char mu_usage[] =
- "mu\n"
- #ifndef BB_FEATURE_TRIVIAL_HELP
- "\nReturns an indeterminate value.\n"
- #endif
- ;
+ #define mu_trivial_usage \
+ "-[abcde] FILES"
+ #define mu_full_usage \
+ "Returns an indeterminate value.\n\n" \
+ "Options:\n" \
+ "\t-a\t\tfirst function\n" \
+ "\t-b\t\tsecond function\n" \
If your program supports flags, the flags should be mentioned on the first
-line (mu -[bcRovma]) and a detailed description of each flag should go in the
-BB_FEATURE_TRIVIAL_HELP section, one flag per line. (Numerous examples of this
-currently exist in usage.c.)
+line (-[abcde]) and a detailed description of each flag should go in the
+mu_full_usage section, one flag per line. (Numerous examples of this
+currently exist in usage.h.)
Header Files
char *output_buffer = NULL;
int opt = 0;
int arg_type = 0;
- int deb_extract_funct = extract_create_dirs | extract_unconditional;
+ int deb_extract_funct = extract_create_leading_dirs | extract_unconditional;
const int arg_type_prefix = 1;
const int arg_type_field = 2;
extract_control_tar_gz = 128,
extract_unzip_only = 256,
extract_unconditional = 512,
- extract_create_dirs = 1024
+ extract_create_leading_dirs = 1024
};
char *unarchive(FILE *src_stream, void *(*get_header)(FILE *),
const int extract_function, const char *prefix, char **extract_names);
#define cpio_full_usage \
"Extract or list files from a cpio archive\n" \
"Main operation mode:\n" \
- "\td\t\tmake directories (assumed)\n" \
+ "\td\t\tmake leading directories\n" \
"\ti\t\textract\n" \
- "\tm\t\tpreserve time\n" \
+ "\tm\t\tpreserve mtime\n" \
"\tt\t\tlist\n" \
- "\tu\t\tunconditional (assumed)\t" \
+ "\tu\t\tunconditional overwrite\t" \
"\tF\t\tinput from file\t"
#define cut_trivial_usage \
extract_control_tar_gz = 128,
extract_unzip_only = 256,
extract_unconditional = 512,
- extract_create_dirs = 1024
+ extract_create_leading_dirs = 1024
};
char *unarchive(FILE *src_stream, void *(*get_header)(FILE *),
const int extract_function, const char *prefix, char **extract_names);
}
} else {
error_msg("%s not created: newer or same age file exists", file_entry->name);
- if (S_ISREG(file_entry->mode)) {
seek_sub_file(src_stream, file_entry->size);
- }
return (NULL);
}
}
+ if (function & extract_create_leading_dirs) { /* Create leading directories with default umask */
+ char *parent = dirname(full_name);
+ if (make_directory (parent, -1, FILEUTILS_RECUR) != 0) {
+ error_msg("couldn't create leading directories");
+ }
+ free (parent);
+ }
switch(file_entry->mode & S_IFMT) {
case S_IFREG:
if (file_entry->link_name) { /* Found a cpio hard link */
}
break;
case S_IFDIR:
- if ((function & extract_create_dirs) && (stat_res != 0)) {
- /* Make sure the prefix component of full_name was create
- * in applet before getting here*/
+ if (stat_res != 0) {
if (mkdir(full_name, file_entry->mode) < 0) {
perror_msg("extract_archive: ");
}
}
if (!found) {
/* seek past the data entry */
- if (!S_ISLNK(file_entry->mode) && file_entry->link_name && file_entry->size == 0) {
- error_msg("You should extract %s as other files are hardlinked to it", file_entry->name);
- }
seek_sub_file(src_stream, file_entry->size);
continue;
}
static char *ar_long_names;
if (fread(ar.raw, 1, 60, src_stream) != 60) {
+ free (ar_long_names);
return(NULL);
}
archive_offset += 60;
archive_offset += typed->size;
/* This ar entries data section only contained filenames for other records
* they are stored in the static ar_long_names for future reference */
- return(NULL);
+ return (get_header_ar(src_stream)); /* Return next header */
+ } else if (ar.formated.name[1] == ' ') {
+ /* This is the index of symbols in the file for compilers */
+ seek_sub_file(src_stream, typed->size);
+ return (get_header_ar(src_stream)); /* Return next header */
} else {
/* The number after the '/' indicates the offset in the ar data section
(saved in variable long_name) that conatains the real filename */
cpio_entry->link_name = (char *) xcalloc(1, cpio_entry->size + 1);
fread(cpio_entry->link_name, 1, cpio_entry->size, src_stream);
archive_offset += cpio_entry->size;
+ cpio_entry->size = 0; /* Stop possiable seeks in future */
}
if (nlink > 1 && !S_ISDIR(cpio_entry->mode)) {
if (cpio_entry->size == 0) { /* Put file on a linked list for later */
#define cpio_full_usage \
"Extract or list files from a cpio archive\n" \
"Main operation mode:\n" \
- "\td\t\tmake directories (assumed)\n" \
+ "\td\t\tmake leading directories\n" \
"\ti\t\textract\n" \
- "\tm\t\tpreserve time\n" \
+ "\tm\t\tpreserve mtime\n" \
"\tt\t\tlist\n" \
- "\tu\t\tunconditional (assumed)\t" \
+ "\tu\t\tunconditional overwrite\t" \
"\tF\t\tinput from file\t"
#define cut_trivial_usage \