From 912f69ad8d7f11abc252ad5538485450e2d9c54e Mon Sep 17 00:00:00 2001 From: gritter <> Date: Mon, 1 Oct 2007 11:39:09 +0000 Subject: [PATCH 01/24] * w, whodo: On a 32-bit system where /proc/kcore is larger than 2 GB, avoid a harmless error message (bug reported by Pierre Gentile). --- CHANGES | 4 ++++ whodo/whodo.c | 8 ++++---- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/CHANGES b/CHANGES index 5060b8a..18725d5 100644 --- a/CHANGES +++ b/CHANGES @@ -1,3 +1,7 @@ +Release ... +* w, whodo: On a 32-bit system where /proc/kcore is larger than 2 GB, + avoid a harmless error message (bug reported by Pierre Gentile). + Release 070715 * cpio: A "-P" option has been introduced that allows to specify attributes like the file owner when creating an archive. With it, unprivileged users diff --git a/whodo/whodo.c b/whodo/whodo.c index e7448c0..c196590 100644 --- a/whodo/whodo.c +++ b/whodo/whodo.c @@ -34,7 +34,7 @@ #else #define USED #endif -static const char sccsid[] USED = "@(#)whodo.sl 1.42 (gritter) 1/12/07"; +static const char sccsid[] USED = "@(#)whodo.sl 1.43 (gritter) 10/1/07"; #include #include @@ -1014,6 +1014,9 @@ getproc(char *pname) wchar_t wc; int n; + strtol(pname, &ep, 10); + if (*ep != '\0') + return NULL; strcpy(fn, "/proc/"); strcat(fn, pname); if (lstat(fn, &st) < 0) { @@ -1022,9 +1025,6 @@ getproc(char *pname) } if (!S_ISDIR(st.st_mode)) return NULL; - strtol(pname, &ep, 10); - if (*ep != '\0') - return NULL; if ((p = readproc(fn)) != NULL) { ep = p->p_cmdline; while (next(wc, ep, n), wc != '\0') { From 0960b5f6f7d35166208a8f07365abcd096e48944 Mon Sep 17 00:00:00 2001 From: gritter <> Date: Sun, 28 Oct 2007 00:17:47 +0000 Subject: [PATCH 02/24] Added missing dependencies for make -j2. --- libwchar/Makefile.mk | 2 ++ nawk/Makefile.mk | 4 ++++ oawk/Makefile.mk | 12 ++++++------ 3 files changed, 12 insertions(+), 6 deletions(-) diff --git a/libwchar/Makefile.mk b/libwchar/Makefile.mk index e4def5d..1eea8c0 100644 --- a/libwchar/Makefile.mk +++ b/libwchar/Makefile.mk @@ -13,6 +13,8 @@ fake: ar r libwchar.a $(OBJ); \ fi +.NO_PARALLEL: fake + install: clean: diff --git a/nawk/Makefile.mk b/nawk/Makefile.mk index 22fc5f8..b4b8578 100644 --- a/nawk/Makefile.mk +++ b/nawk/Makefile.mk @@ -17,6 +17,10 @@ awk.g.c: awk.g.y (echo '1i'; echo '#include '; echo '.'; echo 'w';) | \ ed -s y.tab.h +y.tab.h: awk.g.c + +.NO_PARALLEL: awk.g.c awk.g.2001.c + awk.g.2001.c: awk.g.2001.y awk.g.c $(YACC) awk.g.2001.y mv -f y.tab.c awk.g.2001.c diff --git a/oawk/Makefile.mk b/oawk/Makefile.mk index 5f701ce..86316cb 100644 --- a/oawk/Makefile.mk +++ b/oawk/Makefile.mk @@ -37,25 +37,25 @@ awk.g.o: awk.g.c awk.lx.o: awk.lx.c awk.h $(CC) $(CFLAGSS) $(CPPFLAGS) $(XO5FL) $(LARGEF) $(IUXRE) $(ICOMMON) $(IWCHAR) -c awk.lx.c -b.o: b.c +b.o: b.c awk.h $(CC) $(CFLAGSS) $(CPPFLAGS) $(XO5FL) $(LARGEF) $(IUXRE) $(ICOMMON) $(IWCHAR) -c b.c -lib.o: lib.c +lib.o: lib.c awk.h $(CC) $(CFLAGSS) $(CPPFLAGS) $(XO5FL) $(LARGEF) $(IUXRE) $(ICOMMON) $(IWCHAR) -c lib.c -main.o: main.c +main.o: main.c awk.h $(CC) $(CFLAGSS) $(CPPFLAGS) $(XO5FL) $(LARGEF) $(IUXRE) $(ICOMMON) $(IWCHAR) -c main.c -parse.o: parse.c +parse.o: parse.c awk.h $(CC) $(CFLAGSS) $(CPPFLAGS) $(XO5FL) $(LARGEF) $(IUXRE) $(ICOMMON) $(IWCHAR) -c parse.c proctab.o: proctab.c $(CC) $(CFLAGSS) $(CPPFLAGS) $(XO5FL) $(LARGEF) $(IUXRE) $(ICOMMON) $(IWCHAR) -c proctab.c -run.o: run.c +run.o: run.c awk.h $(CC) $(CFLAGSS) $(CPPFLAGS) $(XO5FL) $(LARGEF) $(IUXRE) $(ICOMMON) $(IWCHAR) -c run.c -tran.o: tran.c +tran.o: tran.c awk.h $(CC) $(CFLAGSS) $(CPPFLAGS) $(XO5FL) $(LARGEF) $(IUXRE) $(ICOMMON) $(IWCHAR) -c tran.c token.o: token.c From 3966f5cbc72b004ca66eea0fe22d7b5db843b261 Mon Sep 17 00:00:00 2001 From: gritter <> Date: Sun, 16 Dec 2007 11:38:14 +0000 Subject: [PATCH 03/24] * mknod: Mac OS X Leopard compilation fix. --- CHANGES | 1 + mknod/mknod.c | 3 ++- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/CHANGES b/CHANGES index 18725d5..47979fc 100644 --- a/CHANGES +++ b/CHANGES @@ -1,4 +1,5 @@ Release ... +* mknod: Mac OS X Leopard compilation fix. * w, whodo: On a 32-bit system where /proc/kcore is larger than 2 GB, avoid a harmless error message (bug reported by Pierre Gentile). diff --git a/mknod/mknod.c b/mknod/mknod.c index b772b88..7172314 100644 --- a/mknod/mknod.c +++ b/mknod/mknod.c @@ -32,11 +32,12 @@ #else #define USED #endif -static const char sccsid[] USED = "@(#)mknod.sl 1.8 (gritter) 5/29/05"; +static const char sccsid[] USED = "@(#)mknod.sl 1.9 (gritter) 12/16/07"; #if defined (__GLIBC__) || defined (_AIX) #include #endif /* __GLIBC__ || _AIX */ +#include #include #include #include From 221d3bb11620c55aa5d1801b09ff3447020294a7 Mon Sep 17 00:00:00 2001 From: gritter <> Date: Sun, 16 Dec 2007 12:09:42 +0000 Subject: [PATCH 04/24] pgrep: Mac OS X Leopard compilation fix. --- CHANGES | 2 +- pgrep/pgrep.c | 4 +++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/CHANGES b/CHANGES index 47979fc..f5f70f7 100644 --- a/CHANGES +++ b/CHANGES @@ -1,5 +1,5 @@ Release ... -* mknod: Mac OS X Leopard compilation fix. +* mknod, pgrep: Mac OS X Leopard compilation fix. * w, whodo: On a 32-bit system where /proc/kcore is larger than 2 GB, avoid a harmless error message (bug reported by Pierre Gentile). diff --git a/pgrep/pgrep.c b/pgrep/pgrep.c index 102269c..c86b232 100644 --- a/pgrep/pgrep.c +++ b/pgrep/pgrep.c @@ -32,7 +32,7 @@ #else #define USED #endif -static const char sccsid[] USED = "@(#)pgrep.sl 1.24 (gritter) 1/12/07"; +static const char sccsid[] USED = "@(#)pgrep.sl 1.25 (gritter) 12/16/07"; #include #include @@ -70,7 +70,9 @@ static const char sccsid[] USED = "@(#)pgrep.sl 1.24 (gritter) 1/12/07"; #endif /* !__linux__, !__NetBSD__, !__OpenBSD__ */ #if defined (__NetBSD__) || defined (__OpenBSD__) || defined (__APPLE__) +#ifndef __APPLE__ #include +#endif #include #include #if defined (__APPLE__) From bb78d824514b1622dc453727cdee0ef826ee0053 Mon Sep 17 00:00:00 2001 From: gritter <> Date: Sun, 16 Dec 2007 12:13:00 +0000 Subject: [PATCH 05/24] ps: Mac OS X Leopard compilation fix. --- CHANGES | 2 +- ps/ps.c | 11 ++++++----- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/CHANGES b/CHANGES index f5f70f7..3578585 100644 --- a/CHANGES +++ b/CHANGES @@ -1,5 +1,5 @@ Release ... -* mknod, pgrep: Mac OS X Leopard compilation fix. +* mknod, pgrep, ps: Mac OS X Leopard compilation fix. * w, whodo: On a 32-bit system where /proc/kcore is larger than 2 GB, avoid a harmless error message (bug reported by Pierre Gentile). diff --git a/ps/ps.c b/ps/ps.c index a15aaf1..ef0b2ee 100644 --- a/ps/ps.c +++ b/ps/ps.c @@ -33,16 +33,16 @@ #define USED #endif #if defined (S42) -static const char sccsid[] USED = "@(#)ps_s42.sl 2.114 (gritter) 1/12/07"; +static const char sccsid[] USED = "@(#)ps_s42.sl 2.115 (gritter) 12/16/07"; #elif defined (SUS) -static const char sccsid[] USED = "@(#)ps_sus.sl 2.114 (gritter) 1/12/07"; +static const char sccsid[] USED = "@(#)ps_sus.sl 2.115 (gritter) 12/16/07"; #elif defined (UCB) -static const char sccsid[] USED = "@(#)/usr/ucb/ps.sl 2.114 (gritter) 1/12/07"; +static const char sccsid[] USED = "@(#)/usr/ucb/ps.sl 2.115 (gritter) 12/16/07"; #else -static const char sccsid[] USED = "@(#)ps.sl 2.114 (gritter) 1/12/07"; +static const char sccsid[] USED = "@(#)ps.sl 2.115 (gritter) 12/16/07"; #endif -static const char cacheid[] = "@(#)/tmp/ps_cache 2.114 (gritter) 1/12/07"; +static const char cacheid[] = "@(#)/tmp/ps_cache 2.115 (gritter) 12/16/07"; #if !defined (__linux__) && !defined (__sun) && !defined (__FreeBSD__) \ && !defined (__DragonFly__) @@ -130,6 +130,7 @@ static const char cacheid[] = "@(#)/tmp/ps_cache 2.114 (gritter) 1/12/07"; #define SCHED_OTHER 1 #endif #elif defined (__APPLE__) +#include #include #include #include From 80c941be3cd794beb69890d788e26c5fb7216c27 Mon Sep 17 00:00:00 2001 From: gritter <> Date: Sun, 16 Dec 2007 13:20:18 +0000 Subject: [PATCH 06/24] mac os x leopard has alloca.h --- libcommon/CHECK.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/libcommon/CHECK.c b/libcommon/CHECK.c index f0a824f..69b360a 100644 --- a/libcommon/CHECK.c +++ b/libcommon/CHECK.c @@ -19,7 +19,7 @@ * * 3. This notice may not be removed or altered from any source distribution. */ -/* Sccsid @(#)CHECK.c 1.7 (gritter) 1/22/06 */ +/* Sccsid @(#)CHECK.c 1.8 (gritter) 12/16/07 */ #include @@ -30,7 +30,10 @@ #endif #ifdef __APPLE__ +#include +#if __MAC_OS_X_VERSION_MIN_REQUIRED < __MAC_OS_X_VERSION_10_5 #define NEED_ALLOCA_H 1 +#endif #define NEED_MALLOC_H 1 #define NEED_UTMPX_H 1 #endif From 3db6701ae74f481855ba72c814df2ff0cd01dbcb Mon Sep 17 00:00:00 2001 From: gritter <> Date: Sun, 16 Dec 2007 20:44:54 +0000 Subject: [PATCH 07/24] * Made the getopt() substitute work with the getopt$UNIX2003() function redirection mechanism on Mac OS X Leopard. --- CHANGES | 4 +++- libcommon/getopt.c | 18 +++++++++++++++++- 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/CHANGES b/CHANGES index 3578585..3729d47 100644 --- a/CHANGES +++ b/CHANGES @@ -1,5 +1,7 @@ Release ... -* mknod, pgrep, ps: Mac OS X Leopard compilation fix. +* Made the getopt() substitute work with the getopt$UNIX2003() function + redirection mechanism on Mac OS X Leopard. +* mknod, pgrep, ps: Mac OS X Leopard compilation fixes. * w, whodo: On a 32-bit system where /proc/kcore is larger than 2 GB, avoid a harmless error message (bug reported by Pierre Gentile). diff --git a/libcommon/getopt.c b/libcommon/getopt.c index 94e0376..0a68ac8 100644 --- a/libcommon/getopt.c +++ b/libcommon/getopt.c @@ -4,7 +4,7 @@ * Gunnar Ritter, Freiburg i. Br., Germany, March 2002. */ -/* Sccsid @(#)getopt.c 1.5 (gritter) 4/2/07 */ +/* Sccsid @(#)getopt.c 1.6 (gritter) 12/16/07 */ #include #include @@ -123,3 +123,19 @@ getopt(int argc, char *const argv[], const char *optstring) optarg = 0; return '?'; } + +#ifdef __APPLE__ +/* + * Starting with Mac OS 10.5 Leopard, turns getopt() + * into getopt$UNIX2003() by default. Consequently, this function + * is called instead of the one defined above. However, optind is + * still taken from this file, so in effect, options are not + * properly handled. Defining an own getopt$UNIX2003() function + * works around this issue. + */ +int +getopt$UNIX2003(int argc, char *const argv[], const char *optstring) +{ + return getopt(argc, argv, optstring); +} +#endif /* __APPLE__ */ From 51564f6d55ba62287164d4a657b671ce7aa8f7ea Mon Sep 17 00:00:00 2001 From: gritter <> Date: Sun, 16 Dec 2007 21:07:08 +0000 Subject: [PATCH 08/24] Use the native utmpx on Mac OS X Leopard. --- libcommon/utmpx.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/libcommon/utmpx.c b/libcommon/utmpx.c index 7a1017b..d88a627 100644 --- a/libcommon/utmpx.c +++ b/libcommon/utmpx.c @@ -19,13 +19,15 @@ * * 3. This notice may not be removed or altered from any source distribution. */ -/* Sccsid @(#)utmpx.c 1.12 (gritter) 1/22/06 */ +/* Sccsid @(#)utmpx.c 1.13 (gritter) 12/16/07 */ #include #if defined (__FreeBSD__) || defined (__dietlibc__) || defined (__NetBSD__) || \ defined (__UCLIBC__) || defined (__OpenBSD__) || \ - defined (__DragonFly__) || defined (__APPLE__) + defined (__DragonFly__) || \ + defined (__APPLE__) && \ + (__MAC_OS_X_VERSION_MIN_REQUIRED < __MAC_OS_X_VERSION_10_5) #include #include #include From 8dc0df6a25ef19bbf8fd5ed5aefedc4ea502e6a6 Mon Sep 17 00:00:00 2001 From: gritter <> Date: Sun, 16 Dec 2007 21:13:37 +0000 Subject: [PATCH 09/24] Mac OS X Leopard has no updwtmpx() in its new utmpx function suite. --- date/date.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/date/date.c b/date/date.c index bd61bb4..dc4988d 100644 --- a/date/date.c +++ b/date/date.c @@ -33,9 +33,9 @@ #define USED #endif #if defined (SUS) -static const char sccsid[] USED = "@(#)date_sus.sl 1.26 (gritter) 1/22/06"; +static const char sccsid[] USED = "@(#)date_sus.sl 1.27 (gritter) 12/16/07"; #else -static const char sccsid[] USED = "@(#)date.sl 1.26 (gritter) 1/22/06"; +static const char sccsid[] USED = "@(#)date.sl 1.27 (gritter) 12/16/07"; #endif #include @@ -175,10 +175,10 @@ settime(char *op) if (bflag == 0) { pututxline(&before); pututxline(&after); -#if !defined (__hpux) && !defined (_AIX) +#if !defined (__hpux) && !defined (_AIX) && !defined(__APPLE__) updwtmpx(wtmpxfile, &before); updwtmpx(wtmpxfile, &after); -#endif /* !__hpux, !__AIX */ +#endif /* !__hpux, !__AIX, !__APPLE__ */ } exit(0); } From f24b80cf29f5fe6a598bd0b99ebb83cb0ddd125d Mon Sep 17 00:00:00 2001 From: gritter <> Date: Tue, 19 Aug 2008 13:22:01 +0000 Subject: [PATCH 10/24] Clarify that -R shows memory usage in pages. --- ps/ps.1 | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/ps/ps.1 b/ps/ps.1 index 8c70e9d..7ba6711 100644 --- a/ps/ps.1 +++ b/ps/ps.1 @@ -1,5 +1,5 @@ '\" t -.\" Sccsid @(#)ps.1 1.47 (gritter) 10/13/05 +.\" Sccsid @(#)ps.1 1.48 (gritter) 8/19/08 .\" Parts taken from ps(1), Unix 7th edition: .\" Copyright(C) Caldera International Inc. 2001-2002. All rights reserved. .\" @@ -32,7 +32,7 @@ .\" WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE .\" OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, .\" EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -.TH PS 1 "10/13/05" "Heirloom Toolchest" "User Commands" +.TH PS 1 "8/19/08" "Heirloom Toolchest" "User Commands" .SH NAME ps \- process status .SH SYNOPSIS @@ -226,7 +226,7 @@ Disables printing of flags and memory address. .B \-R Resource usage format; prints process id, -memory and resident set size, +memory and resident set size in pages, buffer reads and writes, messages sent and received, user and system time, From e0ac7a23dca2f46bc356377dcebb56e194f7cb37 Mon Sep 17 00:00:00 2001 From: gritter <> Date: Fri, 19 Dec 2008 00:16:01 +0000 Subject: [PATCH 11/24] * ptime: Works on recent Linux kernels again. --- CHANGES | 1 + time/time.c | 42 +++++++++++++++++++++++++++--------------- 2 files changed, 28 insertions(+), 15 deletions(-) diff --git a/CHANGES b/CHANGES index 3729d47..2ec030b 100644 --- a/CHANGES +++ b/CHANGES @@ -4,6 +4,7 @@ Release ... * mknod, pgrep, ps: Mac OS X Leopard compilation fixes. * w, whodo: On a 32-bit system where /proc/kcore is larger than 2 GB, avoid a harmless error message (bug reported by Pierre Gentile). +* ptime: Works on recent Linux kernels again. Release 070715 * cpio: A "-P" option has been introduced that allows to specify attributes diff --git a/time/time.c b/time/time.c index d096098..a486129 100644 --- a/time/time.c +++ b/time/time.c @@ -33,9 +33,9 @@ #define USED #endif #ifdef PTIME -static const char sccsid[] USED = "@(#)ptime.sl 1.28 (gritter) 5/29/05"; +static const char sccsid[] USED = "@(#)ptime.sl 1.29 (gritter) 12/19/08"; #else -static const char sccsid[] USED = "@(#)time.sl 1.28 (gritter) 5/29/05"; +static const char sccsid[] USED = "@(#)time.sl 1.29 (gritter) 12/19/08"; #endif #include @@ -52,6 +52,7 @@ static const char sccsid[] USED = "@(#)time.sl 1.28 (gritter) 5/29/05"; #include #ifdef PTIME #include +#include #endif #include @@ -303,6 +304,18 @@ child(char **av) _exit(err == ENOENT ? 0177 : 0176); } +#ifdef PTIME +sigjmp_buf jmpbuf; + +/* + * SIGCHLD signal handler. + */ +void onchld(int signo) +{ + siglongjmp(jmpbuf, 1); +} +#endif + /* * Time a command. */ @@ -322,6 +335,10 @@ timecmd(char **av) oldint = sigset(SIGINT, SIG_IGN); oldquit = sigset(SIGQUIT, SIG_IGN); +#ifdef PTIME + sigset(SIGCHLD, onchld); + sighold(SIGCHLD); +#endif t1 = times(&tp); switch (pid = fork()) { case 0: @@ -334,25 +351,24 @@ timecmd(char **av) return 1; } #ifdef PTIME - /* - * Changing to the child's /proc entry will keep it in zombie status - * even after it has been waited for. - */ snprintf(pdir, sizeof pdir, "/proc/%lu", (long)pid); if (chdir(pdir) < 0) { pnerror(errno, pdir); return 1; } - /* - * Starting with Linux 2.4.5, the stat file has to be opened to - * make it persistent. - */ if ((fp = fopen(stfn, "r")) == NULL) { pnerror(errno, stfn); return 1; } + if (sigsetjmp(jmpbuf, 0) == 0) { + sigrelse(SIGCHLD); + pause(); + } + write(0, 0, 0); + if (ptimes(&tp, fp, stfn) < 0) + return 1; #endif - while (wait(&status) != pid); + while (waitpid(pid, &status, 0) != pid); t2 = times(&tp); sigset(SIGINT, oldint); sigset(SIGQUIT, oldquit); @@ -361,10 +377,6 @@ timecmd(char **av) progname); else fprintf(stderr, "\n"); -#ifdef PTIME - if (ptimes(&tp, fp, stfn) < 0) - return 1; -#endif out("real", t2 - t1); out("user", tp.tms_cutime); out("sys", tp.tms_cstime); From 7d998e7eb9c72a43a15ae09b8a7b1af311a3f7ea Mon Sep 17 00:00:00 2001 From: gritter <> Date: Fri, 19 Dec 2008 00:19:44 +0000 Subject: [PATCH 12/24] fix for last fix --- time/time.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/time/time.c b/time/time.c index a486129..cfabebe 100644 --- a/time/time.c +++ b/time/time.c @@ -33,9 +33,9 @@ #define USED #endif #ifdef PTIME -static const char sccsid[] USED = "@(#)ptime.sl 1.29 (gritter) 12/19/08"; +static const char sccsid[] USED = "@(#)ptime.sl 1.30 (gritter) 12/19/08"; #else -static const char sccsid[] USED = "@(#)time.sl 1.29 (gritter) 12/19/08"; +static const char sccsid[] USED = "@(#)time.sl 1.30 (gritter) 12/19/08"; #endif #include @@ -364,12 +364,14 @@ timecmd(char **av) sigrelse(SIGCHLD); pause(); } - write(0, 0, 0); + t2 = times(&tp); if (ptimes(&tp, fp, stfn) < 0) return 1; #endif while (waitpid(pid, &status, 0) != pid); +#ifndef PTIME t2 = times(&tp); +#endif sigset(SIGINT, oldint); sigset(SIGQUIT, oldquit); if (WIFSIGNALED(status)) From 5a97464e5fb0bcf563cf35bc9a6d381c5c700f5a Mon Sep 17 00:00:00 2001 From: gritter <> Date: Sat, 14 Feb 2009 13:45:45 +0000 Subject: [PATCH 13/24] * cpio: Skip over zip extra headers with fewer than four bytes (the minimum length for them to contain any information) instead of reporting a bad header and terminating. --- CHANGES | 3 +++ cpio/cpio.c | 4 +++- cpio/version.c | 4 ++-- 3 files changed, 8 insertions(+), 3 deletions(-) diff --git a/CHANGES b/CHANGES index 2ec030b..e406e9d 100644 --- a/CHANGES +++ b/CHANGES @@ -1,4 +1,7 @@ Release ... +* cpio: Skip over zip extra headers with fewer than four bytes (the minimum + length for them to contain any information) instead of reporting a bad + header and terminating. * Made the getopt() substitute work with the getopt$UNIX2003() function redirection mechanism on Mac OS X Leopard. * mknod, pgrep, ps: Mac OS X Leopard compilation fixes. diff --git a/cpio/cpio.c b/cpio/cpio.c index 89c5cbc..bc256ed 100644 --- a/cpio/cpio.c +++ b/cpio/cpio.c @@ -26,7 +26,7 @@ */ /* - * Sccsid @(#)cpio.c 1.303 (gritter) 4/14/07 + * Sccsid @(#)cpio.c 1.304 (gritter) 2/14/09 */ #include @@ -5717,6 +5717,8 @@ ziprxtra(struct file *f, struct zip_header *z) x = smalloc(len); if (bread((char *)x, len) != len) return -1; + if (len < 4) + return len; xp = x; while (len > 0) { if (len < 4) diff --git a/cpio/version.c b/cpio/version.c index a2e02b0..dbdf037 100644 --- a/cpio/version.c +++ b/cpio/version.c @@ -5,12 +5,12 @@ #else #define USED #endif -static const char sccsid[] USED = "@(#)cpio.sl 2.5 (gritter) 4/14/07"; +static const char sccsid[] USED = "@(#)cpio.sl 2.6 (gritter) 2/14/09"; /* SLIST */ /* blast.c: * Sccsid @(#)blast.c 1.2 (gritter) 2/17/04 blast.h: * Sccsid @(#)blast.h 1.2 (gritter) 2/17/04 -cpio.c: * Sccsid @(#)cpio.c 1.303 (gritter) 4/14/07 +cpio.c: * Sccsid @(#)cpio.c 1.304 (gritter) 2/14/09 cpio.h: Sccsid @(#)cpio.h 1.29 (gritter) 3/26/07 crc32.c: * Sccsid @(#)crc32.c 1.2 (gritter) 5/29/03 expand.c: Sccsid @(#)expand.c 1.6 (gritter) 12/15/03 From fdef441abd222477e1f9f086bdf4d8cf908b9866 Mon Sep 17 00:00:00 2001 From: gritter <> Date: Thu, 4 Jun 2009 22:46:53 +0000 Subject: [PATCH 14/24] * pg: Handle cases where standard output is a terminal but not open for reading (bug reported by Keith Doyle). --- CHANGES | 2 ++ pg/pg.c | 83 ++++++++++++++++++++++++++++++++++++--------------------- 2 files changed, 55 insertions(+), 30 deletions(-) diff --git a/CHANGES b/CHANGES index e406e9d..5e22886 100644 --- a/CHANGES +++ b/CHANGES @@ -2,6 +2,8 @@ Release ... * cpio: Skip over zip extra headers with fewer than four bytes (the minimum length for them to contain any information) instead of reporting a bad header and terminating. +* pg: Handle cases where standard output is a terminal but not open for + reading (bug reported by Keith Doyle). * Made the getopt() substitute work with the getopt$UNIX2003() function redirection mechanism on Mac OS X Leopard. * mknod, pgrep, ps: Mac OS X Leopard compilation fixes. diff --git a/pg/pg.c b/pg/pg.c index 22c7fb2..0d1077d 100644 --- a/pg/pg.c +++ b/pg/pg.c @@ -30,11 +30,11 @@ #define USED #endif #if defined (SU3) -static const char sccsid[] USED = "@(#)pg_su3.sl 2.66 (gritter) 8/14/05"; +static const char sccsid[] USED = "@(#)pg_su3.sl 2.67 (gritter) 6/5/09"; #elif defined (SUS) -static const char sccsid[] USED = "@(#)pg_sus.sl 2.66 (gritter) 8/14/05"; +static const char sccsid[] USED = "@(#)pg_sus.sl 2.67 (gritter) 6/5/09"; #else -static const char sccsid[] USED = "@(#)pg.sl 2.66 (gritter) 8/14/05"; +static const char sccsid[] USED = "@(#)pg.sl 2.67 (gritter) 6/5/09"; #endif #ifndef USE_TERMCAP @@ -227,6 +227,7 @@ static void (*oldterm)(int); /* old SIGTERM handler */ static char *tty; /* result of ttyname(1) */ static char *progname; /* program name */ static unsigned ontty; /* whether running on tty device */ +static int ttyfd; /* file descriptor of tty device */ static unsigned exitstatus; /* exit status */ static int pagelen = 23; /* lines on a single screen page */ static int ttycols = 79; /* screen columns (starting at 0) */ @@ -364,7 +365,7 @@ static int outcap(int i) { char c = i; - return write(1, &c, 1); + return write(ttyfd, &c, 1); } /* @@ -376,12 +377,12 @@ mesg(const char *message) if (ontty == 0) return; if (must_sgr0) { - write(1, sgr0, strlen(sgr0)); + write(ttyfd, sgr0, strlen(sgr0)); must_sgr0 = 0; } if (*message != '\n' && sflag) vidputs(A_STANDOUT, outcap); - write(1, message, strlen(message)); + write(ttyfd, message, strlen(message)); if (*message != '\n' && sflag) vidputs(A_NORMAL, outcap); } @@ -418,7 +419,7 @@ getwinsize(void) initialized = 1; } #ifdef TIOCGWINSZ - badioctl = ioctl(1, TIOCGWINSZ, &winsz); + badioctl = ioctl(ttyfd, TIOCGWINSZ, &winsz); #endif if (envcols) ttycols = envcols - 1; @@ -599,7 +600,7 @@ sighandler(int signum) if (genjump) longjmp(genenv, signum); } - tcsetattr(1, TCSADRAIN, &otio); + tcsetattr(ttyfd, TCSADRAIN, &otio); quit(exitstatus); } @@ -720,7 +721,7 @@ cline(void) memset(buf, ' ', ttycols + 2); buf[0] = '\r'; buf[ttycols + 1] = '\r'; - write(1, buf, ttycols + 2); + write(ttyfd, buf, ttycols + 2); } /* @@ -842,18 +843,22 @@ prompt(long long pageno) printprompt(pageno); cmd.key = cmd.addon = cmd.cmdline[0] = '\0'; cmd.cmdlen = 0; - tcgetattr(1, &tio); + tcgetattr(ttyfd, &tio); tio.c_lflag &= ~(tcflag_t)(ICANON | ECHO); tio.c_iflag |= ICRNL; tio.c_cc[VMIN] = 1; tio.c_cc[VTIME] = 0; - tcsetattr(1, TCSADRAIN, &tio); - tcflush(1, TCIFLUSH); + tcsetattr(ttyfd, TCSADRAIN, &tio); + tcflush(ttyfd, TCIFLUSH); for (;;) { - switch (read(1, &key, 1)) { - case 0: quit(0); - /*NOTREACHED*/ - case -1: quit(020); + if ((n = read(ttyfd, &key, 1)) != 1) { + tcsetattr(ttyfd, TCSADRAIN, &otio); + cline(); + switch (n) { + case 0: quit(0); + /*NOTREACHED*/ + case -1: quit(020); + } } if (key == tio.c_cc[VERASE]) { if (cmd.cmdlen) { @@ -864,7 +869,7 @@ prompt(long long pageno) if ((n = width(wc)) < 0) n = 1; while (n--) - write(1, "\b \b", 3); + write(ttyfd, "\b \b", 3); if (!escape && cmd.cmdlen && *(p = previous(&cmd.cmdline[cmd.cmdlen], cmd.cmdline, &wc)) == '\\') { @@ -911,7 +916,7 @@ prompt(long long pageno) key == '\n' || key == '\r') break; else if (escape) - write(1, "\b", 1); + write(ttyfd, "\b", 1); if (cmd.cmdlen >= sizeof cmd.cmdline - 1) { ring(); continue; @@ -973,7 +978,7 @@ prompt(long long pageno) cmd.key = key; } } - write(1, &key, 1); + write(ttyfd, &key, 1); cmd.cmdline[cmd.cmdlen++] = key; cmd.cmdline[cmd.cmdlen] = '\0'; if (nflag && state == CMD_FIN) @@ -981,7 +986,7 @@ prompt(long long pageno) escape = (escape ? 0 : key == '\\'); } endprompt: - tcsetattr(1, TCSADRAIN, &otio); + tcsetattr(ttyfd, TCSADRAIN, &otio); cline(); cmd.count = getcount(cmd.cmdline); } @@ -1047,7 +1052,7 @@ print1(const char *s, const char *end) for (i = 0; i < m; i++) { *bp++ = s[i]; if (bp-buf >= sizeof buf - mb_cur_max) { - write(1, buf, bp - buf); + write(ttyfd, buf, bp - buf); bp = buf; } } @@ -1077,12 +1082,12 @@ print1(const char *s, const char *end) } s += n; if (bp - buf >= sizeof buf - mb_cur_max) { - write(1, buf, bp - buf); + write(ttyfd, buf, bp - buf); bp = buf; } } if (bp > buf) - write(1, buf, bp - buf); + write(ttyfd, buf, bp - buf); } /* @@ -1734,7 +1739,7 @@ printline(void) */ if (b[sz-1] != '\n' && (sz == llen || b[sz-1] == '\t' || b[sz] == '\t')) - write(1, "\n", 1); + write(ttyfd, "\n", 1); specjump = 0; } } @@ -1957,8 +1962,8 @@ shell(FILE *f) ": !command not allowed in rflag mode.\n")); return; } - write(1, cmd.cmdline, strlen(cmd.cmdline)); - write(1, "\n", 1); + write(ttyfd, cmd.cmdline, strlen(cmd.cmdline)); + write(ttyfd, "\n", 1); sigset(SIGINT, SIG_IGN); sigset(SIGQUIT, SIG_IGN); switch (cpid = fork()) { @@ -2000,7 +2005,7 @@ shell(FILE *f) static void help(void) { - write(1, helpscreen, strlen(helpscreen)); + write(ttyfd, helpscreen, strlen(helpscreen)); } /* @@ -2244,6 +2249,18 @@ run(char **av, int ac) } } +static int +trytty(int fd) +{ + int i; + char c; + + if (tcgetattr(fd, &otio) == 0 && (i = fcntl(fd, F_GETFL)) >= 0 && + (i & O_ACCMODE) == O_RDWR && read(fd, &c, 0) == 0) + return fd; + return -1; +} + int main(int argc, char **argv) { @@ -2261,7 +2278,13 @@ main(int argc, char **argv) progname = basename(argv[0]); /*setlocale(LC_MESSAGES, "");*/ catd = catopen(CATNAME, NL_CAT_LOCALE); - if (tcgetattr(1, &otio) == 0) { + if ((ttyfd = trytty(1)) < 0 && (ttyfd = trytty(2)) < 0) { + if ((i = open("/dev/tty", O_RDWR)) >= 0) { + if ((ttyfd = trytty(i)) < 0) + close(i); + } + } + if (ttyfd >= 0) { ontty = 1; if ((oldint = sigset(SIGINT, SIG_IGN)) != SIG_IGN) sigset(SIGINT, sighandler); @@ -2271,9 +2294,9 @@ main(int argc, char **argv) sigset(SIGTERM, sighandler); setlocale(LC_COLLATE, ""); setlocale(LC_CTYPE, ""); - tty = ttyname(1); + tty = ttyname(ttyfd); #ifndef USE_TERMCAP - setupterm(NULL, 1, &tinfostat); + setupterm(NULL, ttyfd, &tinfostat); #else /* USE_TERMCAP */ if ((cp = getenv("TERM")) != NULL) { char buf[2048]; From 83f7babe16e64edbbda792f113bb8dd0fa95fbc6 Mon Sep 17 00:00:00 2001 From: gritter <> Date: Thu, 4 Jun 2009 22:51:30 +0000 Subject: [PATCH 15/24] SUSv2 requires us to not paginate if stdout is not a tty --- pg/pg.c | 33 +++++++++------------------------ 1 file changed, 9 insertions(+), 24 deletions(-) diff --git a/pg/pg.c b/pg/pg.c index 0d1077d..4b22d8b 100644 --- a/pg/pg.c +++ b/pg/pg.c @@ -30,11 +30,11 @@ #define USED #endif #if defined (SU3) -static const char sccsid[] USED = "@(#)pg_su3.sl 2.67 (gritter) 6/5/09"; +static const char sccsid[] USED = "@(#)pg_su3.sl 2.68 (gritter) 6/5/09"; #elif defined (SUS) -static const char sccsid[] USED = "@(#)pg_sus.sl 2.67 (gritter) 6/5/09"; +static const char sccsid[] USED = "@(#)pg_sus.sl 2.68 (gritter) 6/5/09"; #else -static const char sccsid[] USED = "@(#)pg.sl 2.67 (gritter) 6/5/09"; +static const char sccsid[] USED = "@(#)pg.sl 2.68 (gritter) 6/5/09"; #endif #ifndef USE_TERMCAP @@ -227,7 +227,7 @@ static void (*oldterm)(int); /* old SIGTERM handler */ static char *tty; /* result of ttyname(1) */ static char *progname; /* program name */ static unsigned ontty; /* whether running on tty device */ -static int ttyfd; /* file descriptor of tty device */ +static int ttyfd = 1; /* file descriptor of tty device */ static unsigned exitstatus; /* exit status */ static int pagelen = 23; /* lines on a single screen page */ static int ttycols = 79; /* screen columns (starting at 0) */ @@ -2249,23 +2249,11 @@ run(char **av, int ac) } } -static int -trytty(int fd) -{ - int i; - char c; - - if (tcgetattr(fd, &otio) == 0 && (i = fcntl(fd, F_GETFL)) >= 0 && - (i & O_ACCMODE) == O_RDWR && read(fd, &c, 0) == 0) - return fd; - return -1; -} - int main(int argc, char **argv) { int arg, i; - char *cp; + char c, *cp; if (sizeof LINE == 4) { LINE = 020000000000UL; @@ -2278,13 +2266,10 @@ main(int argc, char **argv) progname = basename(argv[0]); /*setlocale(LC_MESSAGES, "");*/ catd = catopen(CATNAME, NL_CAT_LOCALE); - if ((ttyfd = trytty(1)) < 0 && (ttyfd = trytty(2)) < 0) { - if ((i = open("/dev/tty", O_RDWR)) >= 0) { - if ((ttyfd = trytty(i)) < 0) - close(i); - } - } - if (ttyfd >= 0) { + if (tcgetattr(ttyfd, &otio) == 0 && + (i = fcntl(ttyfd, F_GETFL)) >= 0 && + (i & O_ACCMODE) == O_RDWR && + read(ttyfd, &c, 0) == 0) { ontty = 1; if ((oldint = sigset(SIGINT, SIG_IGN)) != SIG_IGN) sigset(SIGINT, sighandler); From d0844c3e34afeb37e793351428327af0493029b7 Mon Sep 17 00:00:00 2001 From: gritter <> Date: Fri, 5 Jun 2009 20:08:42 +0000 Subject: [PATCH 16/24] if isatty(1) but stdout is not readable, try 2 and then /dev/tty --- pg/pg.c | 33 +++++++++++++++++++++++++++------ 1 file changed, 27 insertions(+), 6 deletions(-) diff --git a/pg/pg.c b/pg/pg.c index 4b22d8b..8e0fde7 100644 --- a/pg/pg.c +++ b/pg/pg.c @@ -227,7 +227,7 @@ static void (*oldterm)(int); /* old SIGTERM handler */ static char *tty; /* result of ttyname(1) */ static char *progname; /* program name */ static unsigned ontty; /* whether running on tty device */ -static int ttyfd = 1; /* file descriptor of tty device */ +static int ttyfd; /* file descriptor of tty device */ static unsigned exitstatus; /* exit status */ static int pagelen = 23; /* lines on a single screen page */ static int ttycols = 79; /* screen columns (starting at 0) */ @@ -2249,11 +2249,23 @@ run(char **av, int ac) } } +static int +trytty(int fd) +{ + int i; + char c; + + if (tcgetattr(fd, &otio) == 0 && (i = fcntl(fd, F_GETFL)) >= 0 && + (i & O_ACCMODE) == O_RDWR && read(fd, &c, 0) == 0) + return fd; + return -1; +} + int main(int argc, char **argv) { int arg, i; - char c, *cp; + char *cp; if (sizeof LINE == 4) { LINE = 020000000000UL; @@ -2266,10 +2278,19 @@ main(int argc, char **argv) progname = basename(argv[0]); /*setlocale(LC_MESSAGES, "");*/ catd = catopen(CATNAME, NL_CAT_LOCALE); - if (tcgetattr(ttyfd, &otio) == 0 && - (i = fcntl(ttyfd, F_GETFL)) >= 0 && - (i & O_ACCMODE) == O_RDWR && - read(ttyfd, &c, 0) == 0) { + /* + * This is to handle cases where stdout is a terminal but is not + * readable, as when doing "pg file >/dev/tty". + */ + if (!isatty(1)) + ttyfd = -1; + else if ((ttyfd = trytty(1)) < 0 && (ttyfd = trytty(2)) < 0) { + if ((i = open("/dev/tty", O_RDWR)) >= 0) { + if ((ttyfd = trytty(i)) < 0) + close(i); + } + } + if (ttyfd >= 0) { ontty = 1; if ((oldint = sigset(SIGINT, SIG_IGN)) != SIG_IGN) sigset(SIGINT, sighandler); From 2ac39199470265e6be8e2f1cef7507ccbe90a024 Mon Sep 17 00:00:00 2001 From: gritter <> Date: Wed, 12 Aug 2009 22:21:27 +0000 Subject: [PATCH 17/24] * pax: Handle multiple "-s" options correctly, i.e. execute multiple substitutions in the order specified. Previously, everything except the first occurrence was ignored. --- CHANGES | 3 +++ cpio/pax.1 | 6 ++++-- cpio/pax.c | 21 +++++++++++++-------- cpio/version.c | 8 ++++---- 4 files changed, 24 insertions(+), 14 deletions(-) diff --git a/CHANGES b/CHANGES index 5e22886..3c9853c 100644 --- a/CHANGES +++ b/CHANGES @@ -1,4 +1,7 @@ Release ... +* pax: Handle multiple "-s" options correctly, i.e. execute multiple + substitutions in the order specified. Previously, everything except + the first occurrence was ignored. * cpio: Skip over zip extra headers with fewer than four bytes (the minimum length for them to contain any information) instead of reporting a bad header and terminating. diff --git a/cpio/pax.1 b/cpio/pax.1 index e46fc02..4fb9206 100644 --- a/cpio/pax.1 +++ b/cpio/pax.1 @@ -18,8 +18,8 @@ .\" misrepresented as being the original software. .\" .\" 3. This notice may not be removed or altered from any source distribution. -.\" Sccsid @(#)pax.1 1.37 (gritter) 9/5/05 -.TH PAX 1 "9/5/05" "Heirloom Toolchest" "User Commands" +.\" Sccsid @(#)pax.1 1.38 (gritter) 8/13/09 +.TH PAX 1 "8/13/09" "Heirloom Toolchest" "User Commands" .SH NAME pax \- portable archive interchange .SH SYNOPSIS @@ -325,6 +325,8 @@ Any character can be used as delimiter instead of .RI ` / '. If a file name is empty after the replacement is done, the file is ignored. +This option can be specified multiple times +to execute multiple substitutions in the order specified. .TP .B \-t Resets the access times of files diff --git a/cpio/pax.c b/cpio/pax.c index 50632b6..39398e0 100644 --- a/cpio/pax.c +++ b/cpio/pax.c @@ -33,11 +33,11 @@ #define USED #endif #if defined (SU3) -static const char sccsid[] USED = "@(#)pax_su3.sl 1.26 (gritter) 6/26/05"; +static const char sccsid[] USED = "@(#)pax_su3.sl 1.27 (gritter) 8/13/09"; #else -static const char sccsid[] USED = "@(#)pax.sl 1.26 (gritter) 6/26/05"; +static const char sccsid[] USED = "@(#)pax.sl 1.27 (gritter) 8/13/09"; #endif -/* Sccsid @(#)pax.c 1.26 (gritter) 6/26/05 */ +/* Sccsid @(#)pax.c 1.27 (gritter) 8/13/09 */ #include #include @@ -682,13 +682,19 @@ int pax_sname(char **oldp, size_t *olds) { char *new = NULL; - size_t newsize = 0; + size_t newsize; regmatch_t bralist[NBRA+1]; int c, i, k, l, y, z; - int innew = 0, ef = 0; - char *inp = *oldp; + int innew, ef; + char *inp; + if (ren == 0) + return 1; for (z = 0; z < ren; z++) { + new = NULL; + newsize = 0; + inp = *oldp; + innew = ef = 0; in: if (regexec(&rep[z].r_re, inp, NBRA+1, bralist, ef) != 0) { if (ef == 0) continue; @@ -734,9 +740,8 @@ pax_sname(char **oldp, size_t *olds) free(*oldp); *oldp = new; *olds = newsize; - return *new != '\0'; } - return 1; + return *new != '\0'; } void diff --git a/cpio/version.c b/cpio/version.c index dbdf037..cf17ef3 100644 --- a/cpio/version.c +++ b/cpio/version.c @@ -5,7 +5,7 @@ #else #define USED #endif -static const char sccsid[] USED = "@(#)cpio.sl 2.6 (gritter) 2/14/09"; +static const char sccsid[] USED = "@(#)cpio.sl 2.7 (gritter) 8/13/09"; /* SLIST */ /* blast.c: * Sccsid @(#)blast.c 1.2 (gritter) 2/17/04 @@ -18,9 +18,9 @@ explode.c: * Sccsid @(#)explode.c 1.6 (gritter) 9/30/03 flags.c: Sccsid @(#)flags.c 1.6 (gritter) 3/26/07 inflate.c: * Sccsid @(#)inflate.c 1.6 (gritter) 10/13/04 nonpax.c: Sccsid @(#)nonpax.c 1.1 (gritter) 2/24/04 -pax.c:static const char sccsid[] USED = "@(#)pax_su3.sl 1.26 (gritter) 6/26/05"; -pax.c:static const char sccsid[] USED = "@(#)pax.sl 1.26 (gritter) 6/26/05"; -pax.c: Sccsid @(#)pax.c 1.26 (gritter) 6/26/05 +pax.c:static const char sccsid[] USED = "@(#)pax_su3.sl 1.27 (gritter) 8/13/09"; +pax.c:static const char sccsid[] USED = "@(#)pax.sl 1.27 (gritter) 8/13/09"; +pax.c: Sccsid @(#)pax.c 1.27 (gritter) 8/13/09 unshrink.c: * Sccsid @(#)unshrink.c 1.4 (gritter) 6/18/04 unzip.h: * Sccsid @(#)unzip.h 1.5 (gritter) 7/16/04 */ From 32db63dfa0951e040fda5bb07b133e8a2e4d8c7c Mon Sep 17 00:00:00 2001 From: gritter <> Date: Fri, 14 Aug 2009 09:04:25 +0000 Subject: [PATCH 18/24] the spec actually wants at most one successful substitution for pax -s -s --- CHANGES | 3 --- cpio/pax.c | 21 ++++++++------------- cpio/version.c | 10 +++++----- 3 files changed, 13 insertions(+), 21 deletions(-) diff --git a/CHANGES b/CHANGES index 3c9853c..5e22886 100644 --- a/CHANGES +++ b/CHANGES @@ -1,7 +1,4 @@ Release ... -* pax: Handle multiple "-s" options correctly, i.e. execute multiple - substitutions in the order specified. Previously, everything except - the first occurrence was ignored. * cpio: Skip over zip extra headers with fewer than four bytes (the minimum length for them to contain any information) instead of reporting a bad header and terminating. diff --git a/cpio/pax.c b/cpio/pax.c index 39398e0..50632b6 100644 --- a/cpio/pax.c +++ b/cpio/pax.c @@ -33,11 +33,11 @@ #define USED #endif #if defined (SU3) -static const char sccsid[] USED = "@(#)pax_su3.sl 1.27 (gritter) 8/13/09"; +static const char sccsid[] USED = "@(#)pax_su3.sl 1.26 (gritter) 6/26/05"; #else -static const char sccsid[] USED = "@(#)pax.sl 1.27 (gritter) 8/13/09"; +static const char sccsid[] USED = "@(#)pax.sl 1.26 (gritter) 6/26/05"; #endif -/* Sccsid @(#)pax.c 1.27 (gritter) 8/13/09 */ +/* Sccsid @(#)pax.c 1.26 (gritter) 6/26/05 */ #include #include @@ -682,19 +682,13 @@ int pax_sname(char **oldp, size_t *olds) { char *new = NULL; - size_t newsize; + size_t newsize = 0; regmatch_t bralist[NBRA+1]; int c, i, k, l, y, z; - int innew, ef; - char *inp; + int innew = 0, ef = 0; + char *inp = *oldp; - if (ren == 0) - return 1; for (z = 0; z < ren; z++) { - new = NULL; - newsize = 0; - inp = *oldp; - innew = ef = 0; in: if (regexec(&rep[z].r_re, inp, NBRA+1, bralist, ef) != 0) { if (ef == 0) continue; @@ -740,8 +734,9 @@ pax_sname(char **oldp, size_t *olds) free(*oldp); *oldp = new; *olds = newsize; + return *new != '\0'; } - return *new != '\0'; + return 1; } void diff --git a/cpio/version.c b/cpio/version.c index cf17ef3..a9d4a46 100644 --- a/cpio/version.c +++ b/cpio/version.c @@ -5,12 +5,12 @@ #else #define USED #endif -static const char sccsid[] USED = "@(#)cpio.sl 2.7 (gritter) 8/13/09"; +static const char sccsid[] USED = "@(#)cpio.sl 2.9 (gritter) 8/14/09"; /* SLIST */ /* blast.c: * Sccsid @(#)blast.c 1.2 (gritter) 2/17/04 blast.h: * Sccsid @(#)blast.h 1.2 (gritter) 2/17/04 -cpio.c: * Sccsid @(#)cpio.c 1.304 (gritter) 2/14/09 +cpio.c: * Sccsid @(#)cpio.c 1.305 (gritter) 8/14/09 cpio.h: Sccsid @(#)cpio.h 1.29 (gritter) 3/26/07 crc32.c: * Sccsid @(#)crc32.c 1.2 (gritter) 5/29/03 expand.c: Sccsid @(#)expand.c 1.6 (gritter) 12/15/03 @@ -18,9 +18,9 @@ explode.c: * Sccsid @(#)explode.c 1.6 (gritter) 9/30/03 flags.c: Sccsid @(#)flags.c 1.6 (gritter) 3/26/07 inflate.c: * Sccsid @(#)inflate.c 1.6 (gritter) 10/13/04 nonpax.c: Sccsid @(#)nonpax.c 1.1 (gritter) 2/24/04 -pax.c:static const char sccsid[] USED = "@(#)pax_su3.sl 1.27 (gritter) 8/13/09"; -pax.c:static const char sccsid[] USED = "@(#)pax.sl 1.27 (gritter) 8/13/09"; -pax.c: Sccsid @(#)pax.c 1.27 (gritter) 8/13/09 +pax.c:static const char sccsid[] USED = "@(#)pax_su3.sl 1.26 (gritter) 6/26/05"; +pax.c:static const char sccsid[] USED = "@(#)pax.sl 1.26 (gritter) 6/26/05"; +pax.c: Sccsid @(#)pax.c 1.26 (gritter) 6/26/05 unshrink.c: * Sccsid @(#)unshrink.c 1.4 (gritter) 6/18/04 unzip.h: * Sccsid @(#)unzip.h 1.5 (gritter) 7/16/04 */ From 6e0112487ec25e9f6d4672ab5e2cafe8493b2d56 Mon Sep 17 00:00:00 2001 From: gritter <> Date: Fri, 14 Aug 2009 22:49:23 +0000 Subject: [PATCH 19/24] new game, not yet working with Heirloom sed --- sed/test/makefile | 4 +- sed/test/sedtris.sed | 374 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 376 insertions(+), 2 deletions(-) create mode 100644 sed/test/sedtris.sed diff --git a/sed/test/makefile b/sed/test/makefile index 7a89a97..b651086 100644 --- a/sed/test/makefile +++ b/sed/test/makefile @@ -6,7 +6,7 @@ INSTALL=/usr/ucb/install cat $< > $@ chmod 755 $@ -all: math hanoi sokoban +all: math hanoi sokoban sedtris install: all $(INSTALL) -c math $(DST)/math @@ -14,4 +14,4 @@ install: all $(INSTALL) -c sokoban $(DST)/sokoban clean: - rm -f math hanoi sokoban core log *~ + rm -f math hanoi sokoban sedtris core log *~ diff --git a/sed/test/sedtris.sed b/sed/test/sedtris.sed new file mode 100644 index 0000000..d33f38f --- /dev/null +++ b/sed/test/sedtris.sed @@ -0,0 +1,374 @@ +#!/usr/5bin/sed -nf +# sedtris.sed - sed tetris +# 26th of May, 2008 +# Julia Jomantaite +# +# Changes by Gunnar Ritter to make it work with Heirloom sed; +# not yet completed +# +# Sccsid @(#)sedtris.sed 1.2 (gritter) 8/15/09 +# +# from http://uuner.doslash.org/forfun +# +# This is free software. You may distribute it under the terms of the +# Poetic License. http://genaud.net/2005/10/poetic-license/ +# +# (c) 2008 Julia Jomantaite +# +# This work `as-is' we provide. +# No warranty, express or implied. +# We've done our best, +# to debug and test. +# Liability for damages denied. +# +# Permission is granted hereby, +# to copy, share, and modify. +# Use as is fit, +# free or for profit. +# On this notice these rights rely. +# +1{ +s/.*/ 2a2a2a2a|3a3a3a3a3a3a3a3a3a3a|2a2a2a2a~/ +s/[^~]*~$/&&&/ +s/.*/& 2a2a2a2a|0a0a0a0a0a0a0a0a0a0a|2a2a2a2a~/ +s/[^~]*~$/&&&&&&&&&&&&&&&&&&&&/ +s// 2a2a2a2a|4a4a4a4a4a4a4a4a4a4a|2a2a2a2a~/ +s/[^~]*~$/&&&/ +s/.*/~&/ +s/$/#....,,,~/ +s/$/#AAAA AAAA APPA APPA~/ +s/$/#AAAA ANAA LPOA AHAA~/ +s/$/#AAAA BKIA FPFA CKEA~/ +s/$/#AAAA EDCA GPJA IMBA~/ +s/$/#ACIA EGME BDJB ACIA~/ +s/$/#AAAA IKEA FPFA BKCA~/ +s/$/#AAAA CGBA MPDA EJIA~/ +s/$/#NEXTAAAA ANAA LPOA AHAA 5~/ +s/$/#SCORE0~/ +h +b display +} + +/1/{s/1//;x;s/#\.\.*/&./;s/#\.\{8\}/#./;x +} + +/^w/b rotate +/^a/b left +/^d/b right +/^s/b nothing +/^\[A/b rotate +/^\[D/b left +/^\[C/b right +/^\[B/b nothing +/^$/b nothing +/^[z ]/{ +g +s/#\.*/&.../ +s/#\.\{8\}/#./ +s/$/#FALL~/ +h +b nothing +} +b display + +:rotate +g +s/#\.*/&./ +s/#\.\{8\}/#./ +/[14-9x][e-h]/ !{/2[e-h]/!y/abcdefghijklmnop/acegikmobdfhjlnp/ +} +h +b display + +:left +g +s/#\.*/&../ +s/#\.\{8\}/#./ +/|[0-9x][i-p]/ !{/[14-9x][a-p][0-9x][i-p]/ !{ +s/\([0-9x]\)a\(|\{0,1\}\)\([0-9x]\)\([b-p]\)/\1\4\2\3a/g +s/\([b-p]\)\(|\{0,1\}\)\([0-9x]\)a\(|\{0,1\}\)\([0-9x]\)\([b-p]\)/\1\2\3\6\4\5a/g +s/\([b-p]\)\(|\{0,1\}\)\([0-9x]\)a\(|\{0,1\}\)\([0-9x]\)\([b-p]\)/\1\2\3\6\4\5a/g +s/\([b-p]\)\(|\{0,1\}\)\([0-9x]\)a\(|\{0,1\}\)\([0-9x]\)\([b-p]\)/\1\2\3\6\4\5a/g +} +} +h +b display + +:right +g +s/#\.*/&./ +s/#\.\{8\}/#./ +/[i-p]|/ !{/[i-p][14-9x]/!{ +s/\([0-9x]\)\([b-p]\)\(|\{0,1\}\)\([0-9x]\)a/\1a\3\4\2/g +s/\([0-9x]\)\([b-p]\)\(|\{0,1\}\)\([0-9x]\)a\(|\{0,1\}\)\([0-9x]\)\([b-p]\)/\1a\3\4\2\5\6\7/g +s/\([0-9x]\)\([b-p]\)\(|\{0,1\}\)\([0-9x]\)a\(|\{0,1\}\)\([0-9x]\)\([b-p]\)/\1a\3\4\2\5\6\7/g +s/\([0-9x]\)\([b-p]\)\(|\{0,1\}\)\([0-9x]\)a\(|\{0,1\}\)\([0-9x]\)\([b-p]\)/\1a\3\4\2\5\6\7/g +} +} +h +b display + +:nothing +g + +#New brick +/~ \(2a\)*|\([15-9x]a\)*|\(2a\)*~/ !{ +/[b-p]/ !{ +#Set % before all 4-letter "words" +t e +:e +s/\(#NEXT\(\( \)\{0,1\}%[A-P]\)*\)\( \)\{0,1\}\([A-P]\)/\1\4%\5/ +t e + +#Set @ before probable new letters +s/^\(~[^~]*~[^~]*~.\{17\}\)\(..\)\(..\)\(..\)\(..\)/\1@\2@\3@\4@\5/ +s/^\(~[^~]*~[^~]*~[^~]*~.\{17\}\)\(..\)\(..\)\(..\)\(..\)/\1@\2@\3@\4@\5/ +t blank2 +:blank2 +/#NEXT\([^%]*%\)\{13\}[A-H]%[A-H]%[A-H]%[A-H]/{ +s/^\(~[^~]*~[^~]*~[^~]*~[^~]*~.\{17\}\)\(..\)\(..\)\(..\)\(..\)/\1@\2@\3@\4@\5/ +/#NEXT\([^%]*%\)\{9\}[A-H]%[A-H]%[A-H]%[A-H]/{ +s/^\(~[^~]*~[^~]*~[^~]*~[^~]*~[^~]*~.\{17\}\)\(..\)\(..\)\(..\)\(..\)/\1@\2@\3@\4@\5/ +b v2 +} +b v1 +} +s/^\(~.\{17\}\)\(..\)\(..\)\(..\)\(..\)/\1@\2@\3@\4@\5/ +:v1 +s/^\(~[^~]*~.\{17\}\)\(..\)\(..\)\(..\)\(..\)/\1@\2@\3@\4@\5/ +:v2 + +#Add real new letters (capital) +t f +:f +/^\([^@]*\)[15-9x]@.\([^%]*\)%[I-P]/s/$/#OVER~/ +s/^\([^@]*\)@.\([^%]*\)%\([A-P]\)/\1\3\2\3/ +t f + +#Decapitalization +h +s/^\(~[^~]*\)\{6\}~// +x +s/^\(\(~[^~]*\)\{6\}\)\(.*\)$/\1/ +y/ABCDEFGHIJKLMNOP/abcdefghijklmnop/ +x +H +#Add "Current" +g +s/\n/~/ +s/#CURRENT.~//g +s/\(#NEXT[^~]*\)\([0-9x]\)\(.*\)$/\1\2\3#CURRENT\2~/ + +#Add NEXT +:g +/\./{ +s/#/$/ +s/\./@/ +b g +} +s/@/./g +s/^\([^#]*\)#\([^~]*\)\(.*\)\(#NEXT[^~]*\)/\1#\2\3#NEXT\2/ + +s/\([^.]\)\(\.\)\([^.]*\)\(#NEXT[^~]*\)/\1\2\3\4 1/ +s/\([^.]\)\(\.\{2\}\)\([^.]*\)\(#NEXT[^~]*\)/\1\2\3\4 5/ +s/\([^.]\)\(\.\{3\}\)\([^.]*\)\(#NEXT[^~]*\)/\1\2\3\4 6/ +s/\([^.]\)\(\.\{4\}\)\([^.]*\)\(#NEXT[^~]*\)/\1\2\3\4 7/ +s/\([^.]\)\(\.\{5\}\)\([^.]*\)\(#NEXT[^~]*\)/\1\2\3\4 8/ +s/\([^.]\)\(\.\{6\}\)\([^.]*\)\(#NEXT[^~]*\)/\1\2\3\4 9/ +s/\([^.]\)\(\.\{7\}\)\([^.]*\)\(#NEXT[^~]*\)/\1\2\3\4 x/ +s/\$/#/g + +h +s/\(,*\)\([^,]*#NEXT[^~]*\)/\1\2\1/ +s/.*#NEXT\([^~]*\)~.*/\1/ + +:g2 +/,/{ +s/\,/@/ +y/ABCDEFGHIJKLMNOP/ACEGIKMOBDFHJLNP/ +b g2 +} +s/@//g +H +g +s/\n/~/ +s/\(#NEXT\)[^~]*\(~.*\)~\([^~]*\)$/\1\3\2/ +h +b display +} +} + +#Eat that line +t d +:d +/~ \(2a\)*|\([15-9x]a\)*|\(2a\)*~/ { +s/~ \(2a\)*|\([15-9x]a\)*|\(2a\)*// +s/^~\([^~]*~\)\{3\}/& 2a2a2a2a|0a0a0a0a0a0a0a0a0a0a|2a2a2a2a~/ +s/#SCORE[^~]*/&A/ +b d +} +#Scoring +/#SCORE[^~]*A/{ +s/\(#SCORE[^~]*\)AAAA/\1+1200z/ +s/\(#SCORE[^~]*\)AAA/\1+300z/ +s/\(#SCORE[^~]*\)AA/\1+100z/ +s/\(#SCORE[^~]*\)A/\1+40z/ + +/#SCORE[0-9]*+[0-9]*z/{ +s/+/@+/ +:finnul +/0z/{ +/#SCORE@/b endsum +s/\(.\)@/@\1/ +s/0z/z/ +/+z/b endsum +b finnul +} +t incr +:incr +s/9\(%*\)@/%\1@/ +t incr +s/#SCORE\(%*\)@/#SCORE0\1@/ +s/8\(%*\)@/9\1@/ +s/7\(%*\)@/8\1@/ +s/6\(%*\)@/7\1@/ +s/5\(%*\)@/6\1@/ +s/4\(%*\)@/5\1@/ +s/3\(%*\)@/4\1@/ +s/2\(%*\)@/3\1@/ +s/1\(%*\)@/2\1@/ +s/0\(%*\)@/1\1@/ +s/%/0/g +t blank +:blank +s/9z/8z/ +t incr +s/8z/7z/ +t incr +s/7z/6z/ +t incr +s/6z/5z/ +t incr +s/5z/4z/ +t incr +s/4z/3z/ +t incr +s/3z/2z/ +t incr +s/2z/1z/ +t incr +s/1z/0z/ +t finnul +:endsum +s/@// +s/#SCORE\([0-9]*\)+\([0-9]*\)z/#SCORE\2\1/ +} +h +b display +} + +#Falling down +:fall +/~[^~]*[03][i-p].\{38\}[14-9x]/ !{ +:c +#Find the lowest line with the... +s/\(~[^~]*[b-p][^~]*\)~\([^b-p~]*~\)/\1z\2/ +s/~\([^~b-p]*\)\([b-p]\)\([^~]\{39\}\)[a-p]/~\1a\3\2/ +s/~\([^~b-p]*\)\([b-p]\)\([^~]\{39\}\)[a-p]/~\1a\3\2/ +s/~\([^~b-p]*\)\([b-p]\)\([^~]\{39\}\)[a-p]/~\1a\3\2/ +s/~\([^~b-p]*\)\([b-p]\)\([^~]\{39\}\)[a-p]/~\1a\3\2/ +s/z/~/ +/[^~]*[b-p][^~]*~[^~b-p]*~[^~]*[b-p][^~]*/b c +/#FALL~$/b fall +h +b display +} +s/#FALL~//g + +#Freezing +s/0[b-h]/0a/g +t i +:i +s/\(0[i-p]\)\(.*#CURRENT\)\(.\)/\3a\2\3/ +t i + +s/\([15-9x]\)[b-p]/\1a/g +s/2[b-p]/2a/g +s/3[b-h]/3a/g +s/4[b-p]/4a/g + +#if it's over +/3[i-p]/ s/$/#OVER~/ +/[15-9x][i-p]/{ +s/\([15-9x]\)\([i-p]\)/\1a/g +s/$/#OVER~/ +} +h + +#Display +:display +g +s/#\.*/&./ +s/#\.\{8\}/#./ +s/,\{1,\}/&,/ +s/,\{5\}/,/ +s/#FALL~//g +h + +s/^~/~ +----------+~/ +s/~[^~]*~$/& +----------+/ +s/~[^~]*|[^~]*3[^~]*//g +s/~[^~]*|[^~]*4[^~]*//g +s/2[a-h]//g +s/\([15-9x]\)[i-p]/\1a/g + +/#OVER/s/^\(\(~[^~]*\)\{6\}~\)\([^~]*~\)/\1 |GAME OVER!|~/ + +/#CURRENT1/s/0[i-p]/O/g +/#CURRENT5/s/0[i-p]/O/g +/#CURRENT6/s/0[i-p]/O/g +/#CURRENT7/s/0[i-p]/O/g +/#CURRENT8/s/0[i-p]/O/g +/#CURRENT9/s/0[i-p]/O/g +/#CURRENTx/s/0[i-p]/O/g +s/0[a-h]/ /g +#s/[+|\-]/&/g +s/1[a-h]/X/g +s/5[a-h]/X/g +s/6[a-h]/X/g +s/7[a-h]/X/g +s/8[a-h]/X/g +s/9[a-h]/X/g +s/x[a-h]/X/g + +:decap +/#NEXT[^~]*[A-P]/{ +s/\(#NEXT[^~]*\)[A-H]/\1 / +s/\(#NEXT[^~]*\)[I-P]/\1X/ +b decap +} +s/\(#NEXT[^~]*\) /\1/ + +s/^\(\(~[^~]*\)\{2\}\)/& Next:/ +s/^\(\(~[^~]*\)\{3\}\)\(.*\)\(#NEXT\([^~]\{4\}\)\)/\1 \5\3\4/ +s/^\(\(~[^~]*\)\{4\}\)\(.*\)\(#NEXT[^~]\{4\} \([^~]\{4\}\)\)/\1 \5\3\4/ +s/^\(\(~[^~]*\)\{5\}\)\(.*\)\(#NEXT\([^~]\{4\} \)\{2\}\([^~]\{4\}\)\)/\1 \6\3\4/ +s/^\(\(~[^~]*\)\{6\}\)\(.*\)\(#NEXT\([^~]\{4\} \)\{3\}\([^~]\{4\}\)\)/\1 \6\3\4/ +s/^\(\(~[^~]*\)\{7\}\)\(.*\)\(#SCORE\([^~]*\)\)/\1 Score:\5 \3\4/ +s/ \(X\{1,4\}\)/ \1 /g +s/^\(\(~[^~]*\)\{9\}\)/& "w" or up - rotate/ +s/^\(\(~[^~]*\)\{10\}\)/& "a" or left - left/ +s/^\(\(~[^~]*\)\{11\}\)/& "d" or right - right/ +s/^\(\(~[^~]*\)\{12\}\)/& "s" or down - one step down/ +s/^\(\(~[^~]*\)\{13\}\)/& "z" or space - drop down/ + +#uncomment the line below to switch colours off +#s/\[\([0-9]*;\)*[0-9]*m//g +s/#[^~]*~//g +s/^~// +s/~/\ +/g +i\ + +p +/GAME OVER!/q From 3eff067c67239441bd8eb6af0fcb6cd76a2574ac Mon Sep 17 00:00:00 2001 From: gritter <> Date: Fri, 1 Jan 2010 19:03:03 +0000 Subject: [PATCH 20/24] _POSIX_PATH_MAX --- whodo/whodo.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/whodo/whodo.c b/whodo/whodo.c index c196590..1840589 100644 --- a/whodo/whodo.c +++ b/whodo/whodo.c @@ -34,7 +34,7 @@ #else #define USED #endif -static const char sccsid[] USED = "@(#)whodo.sl 1.43 (gritter) 10/1/07"; +static const char sccsid[] USED = "@(#)whodo.sl 1.44 (gritter) 1/1/10"; #include #include @@ -95,6 +95,10 @@ static const char sccsid[] USED = "@(#)whodo.sl 1.43 (gritter) 10/1/07"; #define PRNODEV 0 #endif +#ifndef _POSIX_PATH_MAX +#define _POSIX_PATH_MAX 255 +#endif + #define next(wc, s, n) (mb_cur_max > 1 && *(s) & 0200 ? \ ((n) = mbtowc(&(wc), (s), mb_cur_max), \ (n) = ((n) > 0 ? (n) : (n) < 0 ? (wc=WEOF, 1) : 1)) :\ From fa41adbc56dacc1d236f90273091799ca7f4538b Mon Sep 17 00:00:00 2001 From: gritter <> Date: Fri, 1 Jan 2010 19:05:00 +0000 Subject: [PATCH 21/24] handle missing LINE_MAX --- who/who.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/who/who.c b/who/who.c index e35ee6d..187153b 100644 --- a/who/who.c +++ b/who/who.c @@ -33,9 +33,9 @@ #define USED #endif #ifdef SUS -static const char sccsid[] USED = "@(#)who_sus.sl 1.19 (gritter) 1/22/06"; +static const char sccsid[] USED = "@(#)who_sus.sl 1.20 (gritter) 1/1/10"; #else -static const char sccsid[] USED = "@(#)who.sl 1.19 (gritter) 1/22/06"; +static const char sccsid[] USED = "@(#)who.sl 1.20 (gritter) 1/1/10"; #endif #include @@ -52,6 +52,10 @@ static const char sccsid[] USED = "@(#)who.sl 1.19 (gritter) 1/22/06"; #include #include +#ifndef LINE_MAX +#define LINE_MAX 2048 +#endif + enum okay { OKAY, STOP From bfd9d2a781a2960409e8dffd99e0bd314680a38a Mon Sep 17 00:00:00 2001 From: gritter <> Date: Mon, 28 Jun 2010 21:20:36 +0000 Subject: [PATCH 22/24] * col: The behavior of the -x flag has been inverted to actually match the documentation, i.e. to suppress conversion of spaces to tabs (patch by Markus Schnalke). --- CHANGES | 3 +++ col/col.c | 4 ++-- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/CHANGES b/CHANGES index 5e22886..406d5d5 100644 --- a/CHANGES +++ b/CHANGES @@ -10,6 +10,9 @@ Release ... * w, whodo: On a 32-bit system where /proc/kcore is larger than 2 GB, avoid a harmless error message (bug reported by Pierre Gentile). * ptime: Works on recent Linux kernels again. +* col: The behavior of the -x flag has been inverted to actually match + the documentation, i.e. to suppress conversion of spaces to tabs (patch + by Markus Schnalke). Release 070715 * cpio: A "-P" option has been introduced that allows to specify attributes diff --git a/col/col.c b/col/col.c index 4f30728..ad51eb5 100644 --- a/col/col.c +++ b/col/col.c @@ -43,7 +43,7 @@ #else #define USED #endif -static const char sccsid[] USED = "@(#)col.sl 1.9 (gritter) 5/29/05"; +static const char sccsid[] USED = "@(#)col.sl 1.10 (gritter) 6/28/10"; # include # include @@ -425,7 +425,7 @@ emit (long long *s, int lineno) while (*p) { ncp = pcp; while ((*p++&CMASK) == ' ') { - if ((++ncp & 7) == 0 && xflag) { + if ((++ncp & 7) == 0 && !xflag) { pcp = ncp; putchar ('\t'); } From 5b1ea9180629e8c75bd50ff9036d23b27eebfb10 Mon Sep 17 00:00:00 2001 From: gritter <> Date: Sun, 26 Sep 2010 11:53:22 +0000 Subject: [PATCH 23/24] * cut: With "-s", print the last field of a line that was also the last field specified with "-f" (bugreport by Pierre Gentile). --- CHANGES | 2 ++ cut/cut.c | 18 ++++++++++-------- 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/CHANGES b/CHANGES index 406d5d5..13097ec 100644 --- a/CHANGES +++ b/CHANGES @@ -13,6 +13,8 @@ Release ... * col: The behavior of the -x flag has been inverted to actually match the documentation, i.e. to suppress conversion of spaces to tabs (patch by Markus Schnalke). +* cut: With "-s", print the last field of a line that was also the last + field specified with "-f" (bugreport by Pierre Gentile). Release 070715 * cpio: A "-P" option has been introduced that allows to specify attributes diff --git a/cut/cut.c b/cut/cut.c index ddd9d85..9772e3f 100644 --- a/cut/cut.c +++ b/cut/cut.c @@ -32,7 +32,7 @@ #else #define USED #endif -static const char sccsid[] USED = "@(#)cut.sl 1.20 (gritter) 5/29/05"; +static const char sccsid[] USED = "@(#)cut.sl 1.21 (gritter) 9/26/10"; #include #include @@ -257,7 +257,7 @@ cutf(struct iblok *ip) static char *line; static size_t linesize; char *cp, *lp, *lq; - int c, i, n, m, gotcha; + int c, i, n, m, otherfield, gotdelim; char b; wint_t wc; const int incr = 128; @@ -265,7 +265,7 @@ cutf(struct iblok *ip) if (linesize == 0) line = smalloc(linesize = incr); lp = line; - gotcha = 0; + gotdelim = otherfield = 0; i = 1; do { if (multibyte) @@ -281,22 +281,24 @@ cutf(struct iblok *ip) } n = 1; } + if (wc == wcdelim) + gotdelim = 1; if (cp == NULL || wc == '\n' || wc == wcdelim) { - if (have(i) && (!sflag || gotcha || wc == wcdelim) || + if (have(i) && (!sflag || gotdelim || wc == wcdelim) || (!sflag && i == 1 && (cp == NULL || wc == '\n'))) { - if (gotcha) + if (otherfield) for (m = 0; mbdelim[m]; m++) putc(mbdelim[m], stdout); for (lq = line; lq < lp; lq++) putc(*lq, stdout); - gotcha = 1; + otherfield = 1; } if (wc == '\n') { - if (gotcha) + if (otherfield) putc('\n', stdout); i = 1; - gotcha = 0; + gotdelim = otherfield = 0; } else i++; lp = line; From 91e8b57a51275219efc0981a73d2cb93cca99237 Mon Sep 17 00:00:00 2001 From: gritter <> Date: Sat, 9 Oct 2010 21:19:23 +0000 Subject: [PATCH 24/24] * cpio, tar: If an archive contains a file that is a hardlink to itself on extraction, do nothing at all instead of discarding its data. This mainly happens if a file with more than one link is included under the same name in an archive twice. Since special situations on extraction such as bind mounts on Linux may lead to this scenario even in cases where both link names are different, this is now treated like a successful link() step (bugreport by Thomas Graf). --- CHANGES | 7 +++++++ cpio/cpio.c | 50 ++++++++++++++++++++++++++++++++++++++++++-------- cpio/version.c | 4 ++-- tar/tar.c | 48 ++++++++++++++++++++++++++++++++++++++++++------ 4 files changed, 93 insertions(+), 16 deletions(-) diff --git a/CHANGES b/CHANGES index 13097ec..1b0b25f 100644 --- a/CHANGES +++ b/CHANGES @@ -4,6 +4,13 @@ Release ... header and terminating. * pg: Handle cases where standard output is a terminal but not open for reading (bug reported by Keith Doyle). +* cpio, tar: If an archive contains a file that is a hardlink to itself on + extraction, do nothing at all instead of discarding its data. This mainly + happens if a file with more than one link is included under the same name + in an archive twice. Since special situations on extraction such as bind + mounts on Linux may lead to this scenario even in cases where both link + names are different, this is now treated like a successful link() step + (bugreport by Thomas Graf). * Made the getopt() substitute work with the getopt$UNIX2003() function redirection mechanism on Mac OS X Leopard. * mknod, pgrep, ps: Mac OS X Leopard compilation fixes. diff --git a/cpio/cpio.c b/cpio/cpio.c index bc256ed..955cda7 100644 --- a/cpio/cpio.c +++ b/cpio/cpio.c @@ -26,7 +26,7 @@ */ /* - * Sccsid @(#)cpio.c 1.304 (gritter) 2/14/09 + * Sccsid @(#)cpio.c 1.307 (gritter) 10/9/10 */ #include @@ -81,7 +81,9 @@ #if defined (__linux__) || defined (__sun) || defined (__FreeBSD__) || \ defined (__hpux) || defined (_AIX) || defined (__NetBSD__) || \ defined (__OpenBSD__) || defined (__DragonFly__) || defined (__APPLE__) +#ifndef __G__ #include +#endif #else /* SVR4.2MP */ #include #include @@ -95,7 +97,7 @@ #include #endif /* _AIX */ -#ifndef major +#if !defined (major) && !defined (__G__) #include #endif /* !major */ @@ -111,6 +113,10 @@ #endif /* _IO_putc_unlocked */ #endif /* __GLIBC__ */ +#ifndef _POSIX_PATH_MAX +#define _POSIX_PATH_MAX 255 +#endif + /* * The cpio code assumes that all following S_IFMT bits are the same as * those of the mode fields in cpio headers. The only real Unix system @@ -3071,13 +3077,29 @@ linkunlink(const char *path1, const char *path2) do { if (link(path1, path2) == 0) { - if (vflag && pax == PAX_TYPE_CPIO) + good: if (vflag && pax == PAX_TYPE_CPIO) printf("%s linked to %s\n", path1, path2); return 0; } - if (errno == EEXIST && unlink(path2) < 0) - emsg(3, sysv3 ? "cannot unlink <%s>" : + if (errno == EEXIST) { + struct stat st1, st2; + if (lstat(path1, &st1) == 0 && + lstat(path2, &st2) == 0 && + st1.st_dev == st2.st_dev && + st1.st_ino == st2.st_ino) + /* + * An attempt to hardlink a file to itself. + * This happens if a file with more than one + * link has been stored in the archive more + * than once under the same name. This is odd + * but the best we can do is nothing at all + * in such a case. + */ + goto good; + if (unlink(path2) < 0) + emsg(3, sysv3 ? "cannot unlink <%s>" : "Error cannot unlink \"%s\"", path2); + } } while (twice++ == 0); emsg(023, sysv3 ? "Cannot link <%s> & <%s>" : "Cannot link \"%s\" and \"%s\"", path1, path2); @@ -4488,8 +4510,9 @@ skipdata(struct file *f, int (*copydata)(struct file *, const char *, int)) static int tseek(off_t n) { - int fault; + int fault = 0; +#ifndef __G__ if (tapeblock > 0) { int i = (n - poffs) / tapeblock; #if defined (__linux__) || defined (__sun) || defined (__FreeBSD__) || \ @@ -4506,6 +4529,7 @@ tseek(off_t n) fault = ioctl(mt, t, a); #endif /* SVR4.2MP */ } else +#endif /* __G__ */ fault = lseek(mt, n - poffs, SEEK_CUR) == (off_t)-1 ? -1 : 0; if (fault == 0) poffs = n; @@ -4735,12 +4759,15 @@ mstat(void) done(1); } #if defined (__linux__) +#ifndef __G__ if ((mtst.st_mode&S_IFMT) == S_IFCHR) { struct mtget mg; if (ioctl(mt, MTIOCGET, &mg) == 0) tapeblock = (mg.mt_dsreg&MT_ST_BLKSIZE_MASK) >> MT_ST_BLKSIZE_SHIFT; - } else if ((mtst.st_mode&S_IFMT) == S_IFBLK) { + } else +#endif /* __G__ */ + if ((mtst.st_mode&S_IFMT) == S_IFBLK) { /* * If using a block device, write blocks of the floppy * disk sector with direct i/o. This enables signals @@ -6067,7 +6094,7 @@ zipwtemp(int fd, const char *fn, struct stat *st, union bincpio *bp, size_t sz, uint32_t dev, uint32_t ino, uint32_t *crc, long long *csize) { static int tf = -1; - static char tlate[] = "/var/tmp/cpioXXXXXX"; + static char tlate[_POSIX_PATH_MAX+1]; char ibuf[32768]; #if USE_ZLIB || USE_BZLIB char obuf[32768]; @@ -6083,6 +6110,13 @@ zipwtemp(int fd, const char *fn, struct stat *st, union bincpio *bp, size_t sz, *crc = 0; #if USE_ZLIB || USE_BZLIB if (tf < 0) { + char *tmpdir; + if ((tmpdir = getenv("TMPDIR")) == NULL) + tmpdir = "/var/tmp"; + if (snprintf(tlate, sizeof tlate, "%s/cpioXXXXXX", tmpdir) >= + sizeof tlate) + snprintf(tlate, sizeof tlate, "%s/cpioXXXXXX", + "/var/tmp"); if ((tf = mkstemp(tlate)) >= 0) unlink(tlate); } else if (lseek(tf, 0, SEEK_SET) != 0) { diff --git a/cpio/version.c b/cpio/version.c index a9d4a46..f85de72 100644 --- a/cpio/version.c +++ b/cpio/version.c @@ -5,12 +5,12 @@ #else #define USED #endif -static const char sccsid[] USED = "@(#)cpio.sl 2.9 (gritter) 8/14/09"; +static const char sccsid[] USED = "@(#)cpio.sl 2.11 (gritter) 10/9/10"; /* SLIST */ /* blast.c: * Sccsid @(#)blast.c 1.2 (gritter) 2/17/04 blast.h: * Sccsid @(#)blast.h 1.2 (gritter) 2/17/04 -cpio.c: * Sccsid @(#)cpio.c 1.305 (gritter) 8/14/09 +cpio.c: * Sccsid @(#)cpio.c 1.307 (gritter) 10/9/10 cpio.h: Sccsid @(#)cpio.h 1.29 (gritter) 3/26/07 crc32.c: * Sccsid @(#)crc32.c 1.2 (gritter) 5/29/03 expand.c: Sccsid @(#)expand.c 1.6 (gritter) 12/15/03 diff --git a/tar/tar.c b/tar/tar.c index 2d3dada..63818ac 100644 --- a/tar/tar.c +++ b/tar/tar.c @@ -43,7 +43,7 @@ #else #define USED #endif -static const char sccsid[] USED = "@(#)tar.sl 1.177 (gritter) 4/14/07"; +static const char sccsid[] USED = "@(#)tar.sl 1.180 (gritter) 10/9/10"; #include #include @@ -88,7 +88,9 @@ static const char sccsid[] USED = "@(#)tar.sl 1.177 (gritter) 4/14/07"; #if defined (__linux__) || defined (__sun) || defined (__FreeBSD__) || \ defined (__hpux) || defined (_AIX) || defined (__NetBSD__) || \ defined (__OpenBSD__) || defined (__DragonFly__) || defined (__APPLE__) +#ifndef __G__ #include +#endif #else /* SVR4.2MP */ #include #include @@ -98,7 +100,7 @@ static const char sccsid[] USED = "@(#)tar.sl 1.177 (gritter) 4/14/07"; #include #endif -#ifndef major +#if !defined (major) && !defined (__G__) #include #endif /* !major */ @@ -377,6 +379,7 @@ static char *sequence(void); static void docomp(const char *); static int jflag, zflag, Zflag; static int utf8(const char *); +static void settmp(char *, size_t, const char *); int main(int argc, char *argv[]) @@ -678,11 +681,12 @@ dorep(char *argv[]) } while (!endtape(1)); } if (tfile != NULL) { - char tname[] = "/tmp/tarXXXXXX"; + char tname[PATH_MAX+1]; int tfd; pid_t pid; fflush(tfile); rewind(tfile); + settmp(tname, sizeof tname, "%s/tarXXXXXX"); if ((tfd = mkstemp(tname)) < 0) { fprintf(stderr, "%s: cannot create temporary " "file (%s)\n", progname, tname); @@ -1648,7 +1652,23 @@ xtrreg(const char *name, struct stat *sp) static int xtrlink(const char *name, struct stat *sp, int symbolic) { - remove(name); + struct stat nst, ost; + + if (lstat(name, &nst) == 0) { + if ((nst.st_mode & S_IFMT) == S_IFDIR) + rmdir(name); + else if (!symbolic && lstat(hbuf.rlinkname, &ost) == 0 && + nst.st_dev == ost.st_dev && + nst.st_ino == ost.st_ino) + /* An attempt to hardlink "name" to itself. This + * happens if a file with more than link has been + * stored in the archive more than once under the + * same name. This is odd but the best we can do + * is nothing at all in such a case. */ + goto good; + else + unlink(name); + } if ((symbolic?symlink:link)(symbolic?hbuf.linkname:hbuf.rlinkname, name) < 0) { if (symbolic) @@ -1659,7 +1679,7 @@ xtrlink(const char *name, struct stat *sp, int symbolic) edone(1); return -1; } - if (vflag) +good: if (vflag) fprintf(stderr, "%s %s %s\n", name, symbolic ? "symbolic link to" : "linked to", hbuf.linkname); @@ -2156,6 +2176,7 @@ static void tseek(int n, int rew) { int fault; +#ifndef __G__ if (tapeblock > 0 && rew) { #if defined (__linux__) || defined (__sun) || defined (__FreeBSD__) || \ defined (__hpux) || defined (_AIX) || defined (__NetBSD__) || \ @@ -2171,6 +2192,7 @@ tseek(int n, int rew) fault = ioctl(mt, t, a) < 0; #endif /* SVR4.2MP */ } else +#endif fault = lseek(mt, TBLOCK*n, SEEK_CUR) == (off_t)-1; if (fault && rew) { fprintf(stderr, "%s: device seek error\n", progname); @@ -2660,11 +2682,13 @@ domtstat(void) } #endif /* BLKBSZGET */ } +#ifndef __G__ } else if ((mtstat.st_mode&S_IFMT) == S_IFCHR) { struct mtget mg; if (ioctl(mt, MTIOCGET, &mg) == 0) tapeblock = ((mg.mt_dsreg&MT_ST_BLKSIZE_MASK) >> MT_ST_BLKSIZE_SHIFT); +#endif } #elif defined (__sun) if ((mtstat.st_mode&S_IFMT) == S_IFCHR) { @@ -2947,10 +2971,11 @@ readexcl(const char *fn) static void creatfile(void) { - char tname[] = "/tmp/tarXXXXXX"; + char tname[PATH_MAX+1]; if (tfile != NULL) return; + settmp(tname, sizeof tname, "%s/tarXXXXXX"); if ((tfile = fdopen(mkstemp(tname), "w")) == NULL) { fprintf(stderr, "%s: cannot create temporary file (%s)\n", progname, tname); @@ -3166,3 +3191,14 @@ utf8(const char *cp) } return 1; } + +static void +settmp(char *tbuf, size_t len, const char *template) +{ + char *tmpdir; + + if ((tmpdir = getenv("TMPDIR")) == NULL) + tmpdir = "/tmp"; + if (snprintf(tbuf, len, template, tmpdir) >= len) + snprintf(tbuf, len, template, "/tmp"); +}