home *** CD-ROM | disk | FTP | other *** search
/ RISC DISC 1 / RISC_DISC_1.iso / pd_share / code / unixlib / !UnixLib / src / unix / c / write < prev   
Encoding:
Text File  |  1994-09-30  |  912 b   |  54 lines

  1. static char sccs_id[] = "@(#) write.c 1.2 " __DATE__ " HJR";
  2.  
  3. /* write.c (c) Copyright 1990 H.Rogers */
  4.  
  5. #include <errno.h>
  6.  
  7. #include "fcntl.h"
  8.  
  9. #include "sys/dev.h"
  10. #include "sys/unix.h"
  11.  
  12. /*
  13.    #include <stdio.h>
  14.    #include "sys/os.h"
  15.    int debug = 0;
  16.  */
  17.  
  18. int
  19. write (int fd, register void *data, register int nbyte)
  20. {
  21.   register struct file *f;
  22.  
  23. /*
  24.    if (!debug && os_fopen(0x80,"debug",&debug)) debug = 0;
  25.    if (debug)
  26.    {
  27.    char buf[128];
  28.    int i;
  29.  
  30.    i = sprintf(buf,"write(%d,%x,%d)\n",fd,data,nbyte);
  31.    os_fwrite(debug,buf,i,0);
  32.    }
  33.  */
  34.  
  35.   if (BADF (fd))
  36.     {
  37.       errno = EBADF;
  38.       return (-1);
  39.     }
  40.  
  41.   f = __u->file + fd;
  42.  
  43.   if ((f->oflag & O_OMASK) == O_RDONLY)
  44.     {
  45.       errno = EBADF;
  46.       return (-1);
  47.     }
  48.  
  49.   if (f->oflag & O_APPEND)
  50.     (*(__dev[major (f->dev)].lseek)) (minor (f->dev), 0, 2, f);
  51.  
  52.   return ((*(__dev[major (f->dev)].write)) (minor (f->dev), data, nbyte, f));
  53. }
  54.