home *** CD-ROM | disk | FTP | other *** search
/ Atari FTP / ATARI_FTP_0693.zip / ATARI_FTP_0693 / Mint / mntlib25.zoo / write.c < prev    next >
C/C++ Source or Header  |  1992-09-05  |  1KB  |  66 lines

  1. /*
  2.  * _write: like write, but takes a long instead of an int. Written by
  3.  * Eric R. Smith and placed in the public domain.
  4.  */
  5.  
  6. /* BUG: under TOS, CRMOD doesn't work unless RAW is on or SIGINT is
  7.  * being caught
  8.  */
  9.  
  10. #include <osbind.h>
  11. #include <fcntl.h>
  12. #include <ioctl.h>
  13. #include <errno.h>
  14. #include <unistd.h>
  15. #include <signal.h>
  16. #include "lib.h"
  17.  
  18. extern __Sigfunc _sig_handler[]; /* TOS fakes for signal handling */
  19.  
  20. long
  21. _write(fd, buf, size)
  22.     int fd;
  23.     const void *buf;
  24.     unsigned long size;
  25. {
  26.     unsigned char c, *foo;
  27.     unsigned flags;
  28.     long r;
  29.     extern int __mint;
  30.  
  31.     if (__mint == 0 && isatty(fd)) {
  32.         r = __OPEN_INDEX(fd);
  33.         if (r < 0 || r >= __NHANDLES)
  34.             r = __NHANDLES - 1;
  35.         flags = __open_stat[r].flags;
  36.         if ((flags & RAW) || _sig_handler[SIGINT] != SIG_DFL) {
  37.             foo = (unsigned char *) buf;
  38.             r = size;
  39.             while (r-- > 0) {
  40.                 c = *foo++;
  41.                 if (c == '\n' && (flags & CRMOD))
  42.                     _console_write_byte(fd, '\r');
  43.                 _console_write_byte(fd, c);
  44.             }
  45.             return size;
  46.         }
  47.     }
  48.  
  49.     r = Fwrite(fd, size, buf);
  50.     if (r < 0) {
  51.         errno = (int) -r;
  52.         return -1;
  53.     }
  54.  
  55.     return r;
  56. }
  57.  
  58. int
  59. write(fd, buf, size)
  60.     int fd;
  61.     const void *buf;
  62.     unsigned size;
  63. {
  64.     return (int) _write(fd, buf, (unsigned long)size);
  65. }
  66.