From e744d38673abfc957465a29a25e9cde912a802d8 Mon Sep 17 00:00:00 2001 From: Nate Williams Date: Tue, 3 Dec 1996 21:56:15 +0000 Subject: [PATCH] Added support for '-T' and '-B' (text and binary) file recognition by peeking inside of Chris Torek's stdio library internals. This is similar to the code used for other systems, but didn't work on CT's new implementation. Submitted by: Gary Kline --- gnu/usr.bin/perl/perl/doio.c | 22 +++++++++++++++++++++- gnu/usr.bin/perl/perl/tdoio.c | 23 ++++++++++++++++++++++- 2 files changed, 43 insertions(+), 2 deletions(-) diff --git a/gnu/usr.bin/perl/perl/doio.c b/gnu/usr.bin/perl/perl/doio.c index 9c0731f6099f..0ace3773f9dd 100644 --- a/gnu/usr.bin/perl/perl/doio.c +++ b/gnu/usr.bin/perl/perl/doio.c @@ -1,4 +1,4 @@ -/* $RCSfile: doio.c,v $$Revision: 1.2 $$Date: 1994/09/11 03:17:32 $ +/* $RCSfile: doio.c,v $$Revision: 1.3 $$Date: 1995/05/30 05:03:00 $ * * Copyright (c) 1991, Larry Wall * @@ -6,6 +6,9 @@ * License or the Artistic License, as specified in the README file. * * $Log: doio.c,v $ + * Revision 1.3 1995/05/30 05:03:00 rgrimes + * Remove trailing whitespace. + * * Revision 1.2 1994/09/11 03:17:32 gclarkii * Changed AF_LOCAL to AF_LOCAL_XX so as not to conflict with 4.4 socket.h * Added casts to shutup warnings in doio.c @@ -1220,8 +1223,25 @@ STR *str; return &str_yes; len = stio->ifp->_cnt + (stio->ifp->_ptr - stio->ifp->_base); s = stio->ifp->_base; +#else +#if (defined(BSD) && (BSD >= 199103)) + fstat(fileno(stio->ifp),&statcache); + if (S_ISDIR(statcache.st_mode)) /* handle NFS glitch */ + return arg->arg_type == O_FTTEXT ? &str_no : &str_yes; + + if (stio->ifp->_bf._size <= 0) { + i = getc(stio->ifp); + if (i != EOF) + (void)ungetc(i,stio->ifp); + } + + if (stio->ifp->_bf._size <= 0) + return &str_yes; + len = stio->ifp->_bf._size+(stio->ifp->_p - stio->ifp->_bf._base); + s = stio->ifp->_bf._base; #else fatal("-T and -B not implemented on filehandles"); +#endif #endif } else { diff --git a/gnu/usr.bin/perl/perl/tdoio.c b/gnu/usr.bin/perl/perl/tdoio.c index 1cd6269e8c70..cd5d480bcb80 100644 --- a/gnu/usr.bin/perl/perl/tdoio.c +++ b/gnu/usr.bin/perl/perl/tdoio.c @@ -1,4 +1,4 @@ -/* $RCSfile: tdoio.c,v $$Revision: 1.1.1.1 $$Date: 1994/09/10 06:27:36 $ +/* $RCSfile: tdoio.c,v $$Revision: 1.2 $$Date: 1995/05/30 05:03:23 $ * * Copyright (c) 1991, Larry Wall * @@ -6,6 +6,9 @@ * License or the Artistic License, as specified in the README file. * * $Log: tdoio.c,v $ + * Revision 1.2 1995/05/30 05:03:23 rgrimes + * Remove trailing whitespace. + * * Revision 1.1.1.1 1994/09/10 06:27:36 gclarkii * Initial import of Perl 4.046 bmaked * @@ -1213,8 +1216,26 @@ STR *str; return &str_yes; len = stio->ifp->_cnt + (stio->ifp->_ptr - stio->ifp->_base); s = stio->ifp->_base; +#else +#if (defined(BSD) && (BSD >= 199103)) + s = stio->ifp->_base; + fstat(fileno(stio->ifp),&statcache); + if (S_ISDIR(statcache.st_mode)) /* handle NFS glitch */ + return arg->arg_type == O_FTTEXT ? &str_no : &str_yes; + + if (stio->ifp->_bf._size <= 0) { + i = getc(stio->ifp); + if (i != EOF) + (void)ungetc(i,stio->ifp); + } + + if (stio->ifp->_bf._size <= 0) + return &str_yes; + len = stio->ifp->_bf._size+(stio->ifp->_p - stio->ifp->_bf._base); + s = stio->ifp->_bf._base; #else fatal("-T and -B not implemented on filehandles"); +#endif #endif } else {