diff -aru -x*.o textutils-2.0.16/lib/argmatch.c textutils-2.0.16_pb/lib/argmatch.c --- textutils-2.0.16/lib/argmatch.c Thu May 24 07:12:00 2001 +++ textutils-2.0.16_pb/lib/argmatch.c Wed Oct 3 20:32:50 2001 @@ -39,6 +39,7 @@ #include "error.h" #include "quotearg.h" #include "quote.h" +#include "unlocked-io.h" /* When reporting an invalid argument, show nonprinting characters by using the quoting style ARGMATCH_QUOTING_STYLE. Do not use Only in textutils-2.0.16/lib: charset.alias diff -aru -x*.o textutils-2.0.16/lib/closeout.c textutils-2.0.16_pb/lib/closeout.c --- textutils-2.0.16/lib/closeout.c Sat Aug 26 13:05:50 2000 +++ textutils-2.0.16_pb/lib/closeout.c Wed Oct 3 20:32:39 2001 @@ -40,6 +40,8 @@ extern int errno; #endif +#include "unlocked-io.h" + #include "closeout.h" #include "error.h" #include "quotearg.h" diff -aru -x*.o textutils-2.0.16/lib/dirname.c textutils-2.0.16_pb/lib/dirname.c --- textutils-2.0.16/lib/dirname.c Mon May 21 07:36:36 2001 +++ textutils-2.0.16_pb/lib/dirname.c Wed Oct 3 20:32:26 2001 @@ -25,6 +25,7 @@ #include "dirname.h" #include "xalloc.h" +#include "unlocked-io.h" /* Return the length of `dirname (PATH)', or zero if PATH is in the working directory. Works properly even if diff -aru -x*.o textutils-2.0.16/lib/error.c textutils-2.0.16_pb/lib/error.c --- textutils-2.0.16/lib/error.c Sun Sep 2 15:35:02 2001 +++ textutils-2.0.16_pb/lib/error.c Wed Oct 3 20:32:18 2001 @@ -62,6 +62,8 @@ char *strerror_r (); #endif +#include "unlocked-io.h" + #ifndef _ # define _(String) String #endif diff -aru -x*.o textutils-2.0.16/lib/exclude.c textutils-2.0.16_pb/lib/exclude.c --- textutils-2.0.16/lib/exclude.c Sun Sep 30 07:27:18 2001 +++ textutils-2.0.16_pb/lib/exclude.c Wed Oct 3 20:31:55 2001 @@ -58,6 +58,7 @@ #include "exclude.h" #include "fnmatch.h" #include "xalloc.h" +#include "unlocked-io.h" #ifndef SIZE_MAX # define SIZE_MAX ((size_t) -1) diff -aru -x*.o textutils-2.0.16/lib/getloadavg.c textutils-2.0.16_pb/lib/getloadavg.c --- textutils-2.0.16/lib/getloadavg.c Mon Jun 19 08:25:01 2000 +++ textutils-2.0.16_pb/lib/getloadavg.c Wed Oct 3 20:31:29 2001 @@ -105,6 +105,8 @@ # define setlocale(Category, Locale) /* empty */ #endif +#include "unlocked-io.h" + #ifndef HAVE_GETLOADAVG /* The existing Emacs configuration files define a macro called diff -aru -x*.o textutils-2.0.16/lib/getpass.c textutils-2.0.16_pb/lib/getpass.c --- textutils-2.0.16/lib/getpass.c Wed Jun 21 21:21:03 2000 +++ textutils-2.0.16_pb/lib/getpass.c Wed Oct 3 20:30:32 2001 @@ -23,6 +23,7 @@ #include #include #include +#include "unlocked-io.h" #include "getline.h" /* It is desirable to use this bit on systems that have it. diff -aru -x*.o textutils-2.0.16/lib/getstr.c textutils-2.0.16_pb/lib/getstr.c --- textutils-2.0.16/lib/getstr.c Wed Jun 21 10:09:22 2000 +++ textutils-2.0.16_pb/lib/getstr.c Wed Oct 3 20:29:37 2001 @@ -32,6 +32,7 @@ #else char *malloc (), *realloc (); #endif +#include "unlocked-io.h" /* Always add at least this many bytes when extending the buffer. */ #define MIN_CHUNK 64 diff -aru -x*.o textutils-2.0.16/lib/getusershell.c textutils-2.0.16_pb/lib/getusershell.c --- textutils-2.0.16/lib/getusershell.c Sat Dec 16 22:25:44 2000 +++ textutils-2.0.16_pb/lib/getusershell.c Wed Oct 3 20:28:43 2001 @@ -37,6 +37,7 @@ #endif #include #include "xalloc.h" +#include "unlocked-io.h" #if defined (STDC_HEADERS) || (!defined (isascii) && !defined (HAVE_ISASCII)) # define IN_CTYPE_DOMAIN(c) 1 Only in textutils-2.0.16/lib: libfetish.a diff -aru -x*.o textutils-2.0.16/lib/linebuffer.c textutils-2.0.16_pb/lib/linebuffer.c --- textutils-2.0.16/lib/linebuffer.c Mon Aug 7 16:48:18 2000 +++ textutils-2.0.16_pb/lib/linebuffer.c Wed Oct 3 20:50:46 2001 @@ -15,38 +15,45 @@ along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ -/* Written by Richard Stallman. */ +/* Written by Richard Stallman and Padraig Brady */ #ifdef HAVE_CONFIG_H # include #endif #include +#include +#include #include +#include "unlocked-io.h" #include "linebuffer.h" char *xmalloc (); char *xrealloc (); void free (); -/* Initialize linebuffer LINEBUFFER for use. */ +/* Should really allow this to be passed to initbuffer */ +#define INITIAL_LINE_LENGTH 200 +/* Initialize linebuffer LINEBUFFER for use. */ void initbuffer (struct linebuffer *linebuffer) { linebuffer->length = 0; - linebuffer->size = 200; + linebuffer->size = INITIAL_LINE_LENGTH; linebuffer->buffer = (char *) xmalloc (linebuffer->size); } /* Read an arbitrarily long line of text from STREAM into LINEBUFFER. Keep the newline; append a newline if it's the last line of a file - that ends in a non-newline character. Do not null terminate. - Return LINEBUFFER, except at end of file return 0. */ - + that ends in a non-newline character. Do not null terminate. + Therefore the stream can contain NULLs and the length (including + the newline) is returned in linebuffer->size. + Return LINEBUFFER, except at end of file or error return NULL.*/ struct linebuffer * readline (struct linebuffer *linebuffer, FILE *stream) { +#if HAVE_GETC_UNLOCKED int c; char *buffer = linebuffer->buffer; char *p = linebuffer->buffer; @@ -79,6 +86,105 @@ while (c != '\n'); linebuffer->length = p - buffer; +#else + size_t fgetSize; + char* fgetPos; + char* newline; + char* fgetsRet; + char* buf; + + fgetPos = buf = linebuffer->buffer; + fgetSize = linebuffer->size; + + if (feof (stream) || ferror (stream)) + return NULL; + + while(1) + { + memset (fgetPos, '\1', fgetSize); /* Can be anything except 0 */ + if ((fgetsRet=fgets (fgetPos, (int) fgetSize, stream))) + { + newline=memchr (fgetPos, '\n', fgetSize); + if (!newline) /* No \n => buffer possibly full */ + { + if (buf[linebuffer->size-1] == '\0') /*buffer full*/ + { + if (!feof (stream)) + { + fgetSize = linebuffer->size + 1; + linebuffer->size *= 2; + buf = (char *) xrealloc (buf, linebuffer->size); + linebuffer->buffer = buf; + fgetPos = buf + fgetSize -2; + continue; + } + else /* small chance incomplete line fit buffer exactly */ + { + newline = &buf[linebuffer->size-1]; + *newline = '\n'; + } + } + else /* incomplete line received */ + { + newline=memrchr (fgetPos, '\0', fgetSize); + *newline = '\n'; + } + } + } + else + return NULL; + break; + } + linebuffer->length = newline - buf + 1; +#endif + return linebuffer; +} + +/* Read a long line of text from STREAM into LINEBUFFER. + Remove any newline & null terminate (so can't be \0's in stream), + Return LINEBUFFER, except at end of file or error return NULL. + Note the length is not returned in linebuffer->length but can + be easily determined using strlen(linebuffer->buffer) if required. */ +struct linebuffer * +readlineNoNulls (struct linebuffer *linebuffer, FILE *stream) +{ + size_t fgetSize; + char* fgetPos; + char* newline; + char* fgetsRet; + char* buf; + + fgetPos = buf = linebuffer->buffer; + fgetSize = linebuffer->size; + buf[0]='\0'; + + if (feof (stream) || ferror (stream)) + return NULL; + + while(1) { + buf[linebuffer->size-2]='\0'; //flag for buffer full + if ((fgetsRet=fgets (fgetPos, (int) fgetSize, stream))) { + newline=strchr (fgetPos, '\n'); + if (newline) + *newline='\0'; + else { + if (buf[linebuffer->size-2] != '\0') { //buffer possibly full + if (!feof (stream)) { + fgetSize = linebuffer->size + 1; + linebuffer->size *= 2; + buf = (char *) xrealloc (buf, linebuffer->size); + linebuffer->buffer = buf; + fgetPos = buf + fgetSize -2; + continue; + } + /*else small chance occurred that data matched buff size exactly*/ + } + } + } else { + return NULL; + } + break; + } return linebuffer; } diff -aru -x*.o textutils-2.0.16/lib/linebuffer.h textutils-2.0.16_pb/lib/linebuffer.h --- textutils-2.0.16/lib/linebuffer.h Mon Aug 7 16:48:18 2000 +++ textutils-2.0.16_pb/lib/linebuffer.h Wed Oct 3 19:39:29 2001 @@ -40,10 +40,20 @@ /* Read an arbitrarily long line of text from STREAM into LINEBUFFER. Keep the newline; append a newline if it's the last line of a file - that ends in a non-newline character. Do not null terminate. - Return LINEBUFFER, except at end of file return 0. */ + that ends in a non-newline character. Do not null terminate. + Therefore the stream can contain NULLs and the length (including + the newline) is returned in linebuffer->size. + Return LINEBUFFER, except at end of file or error return NULL.*/ struct linebuffer *readline PARAMS ((struct linebuffer *linebuffer, FILE *stream)); + +/* Read a long line of text from STREAM into LINEBUFFER. + Remove any newline & null terminate (so can't be \0's in stream), + Return LINEBUFFER, except at end of file or error return NULL. + Note the length is not returned in linebuffer->length but can + be easily determined using strlen(linebuffer->buffer) if required. */ +struct linebuffer *readlineNoNulls PARAMS ((struct linebuffer *linebuffer, + FILE *stream)); /* Free linebuffer LINEBUFFER and its data, all allocated with malloc. */ void freebuffer PARAMS ((struct linebuffer *)); diff -aru -x*.o textutils-2.0.16/lib/localcharset.c textutils-2.0.16_pb/lib/localcharset.c --- textutils-2.0.16/lib/localcharset.c Sat Sep 22 15:48:31 2001 +++ textutils-2.0.16_pb/lib/localcharset.c Wed Oct 3 20:28:18 2001 @@ -55,6 +55,8 @@ # include #endif +#include "unlocked-io.h" + #ifndef DIRECTORY_SEPARATOR # define DIRECTORY_SEPARATOR '/' #endif diff -aru -x*.o textutils-2.0.16/lib/md5.c textutils-2.0.16_pb/lib/md5.c --- textutils-2.0.16/lib/md5.c Sun Oct 22 22:09:43 2000 +++ textutils-2.0.16_pb/lib/md5.c Wed Oct 3 20:41:38 2001 @@ -37,6 +37,8 @@ #include "md5.h" +#include "unlocked-io.h" + #ifdef _LIBC # include # if __BYTE_ORDER == __BIG_ENDIAN diff -aru -x*.o textutils-2.0.16/lib/mountlist.c textutils-2.0.16_pb/lib/mountlist.c --- textutils-2.0.16/lib/mountlist.c Sun Sep 30 22:27:48 2001 +++ textutils-2.0.16_pb/lib/mountlist.c Wed Oct 3 20:27:12 2001 @@ -21,6 +21,8 @@ #include #include +#include "unlocked-io.h" + #include "mountlist.h" #ifdef STDC_HEADERS diff -aru -x*.o textutils-2.0.16/lib/obstack.c textutils-2.0.16_pb/lib/obstack.c --- textutils-2.0.16/lib/obstack.c Sat Aug 25 18:17:00 2001 +++ textutils-2.0.16_pb/lib/obstack.c Wed Oct 3 20:26:59 2001 @@ -21,6 +21,7 @@ #ifdef HAVE_CONFIG_H # include #endif +#include "unlocked-io.h" #include "obstack.h" diff -aru -x*.o textutils-2.0.16/lib/posixtm.c textutils-2.0.16_pb/lib/posixtm.c --- textutils-2.0.16/lib/posixtm.c Mon Jun 26 11:55:18 2000 +++ textutils-2.0.16_pb/lib/posixtm.c Wed Oct 3 20:26:49 2001 @@ -39,6 +39,7 @@ # include #endif +#include "unlocked-io.h" #include "posixtm.h" /* ISDIGIT differs from isdigit, as follows: diff -aru -x*.o textutils-2.0.16/lib/readtokens.c textutils-2.0.16_pb/lib/readtokens.c --- textutils-2.0.16/lib/readtokens.c Sun Apr 11 14:25:52 1999 +++ textutils-2.0.16_pb/lib/readtokens.c Wed Oct 3 20:26:25 2001 @@ -48,6 +48,7 @@ /* memory.h and strings.h conflict on some systems. */ #endif /* not STDC_HEADERS and not HAVE_STRING_H */ +#include "unlocked-io.h" #include "readtokens.h" void *xmalloc (); void *xrealloc (); diff -aru -x*.o textutils-2.0.16/lib/readutmp.c textutils-2.0.16_pb/lib/readutmp.c --- textutils-2.0.16/lib/readutmp.c Wed Apr 5 16:00:11 2000 +++ textutils-2.0.16_pb/lib/readutmp.c Wed Oct 3 20:26:15 2001 @@ -29,6 +29,7 @@ # include #endif /* STDC_HEADERS || HAVE_STRING_H */ +#include "unlocked-io.h" #include "readutmp.h" char *xmalloc (); Only in textutils-2.0.16/lib: ref-add.sed Only in textutils-2.0.16/lib: ref-del.sed diff -aru -x*.o textutils-2.0.16/lib/regex.c textutils-2.0.16_pb/lib/regex.c --- textutils-2.0.16/lib/regex.c Sat Sep 1 08:37:55 2001 +++ textutils-2.0.16_pb/lib/regex.c Wed Oct 3 20:26:00 2001 @@ -192,6 +192,7 @@ /* isalpha etc. are used for the character classes. */ # include +#include "unlocked-io.h" /* Jim Meyering writes: diff -aru -x*.o textutils-2.0.16/lib/sha.c textutils-2.0.16_pb/lib/sha.c --- textutils-2.0.16/lib/sha.c Mon Sep 25 00:59:39 2000 +++ textutils-2.0.16_pb/lib/sha.c Wed Oct 3 20:42:01 2001 @@ -25,6 +25,8 @@ #include "md5.h" #include "sha.h" +#include "unlocked-io.h" + /* Not-swap is a macro that does an endian swap on architectures that are big-endian, as SHA needs some data in a little-endian format diff -aru -x*.o textutils-2.0.16/lib/unicodeio.c textutils-2.0.16_pb/lib/unicodeio.c --- textutils-2.0.16/lib/unicodeio.c Tue Mar 6 18:11:01 2001 +++ textutils-2.0.16_pb/lib/unicodeio.c Wed Oct 3 20:22:48 2001 @@ -53,6 +53,7 @@ #endif #include "unicodeio.h" +#include "unlocked-io.h" /* When we pass a Unicode character to iconv(), we must pass it in a suitable encoding. The standardized Unicode encodings are diff -aru -x*.o textutils-2.0.16/lib/version-etc.c textutils-2.0.16_pb/lib/version-etc.c --- textutils-2.0.16/lib/version-etc.c Mon Aug 27 09:50:10 2001 +++ textutils-2.0.16_pb/lib/version-etc.c Wed Oct 3 20:22:31 2001 @@ -30,6 +30,7 @@ #else # define _(Text) Text #endif +#include "unlocked-io.h" /* Default copyright goes to the FSF. */ diff -aru -x*.o textutils-2.0.16/lib/yesno.c textutils-2.0.16_pb/lib/yesno.c --- textutils-2.0.16/lib/yesno.c Mon Aug 7 16:48:19 2000 +++ textutils-2.0.16_pb/lib/yesno.c Wed Oct 3 20:22:13 2001 @@ -24,6 +24,7 @@ # include #endif #include +#include "unlocked-io.h" /* Read one line from standard input and return nonzero if that line begins with y or Y,