home *** CD-ROM | disk | FTP | other *** search
/ The CDPD Public Domain Collection for CDTV 3 / CDPDIII.bin / pd / programming / gnuc / library / rcs / __read.c,v < prev    next >
Encoding:
Text File  |  1992-07-04  |  2.5 KB  |  113 lines

  1. head    1.1;
  2. access;
  3. symbols
  4.     version39-41:1.1;
  5. locks;
  6. comment    @ *  @;
  7.  
  8.  
  9. 1.1
  10. date    92.05.14.19.55.40;    author mwild;    state Exp;
  11. branches;
  12. next    ;
  13.  
  14.  
  15. desc
  16. @lowlevel read for plain files
  17. @
  18.  
  19.  
  20. 1.1
  21. log
  22. @Initial revision
  23. @
  24. text
  25. @/*
  26.  *  This file is part of ixemul.library for the Amiga.
  27.  *  Copyright (C) 1991, 1992  Markus M. Wild
  28.  *
  29.  *  This library is free software; you can redistribute it and/or
  30.  *  modify it under the terms of the GNU Library General Public
  31.  *  License as published by the Free Software Foundation; either
  32.  *  version 2 of the License, or (at your option) any later version.
  33.  *
  34.  *  This library is distributed in the hope that it will be useful,
  35.  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
  36.  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  37.  *  Library General Public License for more details.
  38.  *
  39.  *  You should have received a copy of the GNU Library General Public
  40.  *  License along with this library; if not, write to the Free
  41.  *  Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  42.  *
  43.  *  $Id$
  44.  *
  45.  *  $Log$
  46.  */
  47.  
  48. #define KERNEL
  49. #include "ixemul.h"
  50.  
  51. #ifdef DEBUG
  52. #define DP(a) kprintf a
  53. #else
  54. #define DP(a)
  55. #endif
  56.  
  57. int
  58. __read(struct file *f, char *buf, int len)
  59. {
  60.   int err=errno, res = 0;
  61.   int omask;
  62.  
  63.   /* always return EOF */
  64.   if (HANDLER_NIL(f)) return 0;
  65.  
  66.   omask = syscall (SYS_sigsetmask, ~0);
  67.   __get_file (f);
  68.   /* just to make sure, this packet is really free, it could have
  69.    * been used by a semi-async write, eg. */
  70.   __wait_packet(&f->f_sp);
  71.  
  72.   if (len > 0)
  73.     {
  74.       if (f->f_flags & FNDELAY)
  75.     {
  76.       /* shudder.. this is the most inefficient part of the whole
  77.        * library, but I don't know of another way of doing it... */
  78.       while (res < len)
  79.             {
  80.               SendPacket1(f,__rwport,ACTION_WAIT_CHAR,10);
  81.               __wait_packet(&f->f_sp);
  82.               if (! LastResult(f)) break;
  83.           SendPacket3(f,__rwport,ACTION_READ,f->f_fh->fh_Arg1,(long)buf,1);
  84.           __wait_packet(&f->f_sp);
  85.           if (LastResult(f) != 1) 
  86.         {
  87.           err = __ioerr_to_errno(LastError(f));
  88.           /* if there really was no character to read, we should
  89.            * have escaped already at the 'if WaitForChar' line */
  90.           if (!res) res = -1;
  91.           break;
  92.         }
  93.           buf++;
  94.           res++;
  95.         }
  96.     }      
  97.       else
  98.     {
  99.       SendPacket3(f,__rwport,ACTION_READ,f->f_fh->fh_Arg1,(long)buf,len);
  100.       __wait_packet(&f->f_sp);
  101.       res = LastResult(f);
  102.       if (res == -1) err = __ioerr_to_errno(LastError(f));
  103.     }
  104.    }
  105.  
  106.   LastResult(f) = 0;
  107.   __release_file (f);
  108.   syscall (SYS_sigsetmask, omask);
  109.   errno = err;
  110.   return res;
  111. }
  112. @
  113.