diff options
Diffstat (limited to 'contrib/cpio')
-rw-r--r-- | contrib/cpio/README.FreeBSD | 15 | ||||
-rw-r--r-- | contrib/cpio/copyin.c | 15 | ||||
-rw-r--r-- | contrib/cpio/copyout.c | 142 | ||||
-rw-r--r-- | contrib/cpio/cpio.1 | 8 | ||||
-rw-r--r-- | contrib/cpio/extern.h | 5 | ||||
-rw-r--r-- | contrib/cpio/main.c | 12 | ||||
-rw-r--r-- | contrib/cpio/rtapelib.c | 18 | ||||
-rw-r--r-- | contrib/cpio/tcexparg.c | 240 | ||||
-rw-r--r-- | contrib/cpio/util.c | 4 |
9 files changed, 194 insertions, 265 deletions
diff --git a/contrib/cpio/README.FreeBSD b/contrib/cpio/README.FreeBSD new file mode 100644 index 0000000..ac95b1e --- /dev/null +++ b/contrib/cpio/README.FreeBSD @@ -0,0 +1,15 @@ +GNU cpio 2.4.2 + originals can be found at: ftp://prep.ai.mit.edu/pub/gnu + + removed files: + INSTALL cpio.info mkdir.c + Makefile.in cpio.texi mkinstalldirs + argmatch.c fnmatch.c mt.1 + bcopy.c fnmatch.h mt.c + configure install-sh rmt.c + configure.in makefile.os2 strdup.c + cpio.def makefile.pc tcexparg.c + texinfo.tex + + + obrien@FreeBSD.org diff --git a/contrib/cpio/copyin.c b/contrib/cpio/copyin.c index 1cc7e47..2008c39 100644 --- a/contrib/cpio/copyin.c +++ b/contrib/cpio/copyin.c @@ -18,6 +18,13 @@ #include <stdio.h> #include <sys/types.h> #include <sys/stat.h> +#ifdef HAVE_SYS_PARAM_H +#include <sys/param.h> +#endif +#if (defined(BSD) && (BSD >= 199306)) +#define HAVE_STRFTIME +#include <ctype.h> +#endif #include "filetypes.h" #include "system.h" #include "cpiohdr.h" @@ -1043,7 +1050,11 @@ long_format (file_hdr, link_name) /* Get time values ready to print. */ when = file_hdr->c_mtime; +#ifdef HAVE_STRFTIME + strftime(tbuf, sizeof(tbuf), "%c", localtime(&when)); +#else strcpy (tbuf, ctime (&when)); +#endif if (current_time - when > 6L * 30L * 24L * 60L * 60L || current_time - when < 0L) { @@ -1129,6 +1140,9 @@ print_name_with_quoting (p) break; default: +#if (defined(BSD) && (BSD >= 199306)) + if (isprint(c)) +#else if (c > 040 && #ifdef __MSDOS__ c < 0377 && c != 0177 @@ -1136,6 +1150,7 @@ print_name_with_quoting (p) c < 0177 #endif ) +#endif putchar (c); else printf ("\\%03o", (unsigned int) c); diff --git a/contrib/cpio/copyout.c b/contrib/cpio/copyout.c index 22e9a0c..39890b0 100644 --- a/contrib/cpio/copyout.c +++ b/contrib/cpio/copyout.c @@ -35,6 +35,7 @@ static void add_link_defer (); static void writeout_other_defers (); static void writeout_final_defers(); static void writeout_defered_file (); +static int check_rdev (); /* Write out header FILE_HDR, including the file name, to file descriptor OUT_DES. */ @@ -293,8 +294,32 @@ process_copy_out () file_hdr.c_uid = file_stat.st_uid; file_hdr.c_gid = file_stat.st_gid; file_hdr.c_nlink = file_stat.st_nlink; - file_hdr.c_rdev_maj = major (file_stat.st_rdev); - file_hdr.c_rdev_min = minor (file_stat.st_rdev); + + /* The rdev is meaningless except for block and character + special files (POSIX standard) and perhaps fifos and + sockets. Clear it for other types of files so that + check_rdev() doesn't reject files just because stat() + put garbage in st_rdev and so that the output doesn't + depend on the garbage. */ + switch (file_hdr.c_mode & CP_IFMT) + { + case CP_IFBLK: + case CP_IFCHR: +#ifdef CP_IFIFO + case CP_IFIFO: +#endif +#ifdef CP_IFSOCK + case CP_IFSOCK: +#endif + file_hdr.c_rdev_maj = major (file_stat.st_rdev); + file_hdr.c_rdev_min = minor (file_stat.st_rdev); + break; + default: + file_hdr.c_rdev_maj = 0; + file_hdr.c_rdev_min = 0; + break; + } + file_hdr.c_mtime = file_stat.st_mtime; file_hdr.c_filesize = file_stat.st_size; file_hdr.c_chksum = 0; @@ -338,6 +363,23 @@ process_copy_out () continue; } + switch (check_rdev (&file_hdr)) + { + case 1: + error (0, 0, "%s not dumped: major number would be truncated", + file_hdr.c_name); + continue; + case 2: + error (0, 0, "%s not dumped: minor number would be truncated", + file_hdr.c_name); + continue; + case 4: + error (0, 0, "%s not dumped: device number would be truncated", + file_hdr.c_name); + continue; + } + + /* Copy the named file to the output. */ switch (file_hdr.c_mode & CP_IFMT) { @@ -805,3 +847,99 @@ writeout_defered_file (header, out_file_des) } return; } + + +static int +check_rdev (file_hdr) + struct new_cpio_header *file_hdr; +{ + if (archive_format == arf_newascii || archive_format == arf_crcascii) + { + if ((file_hdr->c_rdev_maj & 0xFFFFFFFF) != file_hdr->c_rdev_maj) + return 1; + if ((file_hdr->c_rdev_min & 0xFFFFFFFF) != file_hdr->c_rdev_min) + return 2; + } + else if (archive_format == arf_oldascii || archive_format == arf_hpoldascii) + { +#ifndef __MSDOS__ + dev_t rdev; + + rdev = makedev (file_hdr->c_rdev_maj, file_hdr->c_rdev_min); + if (archive_format == arf_oldascii) + { + if ((rdev & 0xFFFF) != rdev) + return 4; + } + else + { + switch (file_hdr->c_mode & CP_IFMT) + { + case CP_IFCHR: + case CP_IFBLK: +#ifdef CP_IFSOCK + case CP_IFSOCK: +#endif +#ifdef CP_IFIFO + case CP_IFIFO: +#endif + /* We could handle one more bit if longs are >= 33 bits. */ + if ((rdev & 037777777777) != rdev) + return 4; + break; + default: + if ((rdev & 0xFFFF) != rdev) + return 4; + break; + } + } +#endif + } + else if (archive_format == arf_tar || archive_format == arf_ustar) + { + /* The major and minor formats are limited to 7 octal digits in ustar + format, and to_oct () adds a gratuitous trailing blank to further + limit the format to 6 octal digits. */ + if ((file_hdr->c_rdev_maj & 0777777) != file_hdr->c_rdev_maj) + return 1; + if ((file_hdr->c_rdev_min & 0777777) != file_hdr->c_rdev_min) + return 2; + } + else + { +#ifndef __MSDOS__ + dev_t rdev; + + rdev = makedev (file_hdr->c_rdev_maj, file_hdr->c_rdev_min); + if (archive_format != arf_hpbinary) + { + if ((rdev & 0xFFFF) != rdev) + return 4; + } + else + { + switch (file_hdr->c_mode & CP_IFMT) + { + case CP_IFCHR: + case CP_IFBLK: +#ifdef CP_IFSOCK + case CP_IFSOCK: +#endif +#ifdef CP_IFIFO + case CP_IFIFO: +#endif + if ((rdev & 0xFFFFFFFF) != rdev) + return 4; + file_hdr->c_filesize = rdev; + rdev = makedev (0, 1); + break; + default: + if ((rdev & 0xFFFF) != rdev) + return 4; + break; + } + } +#endif + } + return 0; +} diff --git a/contrib/cpio/cpio.1 b/contrib/cpio/cpio.1 index 0554766..2e24ee3 100644 --- a/contrib/cpio/cpio.1 +++ b/contrib/cpio/cpio.1 @@ -48,7 +48,7 @@ output. A typical way to generate the list of filenames is with the .B find command; you should give .B find -the \-depth option to minimize problems with permissions on +the \-d option to minimize problems with permissions on directories that are unwritable or not searchable. .PP In copy-in mode, @@ -92,7 +92,7 @@ and verifies when the file is extracted from the archive. The HPUX formats are provided for compatibility with HPUX's cpio which stores device files differently. .PP -The tar format is provided for compatability with +The tar format is provided for compatibility with the .B tar program. It can not be used to archive files with names @@ -230,7 +230,9 @@ Ignored; for compatibility with other versions of .BR cpio . .TP .I "\-l, \-\-link" -Link files instead of copying them, when possible. +Link files instead of copying them, when possible (usable only with the +.I \-p +option). .TP .I "\-L, \-\-dereference" Dereference symbolic links (copy the files that they point to instead diff --git a/contrib/cpio/extern.h b/contrib/cpio/extern.h index 3ff70cc..0e1344f 100644 --- a/contrib/cpio/extern.h +++ b/contrib/cpio/extern.h @@ -128,6 +128,11 @@ uid_t *getuidbyname (); gid_t *getgidbyname (); #endif +/* lchown.c */ +#ifdef HAVE_LCHOWN +int lchown P_((const char *path, uid_t owner, gid_t group)); +#endif + /* main.c */ void process_args P_((int argc, char *argv[])); void initialize_buffers P_((void)); diff --git a/contrib/cpio/main.c b/contrib/cpio/main.c index 76125f0..bba4d32 100644 --- a/contrib/cpio/main.c +++ b/contrib/cpio/main.c @@ -23,6 +23,12 @@ #include <getopt.h> #include <sys/types.h> #include <sys/stat.h> +#ifdef HAVE_SYS_PARAM_H +#include <sys/param.h> +#endif +#if (defined(BSD) && (BSD >= 199306)) +#include <locale.h> +#endif #include "filetypes.h" #include "system.h" #include "cpiohdr.h" @@ -498,7 +504,10 @@ main (argc, argv) char *argv[]; { program_name = argv[0]; - umask (0); + +#if (defined(BSD) && (BSD >= 199306)) + (void) setlocale (LC_ALL, ""); +#endif #ifdef __TURBOC__ _fmode = O_BINARY; /* Put stdin and stdout in binary mode. */ @@ -509,6 +518,7 @@ main (argc, argv) #endif process_args (argc, argv); + umask (0); initialize_buffers (); diff --git a/contrib/cpio/rtapelib.c b/contrib/cpio/rtapelib.c index eece76f..6550a6c 100644 --- a/contrib/cpio/rtapelib.c +++ b/contrib/cpio/rtapelib.c @@ -372,29 +372,13 @@ __rmt_open (path, oflag, mode, bias) if (*login) { - execl ("/usr/ucb/rsh", "rsh", system, "-l", login, - "/etc/rmt", (char *) 0); - execl ("/usr/bin/remsh", "remsh", system, "-l", login, - "/etc/rmt", (char *) 0); - execl ("/usr/bin/rsh", "rsh", system, "-l", login, - "/etc/rmt", (char *) 0); - execl ("/usr/bsd/rsh", "rsh", system, "-l", login, - "/etc/rmt", (char *) 0); - execl ("/usr/bin/nsh", "nsh", system, "-l", login, + execl ("/usr/bin/rsh", "rsh", "-l", login, system, "/etc/rmt", (char *) 0); } else { - execl ("/usr/ucb/rsh", "rsh", system, - "/etc/rmt", (char *) 0); - execl ("/usr/bin/remsh", "remsh", system, - "/etc/rmt", (char *) 0); execl ("/usr/bin/rsh", "rsh", system, "/etc/rmt", (char *) 0); - execl ("/usr/bsd/rsh", "rsh", system, - "/etc/rmt", (char *) 0); - execl ("/usr/bin/nsh", "nsh", system, - "/etc/rmt", (char *) 0); } /* Bad problems if we get here. */ diff --git a/contrib/cpio/tcexparg.c b/contrib/cpio/tcexparg.c deleted file mode 100644 index c5d88f0..0000000 --- a/contrib/cpio/tcexparg.c +++ /dev/null @@ -1,240 +0,0 @@ -/* tcexparg.c - Unix-style command line wildcards for Turbo C 2.0 - - This file is in the public domain. - - Compile your main program with -Dmain=_main and link with this file. - - After that, it is just as if the operating system had expanded the - arguments, except that they are not sorted. The program name and all - arguments that are expanded from wildcards are lowercased. - - Syntax for wildcards: - * Matches zero or more of any character (except a '.' at - the beginning of a name). - ? Matches any single character. - [r3z] Matches 'r', '3', or 'z'. - [a-d] Matches a single character in the range 'a' through 'd'. - [!a-d] Matches any single character except a character in the - range 'a' through 'd'. - - The period between the filename root and its extension need not be - given explicitly. Thus, the pattern `a*e' will match 'abacus.exe' - and 'axyz.e' as well as 'apple'. Comparisons are not case sensitive. - - Authors: - The expargs code is a modification of wildcard expansion code - written for Turbo C 1.0 by - Richard Hargrove - Texas Instruments, Inc. - P.O. Box 869305, m/s 8473 - Plano, Texas 75086 - 214/575-4128 - and posted to USENET in September, 1987. - - The wild_match code was written by Rich Salz, rsalz@bbn.com, - posted to net.sources in November, 1986. - - The code connecting the two is by Mike Slomin, bellcore!lcuxa!mike2, - posted to comp.sys.ibm.pc in November, 1988. - - Major performance enhancements and bug fixes, and source cleanup, - by David MacKenzie, djm@gnu.ai.mit.edu. */ - -#include <stdio.h> -#include <string.h> -#include <stdlib.h> -#include <dos.h> -#include <dir.h> - -/* Number of new arguments to allocate space for at a time. */ -#define ARGS_INCREMENT 10 - -/* The name this program was run with, for error messages. */ -static char *program_name; - -static char **grow_argv (char **new_argv, int new_argc); -static void fatal_error (const char *message); - -int wild_match (char *string, char *pattern); -char *basename (char *path); - -char **expargs (int *, char **); - -#ifdef main -#undef main -#endif - -int -main (int argc, char **argv, char **envp) -{ - argv = expargs (&argc, argv); - return _main (argc, argv, envp); -} - -char ** -expargs (int *pargc, char **argv) -{ - char path[MAXPATH + 1]; - char **new_argv; - struct ffblk block; - char *path_base; - char *arg_base; - int argind; - int new_argc; - int path_length; - int matched; - - program_name = argv[0]; - if (program_name && *program_name) - strlwr (program_name); - new_argv = grow_argv (NULL, 0); - new_argv[0] = argv[0]; - new_argc = 1; - - for (argind = 1; argind < *pargc; ++argind) - { - matched = 0; - if (strpbrk (argv[argind], "?*[") != NULL) - { - strncpy (path, argv[argind], MAXPATH - 3); - path_base = basename (path); - strcpy (path_base, "*.*"); - arg_base = argv[argind] + (path_base - path); - - if (!findfirst (path, &block, FA_DIREC)) - { - strlwr (path); - do - { - /* Only match "." and ".." explicitly. */ - if (*block.ff_name == '.' && *arg_base != '.') - continue; - path_length = stpcpy (path_base, block.ff_name) - path + 1; - strlwr (path_base); - if (wild_match (path, argv[argind])) - { - matched = 1; - new_argv[new_argc] = (char *) malloc (path_length); - if (new_argv[new_argc] == NULL) - fatal_error ("memory exhausted"); - strcpy (new_argv[new_argc++], path); - new_argv = grow_argv (new_argv, new_argc); - } - } while (!findnext (&block)); - } - } - if (matched == 0) - new_argv[new_argc++] = argv[argind]; - new_argv = grow_argv (new_argv, new_argc); - } - - *pargc = new_argc; - new_argv[new_argc] = NULL; - return &new_argv[0]; -} - -/* Return a pointer to the last element of PATH. */ - -char * -basename (char *path) -{ - char *tail; - - for (tail = path; *path; ++path) - if (*path == ':' || *path == '\\') - tail = path + 1; - return tail; -} - -static char ** -grow_argv (char **new_argv, int new_argc) -{ - if (new_argc % ARGS_INCREMENT == 0) - { - new_argv = (char **) realloc - (new_argv, sizeof (char *) * (new_argc + ARGS_INCREMENT)); - if (new_argv == NULL) - fatal_error ("memory exhausted"); - } - return new_argv; -} - -static void -fatal_error (const char *message) -{ - putc ('\n', stderr); - if (program_name && *program_name) - { - fputs (program_name, stderr); - fputs (": ", stderr); - } - fputs (message, stderr); - putc ('\n', stderr); - exit (1); -} - -/* Shell-style pattern matching for ?, \, [], and * characters. - I'm putting this replacement in the public domain. - - Written by Rich $alz, mirror!rs, Wed Nov 26 19:03:17 EST 1986. */ - -/* The character that inverts a character class; '!' or '^'. */ -#define INVERT '!' - -static int star (char *string, char *pattern); - -/* Return nonzero if `string' matches Unix-style wildcard pattern - `pattern'; zero if not. */ - -int -wild_match (char *string, char *pattern) -{ - int prev; /* Previous character in character class. */ - int matched; /* If 1, character class has been matched. */ - int reverse; /* If 1, character class is inverted. */ - - for (; *pattern; string++, pattern++) - switch (*pattern) - { - case '\\': - /* Literal match with following character; fall through. */ - pattern++; - default: - if (*string != *pattern) - return 0; - continue; - case '?': - /* Match anything. */ - if (*string == '\0') - return 0; - continue; - case '*': - /* Trailing star matches everything. */ - return *++pattern ? star (string, pattern) : 1; - case '[': - /* Check for inverse character class. */ - reverse = pattern[1] == INVERT; - if (reverse) - pattern++; - for (prev = 256, matched = 0; *++pattern && *pattern != ']'; - prev = *pattern) - if (*pattern == '-' - ? *string <= *++pattern && *string >= prev - : *string == *pattern) - matched = 1; - if (matched == reverse) - return 0; - continue; - } - - return *string == '\0'; -} - -static int -star (char *string, char *pattern) -{ - while (wild_match (string, pattern) == 0) - if (*++string == '\0') - return 0; - return 1; -} diff --git a/contrib/cpio/util.c b/contrib/cpio/util.c index ab2d298..216041f 100644 --- a/contrib/cpio/util.c +++ b/contrib/cpio/util.c @@ -880,9 +880,9 @@ get_next_reel (tape_des) fprintf (tty_out, "%s%d%s", new_media_message_with_number, reel_number, new_media_message_after_number); else if (archive_name) - fprintf (tty_out, "Found end of tape. Load next tape and press RETURN. "); + fprintf (tty_out, "Found end of volume. Load next volume and press RETURN. "); else - fprintf (tty_out, "Found end of tape. To continue, type device/file name when ready.\n"); + fprintf (tty_out, "Found end of volume. To continue, type device/file name when ready.\n"); fflush (tty_out); |