cechew@bruce.OZ (Earl Chew) (09/05/89)
#! /bin/sh
# This is a shell archive. Remove anything before this line, then unpack
# it by saving it into a file and typing "sh file". To overwrite existing
# files, type "sh file -c". You can also feed this as standard input via
# unshar, or by typing "sh <file", e.g.. If this archive is complete, you
# will see the following message at the end:
# "End of archive 2 (of 5)."
# Contents: exercise.c.cdif exit.c.cdif fprintf.c.cdif fputs.c.cdif
# fread.c.cdif fscanf.c.cdif
# Wrapped by cechew@bruce on Tue Sep 5 16:55:06 1989
PATH=/bin:/usr/bin:/usr/ucb ; export PATH
if test -f 'exercise.c.cdif' -a "${1}" != "-c" ; then
echo shar: Will not clobber existing file \"'exercise.c.cdif'\"
else
echo shar: Extracting \"'exercise.c.cdif'\" \(2141 characters\)
sed "s/^X//" >'exercise.c.cdif' <<'END_OF_FILE'
X*** Old/exercise.c Mon Sep 4 08:55:42 1989
X--- New/exercise.c Tue Sep 5 14:39:45 1989
X***************
X*** 20,26
X #define LARGEBUFS 16
X #if defined(MSDOS)
X # define TTY "con"
X- void (*__cleanup)() = 0;
X #else
X # define TTY "/dev/tty"
X #endif
X
X--- 20,25 -----
X #define LARGEBUFS 16
X #if defined(MSDOS)
X # define TTY "con"
X #else
X # define TTY "/dev/tty"
X #endif
X***************
X*** 548,554
X char buf[1023];
X char bbuf[3071];
X double sqrt();
X! void *malloc();
X
X puts("\nFwrite Test");
X if ((fp = fopen(TESTFILE, "w+")) != NULL) {
X
X--- 547,555 -----
X char buf[1023];
X char bbuf[3071];
X double sqrt();
X! char *malloc();
X! void free();
X! char *p;
X
X puts("\nFwrite Test");
X if ((fp = fopen(TESTFILE, "w+")) != NULL) {
X***************
X*** 612,617
X }
X }
X puts(" verified ok");
X }
X }
X
X
X--- 613,641 -----
X }
X }
X puts(" verified ok");
X+
X+ rewind(fp);
X+ p = malloc(48*1024);
X+ for (j = 13, i = 48*1024; --i; j++)
X+ p[i] = j;
X+ fwrite(p, 48*1024, 1, fp);
X+ rewind(fp);
X+ for (i = 48*1024; --i; )
X+ p[i] = 0;
X+ fread(p, 48*1024, 1, fp);
X+ for (j = 13, i = 48*1024; --i; j++) {
X+ if (i % 1024 == 0) {
X+ printf("\r%5d", i);
X+ fflush(stdout);
X+ }
X+ if (p[i] != (char) j) {
X+ printf("\r%5d failed %d instead of %d\n", i, p[i], (unsigned char) j);
X+ free(p);
X+ return;
X+ }
X+ }
X+ puts(" ok");
X+ free(p);
X }
X }
X
X***************
X*** 615,620
X }
X }
X
X int main()
X
X {
X
X--- 639,664 -----
X }
X }
X
X+ /*
X+ * Test the exit code
X+ *
X+ * Load an exit handler and check buffer flushing.
X+ */
X+
X+ static void handler() { printf("Exit handler called ok\nBuffer flush ok"); }
X+
X+ void exit_test()
X+
X+ {
X+ int atexit();
X+
X+ puts("\nExit Test");
X+ if (atexit(handler) == 0) {
X+ puts("Exit handler not lodged");
X+ exit(1);
X+ }
X+ }
X+
X int main()
X
X {
X***************
X*** 633,637
X uwr_test();
X uawr_test();
X uwrwr_test();
X! return 0;
X }
X
X--- 677,682 -----
X uwr_test();
X uawr_test();
X uwrwr_test();
X! exit_test();
X! exit(0);
X }
END_OF_FILE
if test 2141 -ne `wc -c <'exercise.c.cdif'`; then
echo shar: \"'exercise.c.cdif'\" unpacked with wrong size!
fi
# end of 'exercise.c.cdif'
fi
if test -f 'exit.c.cdif' -a "${1}" != "-c" ; then
echo shar: Will not clobber existing file \"'exit.c.cdif'\"
else
echo shar: Extracting \"'exit.c.cdif'\" \(992 characters\)
sed "s/^X//" >'exit.c.cdif' <<'END_OF_FILE'
X*** /dev/null Tue Sep 5 16:22:51 1989
X--- New/exit.c Tue Sep 5 15:37:23 1989
X***************
X*** 0
X
X--- 1,37 -----
X+ /* e x i t
X+ *
X+ * Exit with stdio wrap up. A scan is made of the exit handler list.
X+ * All non-null pointers will be used to call the named functions.
X+ * Finally the stdio exit handler, _ioflush(), is called, followed by an
X+ * _exit().
X+ *
X+ * Patchlevel 1.0
X+ *
X+ * Edit History:
X+ * 05-Sep-1989 Created.
X+ */
X+
X+ #include "stdiolib.h"
X+
X+ #define MAX_HANDLERS 15 /* maximum number of handlers */
X+
X+ void exit P(()); /* exit coming up */
X+
X+ /* Exit handler list */
X+ static void (*_exit_list[MAX_HANDLERS+1]) P((void)) = {exit};
X+
X+ /* Exit handler list pointer */
X+ void (**_exit_hp) P(()) = &_exit_list[MAX_HANDLERS];
X+
X+ void exit(status)
X+
X+ int status; /* exit status */
X+
X+ {
X+ void _exit P((void)); /* exit */
X+
X+ for ( ; _exit_hp < &_exit_list[MAX_HANDLERS]; )
X+ (*++_exit_hp)();
X+ _ioflush();
X+ _exit(status);
X+ }
END_OF_FILE
if test 992 -ne `wc -c <'exit.c.cdif'`; then
echo shar: \"'exit.c.cdif'\" unpacked with wrong size!
fi
# end of 'exit.c.cdif'
fi
if test -f 'fprintf.c.cdif' -a "${1}" != "-c" ; then
echo shar: Will not clobber existing file \"'fprintf.c.cdif'\"
else
echo shar: Extracting \"'fprintf.c.cdif'\" \(294 characters\)
sed "s/^X//" >'fprintf.c.cdif' <<'END_OF_FILE'
X*** Old/fprintf.c Sun Sep 3 13:56:22 1989
X--- New/fprintf.c Tue Sep 5 15:44:00 1989
X***************
X*** 16,21
X
X /*LINTLIBRARY*/
X /*VARARGS2*/
X
X int fprintf(fp, fmt, va_alist)
X
X
X--- 16,22 -----
X
X /*LINTLIBRARY*/
X /*VARARGS2*/
X+ /*ARGSUSED*/
X
X int fprintf(fp, fmt, va_alist)
X
END_OF_FILE
if test 294 -ne `wc -c <'fprintf.c.cdif'`; then
echo shar: \"'fprintf.c.cdif'\" unpacked with wrong size!
fi
# end of 'fprintf.c.cdif'
fi
if test -f 'fputs.c.cdif' -a "${1}" != "-c" ; then
echo shar: Will not clobber existing file \"'fputs.c.cdif'\"
else
echo shar: Extracting \"'fputs.c.cdif'\" \(2864 characters\)
sed "s/^X//" >'fputs.c.cdif' <<'END_OF_FILE'
X*** Old/fputs.c Mon Sep 4 08:24:36 1989
X--- New/fputs.c Tue Sep 5 15:37:11 1989
X***************
X*** 6,12
X * The function returns EOF on error, otherwise it will return the
X * last character written.
X *
X! * Patchlevel 1.0
X *
X * Edit History:
X * 03-Sep-1989 Accommodate line buffered streams by flushing
X
X--- 6,12 -----
X * The function returns EOF on error, otherwise it will return the
X * last character written.
X *
X! * Patchlevel 1.1
X *
X * Edit History:
X * 05-Sep-1989 Change SETCLEANUP to SETIOFLUSH. Cast buffer
X***************
X*** 9,14
X * Patchlevel 1.0
X *
X * Edit History:
X * 03-Sep-1989 Accommodate line buffered streams by flushing
X * afterwards. Don't even bother looking for '\n'.
X * Call NPUTC() for faster processing of unbuffered
X
X--- 9,16 -----
X * Patchlevel 1.1
X *
X * Edit History:
X+ * 05-Sep-1989 Change SETCLEANUP to SETIOFLUSH. Cast buffer
X+ * pointer to unsigned char *.
X * 03-Sep-1989 Accommodate line buffered streams by flushing
X * afterwards. Don't even bother looking for '\n'.
X * Call NPUTC() for faster processing of unbuffered
X***************
X*** 20,26
X
X /*LINTLIBRARY*/
X
X! int fputs(s, fp)
X
X char *s; /* string */
X FILE *fp; /* stream */
X
X--- 22,28 -----
X
X /*LINTLIBRARY*/
X
X! int fputs(str, fp)
X
X char *str; /* string */
X FILE *fp; /* stream */
X***************
X*** 22,28
X
X int fputs(s, fp)
X
X! char *s; /* string */
X FILE *fp; /* stream */
X
X {
X
X--- 24,30 -----
X
X int fputs(str, fp)
X
X! char *str; /* string */
X FILE *fp; /* stream */
X
X {
X***************
X*** 30,35
X int lastch; /* last character */
X unsigned int bytesleft; /* bytes left in output buffer */
X unsigned char *q; /* output buffer pointer */
X
X /* Check for output buffer */
X if (! HASBUFFER(fp)) {
X
X--- 32,38 -----
X int lastch; /* last character */
X unsigned int bytesleft; /* bytes left in output buffer */
X unsigned char *q; /* output buffer pointer */
X+ unsigned char *s; /* input string */
X
X /* Check for output buffer */
X if (! HASBUFFER(fp)) {
X***************
X*** 35,41
X if (! HASBUFFER(fp)) {
X if (_allocbuf(fp) < 0)
X return EOF;
X! SETCLEANUP();
X }
X
X if (TESTFLAG(fp, _IONBF)) {
X
X--- 38,44 -----
X if (! HASBUFFER(fp)) {
X if (_allocbuf(fp) < 0)
X return EOF;
X! SETIOFLUSH();
X }
X
X /* Cast buffer pointer */
X***************
X*** 38,43
X SETCLEANUP();
X }
X
X if (TESTFLAG(fp, _IONBF)) {
X for (lastch = 0; *s; lastch = (unsigned char) *s++) {
X if (NPUTC(*s, fp) == EOF)
X
X--- 41,50 -----
X SETIOFLUSH();
X }
X
X+ /* Cast buffer pointer */
X+ s = (unsigned char *) str;
X+
X+ /* Do unbuffered cases slowly */
X if (TESTFLAG(fp, _IONBF)) {
X for (lastch = 0; *s; lastch = (unsigned char) *s++) {
X if (NPUTC(*s, fp) == EOF)
END_OF_FILE
if test 2864 -ne `wc -c <'fputs.c.cdif'`; then
echo shar: \"'fputs.c.cdif'\" unpacked with wrong size!
fi
# end of 'fputs.c.cdif'
fi
if test -f 'fread.c.cdif' -a "${1}" != "-c" ; then
echo shar: Will not clobber existing file \"'fread.c.cdif'\"
else
echo shar: Extracting \"'fread.c.cdif'\" \(8048 characters\)
sed "s/^X//" >'fread.c.cdif' <<'END_OF_FILE'
X*** Old/fread.c Mon Sep 4 11:14:06 1989
X--- New/fread.c Mon Sep 4 22:10:24 1989
X***************
X*** 5,11
X * stops reading when the number of items is satisfied or when
X * EOF is encountered.
X *
X! * Patchlevel 1.0
X *
X * Edit History:
X * 04-Sep-1989 Add code for reading very large objects.
X
X--- 5,11 -----
X * stops reading when the number of items is satisfied or when
X * EOF is encountered.
X *
X! * Patchlevel 1.1
X *
X * Edit History:
X * 05-Sep-1989 Include limits.h if INT_MAX undefined so removing
X***************
X*** 8,13
X * Patchlevel 1.0
X *
X * Edit History:
X * 04-Sep-1989 Add code for reading very large objects.
X * 01-Sep-1989 Use Henry Spencer's ideas to speed up code by reading
X * directly into buffer.
X
X--- 8,17 -----
X * Patchlevel 1.1
X *
X * Edit History:
X+ * 05-Sep-1989 Include limits.h if INT_MAX undefined so removing
X+ * need to define MINIX when compiling. Fix void *
X+ * problems by assigning to an unsigned char *.
X+ * Add EINTR repeat code after read().
X * 04-Sep-1989 Add code for reading very large objects.
X * 01-Sep-1989 Use Henry Spencer's ideas to speed up code by reading
X * directly into buffer.
X***************
X*** 20,26
X # define INT_MAX (MAXINT)
X #endif
X
X! #if defined(MINIX) || defined(MSDOS) || defined(__MSDOS__)
X # include <limits.h>
X #endif
X
X
X--- 24,30 -----
X # define INT_MAX (MAXINT)
X #endif
X
X! #if !defined(INT_MAX)
X # include <limits.h>
X #endif
X
X***************
X*** 26,32
X
X /*LINTLIBRARY*/
X
X! int fread(p, size, nitems, fp)
X
X void *p; /* buffer */
X unsigned size; /* size of record */
X
X--- 30,36 -----
X
X /*LINTLIBRARY*/
X
X! int fread(ptr, size, nitems, fp)
X
X void *ptr; /* buffer */
X unsigned size; /* size of record */
X***************
X*** 28,34
X
X int fread(p, size, nitems, fp)
X
X! void *p; /* buffer */
X unsigned size; /* size of record */
X unsigned nitems; /* number of items */
X FILE *fp; /* stream */
X
X--- 32,38 -----
X
X int fread(ptr, size, nitems, fp)
X
X! void *ptr; /* buffer */
X unsigned size; /* size of record */
X unsigned nitems; /* number of items */
X FILE *fp; /* stream */
X***************
X*** 36,41
X {
X int red; /* bytes read in read call */
X int read(); /* read call */
X
X /* Phase 1 --- Amount to read overflows INT_MAX */
X unsigned int burstsize; /* size aligned chunk to read */
X
X--- 40,46 -----
X {
X int red; /* bytes read in read call */
X int read(); /* read call */
X+ unsigned char *p; /* buffer pointer */
X
X /* Phase 1 --- Amount to read overflows INT_MAX */
X unsigned int burstsize; /* size aligned chunk to read */
X***************
X*** 57,62
X if (fp == stdin && TESTFLAG(stdout, _IOLBF))
X (void) fflush(stdout);
X
X /* Read very large objects */
X if ((itemsperburst = INT_MAX / size) == 0) {
X do {
X
X--- 62,70 -----
X if (fp == stdin && TESTFLAG(stdout, _IOLBF))
X (void) fflush(stdout);
X
X+ /* Fix void * casting problems */
X+ p = (unsigned char *) ptr;
X+
X /* Read very large objects */
X if ((itemsperburst = INT_MAX / size) == 0) {
X do {
X***************
X*** 66,72
X if (burstsize > bytesleft)
X burstsize = bytesleft;
X q = GETREADPTR(fp);
X! UNROLL_DO(freadlarge, burstsize, (* ((unsigned char *) p)++ = *q++));
X SETREADPTR(fp, q);
X }
X else {
X
X--- 74,80 -----
X if (burstsize > bytesleft)
X burstsize = bytesleft;
X q = GETREADPTR(fp);
X! UNROLL_DO(freadlarge, burstsize, *p++ = *q++);
X SETREADPTR(fp, q);
X }
X else {
X***************
X*** 72,79
X else {
X if ((burstsize = INT_MAX) > bytesleft)
X burstsize = bytesleft;
X! if ((red = read(fileno(fp), (char *) p, (int) burstsize)) !=
X! burstsize)
X return (nitems-itemsleft);
X p = (void *) ((unsigned char *) p + burstsize);
X }
X
X--- 80,89 -----
X else {
X if ((burstsize = INT_MAX) > bytesleft)
X burstsize = bytesleft;
X! do
X! red = read(fileno(fp), (char *) p, (int) burstsize);
X! while (red == -1 && errno == EINTR);
X! if (red != burstsize)
X return (nitems-itemsleft);
X p += burstsize;
X }
X***************
X*** 75,81
X if ((red = read(fileno(fp), (char *) p, (int) burstsize)) !=
X burstsize)
X return (nitems-itemsleft);
X! p = (void *) ((unsigned char *) p + burstsize);
X }
X } while ((bytesleft -= burstsize) != 0);
X } while (--itemsleft);
X
X--- 85,91 -----
X while (red == -1 && errno == EINTR);
X if (red != burstsize)
X return (nitems-itemsleft);
X! p += burstsize;
X }
X } while ((bytesleft -= burstsize) != 0);
X } while (--itemsleft);
X***************
X*** 93,99
X if ((bytesleft = copybytes%size) != 0)
X bytesleft = size-bytesleft;
X q = GETREADPTR(fp);
X! UNROLL_DO(freadburst, copybytes, (* ((unsigned char *) p)++ = *q++));
X SETREADPTR(fp, q);
X if (bytesleft != 0) {
X if ((red = read(fileno(fp), (char *) p, (int) bytesleft)) !=
X
X--- 103,109 -----
X if ((bytesleft = copybytes%size) != 0)
X bytesleft = size-bytesleft;
X q = GETREADPTR(fp);
X! UNROLL_DO(freadburst, copybytes, *p++ = *q++);
X SETREADPTR(fp, q);
X if (bytesleft != 0) {
X do
X***************
X*** 96,105
X UNROLL_DO(freadburst, copybytes, (* ((unsigned char *) p)++ = *q++));
X SETREADPTR(fp, q);
X if (bytesleft != 0) {
X! if ((red = read(fileno(fp), (char *) p, (int) bytesleft)) !=
X! bytesleft) {
X! if (red == -1)
X! red = 0;
X return (nitems-itemsleft);
X }
X itemsleft--;
X
X--- 106,115 -----
X UNROLL_DO(freadburst, copybytes, *p++ = *q++);
X SETREADPTR(fp, q);
X if (bytesleft != 0) {
X! do
X! red = read(fileno(fp), (char *) p, (int) bytesleft);
X! while (red == -1 && errno == EINTR);
X! if (red != bytesleft)
X return (nitems-itemsleft);
X itemsleft--;
X }
X***************
X*** 101,107
X if (red == -1)
X red = 0;
X return (nitems-itemsleft);
X- }
X itemsleft--;
X }
X }
X
X--- 111,116 -----
X while (red == -1 && errno == EINTR);
X if (red != bytesleft)
X return (nitems-itemsleft);
X itemsleft--;
X }
X }
X***************
X*** 106,113
X }
X }
X else {
X! if ((red = read(fileno(fp), (char *) p, (int) burstsize)) !=
X! burstsize) {
X if (red == -1)
X red = 0;
X return (nitems-itemsleft) + (red/size);
X
X--- 115,124 -----
X }
X }
X else {
X! do
X! red = read(fileno(fp), (char *) p, (int) burstsize);
X! while (red == -1 && errno == EINTR);
X! if (red != burstsize) {
X if (red == -1)
X red = 0;
X return (nitems-itemsleft) + (red/size);
X***************
X*** 112,118
X red = 0;
X return (nitems-itemsleft) + (red/size);
X }
X! p = (void *) ((unsigned char *) p + burstsize);
X itemsleft -= itemsperburst;
X }
X }
X
X--- 123,129 -----
X red = 0;
X return (nitems-itemsleft) + (red/size);
X }
X! p += burstsize;
X itemsleft -= itemsperburst;
X }
X }
X***************
X*** 130,136
X copybytes = bytesleft;
X bytesleft -= copybytes;
X q = GETREADPTR(fp);
X! UNROLL_DO(freadbytes, copybytes, (* ((unsigned char *) p)++ = *q++));
X SETREADPTR(fp, q);
X }
X
X
X--- 141,147 -----
X copybytes = bytesleft;
X bytesleft -= copybytes;
X q = GETREADPTR(fp);
X! UNROLL_DO(freadbytes, copybytes, *p++ = *q++);
X SETREADPTR(fp, q);
X }
X
X***************
X*** 135,143
X }
X
X /* Read rest of object directly to user buffer */
X! if (bytesleft != 0 &&
X! (red = read(fileno(fp), (char *) p, (int) bytesleft)) != -1)
X! bytesleft -= red;
X }
X
X return (nitems-itemsleft) + (bytestotal-bytesleft)/size;
X
X--- 146,158 -----
X }
X
X /* Read rest of object directly to user buffer */
X! if (bytesleft != 0) {
X! do
X! red = read(fileno(fp), (char *) p, (int) bytesleft);
X! while (red == -1 && errno == EINTR);
X! if (red != -1)
X! bytesleft -= red;
X! }
X }
X
X return (nitems-itemsleft) + (bytestotal-bytesleft)/size;
END_OF_FILE
if test 8048 -ne `wc -c <'fread.c.cdif'`; then
echo shar: \"'fread.c.cdif'\" unpacked with wrong size!
fi
# end of 'fread.c.cdif'
fi
if test -f 'fscanf.c.cdif' -a "${1}" != "-c" ; then
echo shar: Will not clobber existing file \"'fscanf.c.cdif'\"
else
echo shar: Extracting \"'fscanf.c.cdif'\" \(290 characters\)
sed "s/^X//" >'fscanf.c.cdif' <<'END_OF_FILE'
X*** Old/fscanf.c Sun Sep 3 13:56:52 1989
X--- New/fscanf.c Tue Sep 5 15:44:28 1989
X***************
X*** 16,21
X
X /*LINTLIBRARY*/
X /*VARARGS2*/
X
X int fscanf(fp, fmt, va_alist)
X
X
X--- 16,22 -----
X
X /*LINTLIBRARY*/
X /*VARARGS2*/
X+ /*ARGSUSED*/
X
X int fscanf(fp, fmt, va_alist)
X
END_OF_FILE
if test 290 -ne `wc -c <'fscanf.c.cdif'`; then
echo shar: \"'fscanf.c.cdif'\" unpacked with wrong size!
fi
# end of 'fscanf.c.cdif'
fi
echo shar: End of archive 2 \(of 5\).
cp /dev/null ark2isdone
MISSING=""
for I in 1 2 3 4 5 ; do
if test ! -f ark${I}isdone ; then
MISSING="${MISSING} ${I}"
fi
done
if test "${MISSING}" = "" ; then
echo You have unpacked all 5 archives.
rm -f ark[1-9]isdone
else
echo You still need to unpack the following archives:
echo " " ${MISSING}
fi
## End of shell archive.
exit 0