Date: Mon, 17 Jun 1996 21:31:38 +0400 (MSD) From: "Alexander V. Lukyanov" Message-Id: <199606171731.VAA11558@video.yars.free.net> To: djgpp-workers AT delorie DOT com Subject: changed filbuf.c and flsbuf.c I have slightly rearranged those functions and I have to post them entirely since patches are larger. #!/bin/sh # This is a shell archive (produced by GNU shar 4.0). # To extract the files from this archive, save it to some FILE, remove # everything before the `!/bin/sh' line above, then type `sh FILE'. # # Made on 1996-06-17 20:21 MSK by . # Source directory was `/home/lav/ftp/djgpp'. # # Existing files will *not* be overwritten unless `-c' is specified. # # This shar contains: # length mode name # ------ ---------- ------------------------------------------ # 1585 -rw-r--r-- src/libc/ansi/stdio/filbuf.c # 2066 -rw-r--r-- src/libc/ansi/stdio/flsbuf.c # touch -am 1231235999 $$.touch >/dev/null 2>&1 if test ! -f 1231235999 && test -f $$.touch; then shar_touch=touch else shar_touch=: echo 'WARNING: not restoring timestamps' fi rm -f 1231235999 $$.touch # # ============= src/libc/ansi/stdio/filbuf.c ============== if test ! -d 'src'; then echo 'x - creating directory src' mkdir 'src' fi if test ! -d 'src/libc'; then echo 'x - creating directory src/libc' mkdir 'src/libc' fi if test ! -d 'src/libc/ansi'; then echo 'x - creating directory src/libc/ansi' mkdir 'src/libc/ansi' fi if test ! -d 'src/libc/ansi/stdio'; then echo 'x - creating directory src/libc/ansi/stdio' mkdir 'src/libc/ansi/stdio' fi if test -f 'src/libc/ansi/stdio/filbuf.c' && test X"$1" != X"-c"; then echo 'x - skipping src/libc/ansi/stdio/filbuf.c (File already exists)' else echo 'x - extracting src/libc/ansi/stdio/filbuf.c (text)' sed 's/^X//' << 'SHAR_EOF' > 'src/libc/ansi/stdio/filbuf.c' && /* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */ #include #include #include #include #include #include #include #include #include #include X int _filbuf(FILE *f) { X int size; X char c; X X if (f->_flag & _IORW) X f->_flag |= _IOREAD; X X if ((f->_flag&_IOREAD) == 0) X return EOF; X if (f->_flag&(_IOSTRG|_IOEOF)) X return EOF; X f->_flag &= ~_IOUNGETC; X X if (f->_base==NULL && (f->_flag&_IONBF)==0) { X size = _go32_info_block.size_of_transfer_buffer; X if ((f->_base = malloc(size)) == NULL) X { X f->_flag |= _IONBF; X f->_flag &= ~(_IOFBF|_IOLBF); X } X else X { X f->_flag |= _IOMYBUF; X f->_bufsiz = size; X } X } X X if (f->_flag&_IONBF) X f->_base = &c; X X if (f == stdin) { X if (stdout->_flag&_IOLBF) X fflush(stdout); X if (stderr->_flag&_IOLBF) X fflush(stderr); X } X f->_cnt = _read(fileno(f), f->_base, X f->_flag & _IONBF ? 1 : f->_bufsiz); X if(__is_text_file(f) && f->_cnt>0) X { X /* truncate text file at Ctrl-Z */ X char *cz=memchr(f->_base, 0x1A, f->_cnt); X if(cz) X f->_cnt = cz - f->_base; X } X f->_ptr = f->_base; X if (f->_flag & _IONBF) X f->_base = NULL; X if (--f->_cnt < 0) { X if (f->_cnt == -1) { X f->_flag |= _IOEOF; X if (f->_flag & _IORW) X f->_flag &= ~_IOREAD; X } else X f->_flag |= _IOERR; X f->_cnt = 0; X return EOF; X } X return *f->_ptr++ & 0377; } SHAR_EOF $shar_touch -am 0614195296 'src/libc/ansi/stdio/filbuf.c' && chmod 0644 'src/libc/ansi/stdio/filbuf.c' || echo 'restore of src/libc/ansi/stdio/filbuf.c failed' shar_count="`wc -c < 'src/libc/ansi/stdio/filbuf.c'`" test 1585 -eq "$shar_count" || echo "src/libc/ansi/stdio/filbuf.c: original size 1585, current size $shar_count" fi # ============= src/libc/ansi/stdio/flsbuf.c ============== if test -f 'src/libc/ansi/stdio/flsbuf.c' && test X"$1" != X"-c"; then echo 'x - skipping src/libc/ansi/stdio/flsbuf.c (File already exists)' else echo 'x - extracting src/libc/ansi/stdio/flsbuf.c (text)' sed 's/^X//' << 'SHAR_EOF' > 'src/libc/ansi/stdio/flsbuf.c' && /* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */ #include #include #include #include #include #include #include #include X int _flsbuf(int c, FILE *f) { X char *base; X int n, rn; X char c1; X int size; X X if (f->_flag & _IORW) X { X f->_flag |= _IOWRT; X f->_flag &= ~(_IOEOF|_IOREAD); X } X X if ((f->_flag&_IOWRT)==0) X return EOF; X X /* if the buffer is not yet allocated, allocate it */ X if ((base = f->_base) == NULL && (f->_flag & _IONBF) == 0) X { X size = _go32_info_block.size_of_transfer_buffer; X if ((f->_base = base = malloc (size)) == NULL) X { X f->_flag |= _IONBF; X f->_flag &= ~(_IOFBF|_IOLBF); X } X else X { X f->_flag |= _IOMYBUF; X f->_cnt = f->_bufsiz = size; X f->_ptr = base; X rn = 0; X if (f == stdout && isatty (fileno (stdout))) X f->_flag |= _IOLBF; X } X } X X if (f->_flag & _IOLBF) X { X /* in line-buffering mode we get here on each character */ X *f->_ptr++ = c; X rn = f->_ptr - base; X if (c == '\n' || rn >= f->_bufsiz) X { X /* time for real flush */ X f->_ptr = base; X f->_cnt = 0; X } X else X { X /* we got here because _cnt is wrong, so fix it */ X /* Negative _cnt causes all output functions X to call _flsbuf for each character, thus realizing line-buffering */ X f->_cnt = -rn; X return c; X } X } X else if (f->_flag & _IONBF) X { X c1 = c; X rn = 1; X base = &c1; X f->_cnt = 0; X } X else /* _IOFBF */ X { X rn = f->_ptr - base; X f->_ptr = base; X f->_cnt = f->_bufsiz; X } X while (rn > 0) X { X n = _write(fileno(f), base, rn); X if (n <= 0) X { X f->_flag |= _IOERR; X return EOF; X } X rn -= n; X base += n; X } X if ((f->_flag&(_IOLBF|_IONBF)) == 0) X { X f->_cnt--; X *f->_ptr++ = c; X } X return c; } SHAR_EOF $shar_touch -am 0615132396 'src/libc/ansi/stdio/flsbuf.c' && chmod 0644 'src/libc/ansi/stdio/flsbuf.c' || echo 'restore of src/libc/ansi/stdio/flsbuf.c failed' shar_count="`wc -c < 'src/libc/ansi/stdio/flsbuf.c'`" test 2066 -eq "$shar_count" || echo "src/libc/ansi/stdio/flsbuf.c: original size 2066, current size $shar_count" fi exit 0