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

  1. head    1.2;
  2. access;
  3. symbols
  4.     version39-41:1.1;
  5. locks;
  6. comment    @ *  @;
  7.  
  8.  
  9. 1.2
  10. date    92.08.09.20.40.39;    author amiga;    state Exp;
  11. branches;
  12. next    1.1;
  13.  
  14. 1.1
  15. date    92.05.14.19.55.40;    author mwild;    state Exp;
  16. branches;
  17. next    ;
  18.  
  19.  
  20. desc
  21. @lowlevel asynchronous write function for plain files
  22. @
  23.  
  24.  
  25. 1.2
  26. log
  27. @add a cast to get rid of a warning
  28. @
  29. text
  30. @/*
  31.  *  This file is part of ixemul.library for the Amiga.
  32.  *  Copyright (C) 1991, 1992  Markus M. Wild
  33.  *
  34.  *  This library is free software; you can redistribute it and/or
  35.  *  modify it under the terms of the GNU Library General Public
  36.  *  License as published by the Free Software Foundation; either
  37.  *  version 2 of the License, or (at your option) any later version.
  38.  *
  39.  *  This library is distributed in the hope that it will be useful,
  40.  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
  41.  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  42.  *  Library General Public License for more details.
  43.  *
  44.  *  You should have received a copy of the GNU Library General Public
  45.  *  License along with this library; if not, write to the Free
  46.  *  Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  47.  *
  48.  *  $Id: __write.c,v 1.1 1992/05/14 19:55:40 mwild Exp $
  49.  *
  50.  *  $Log: __write.c,v $
  51.  *  Revision 1.1  1992/05/14  19:55:40  mwild
  52.  *  Initial revision
  53.  *
  54.  */
  55.  
  56. #define KERNEL
  57. #include "ixemul.h"
  58.  
  59. #undef DEBUG
  60.  
  61. #ifdef DEBUG
  62. #define DP(a) kprintf a
  63. #else
  64. #define DP(a)
  65. #endif
  66.  
  67. int
  68. __write(struct file *f, char *buf, int len)
  69. {
  70.   int err=errno, res = 0;
  71.   int omask;
  72.  
  73.   if (HANDLER_NIL(f)) return len;
  74.  
  75.   omask = syscall (SYS_sigsetmask, ~0);
  76.   __get_file (f);
  77.   /* get results of last call */
  78.   __wait_packet(&f->f_sp);
  79.   res = LastResult(f);
  80.   if (res == -1)
  81.     err = __ioerr_to_errno(LastError(f));
  82.   else
  83.     {
  84.       /* we have no way of telling, whether the last written number
  85.        * of characters was correct or not, we just say, if it wasn't
  86.        * an error (res == -1), than it's ok to continue writing to this
  87.        * file. We have to return 'len' instead of 'res', because the 
  88.        * user normally expects to say "while write(fd,buf,len)==len"
  89.        * as a check whether there was an error with write() or not */
  90.  
  91.       res = len;
  92.  
  93.       if (len > 0)
  94.         {
  95.           /* right append-mode means, before each write do an explicit
  96.            * seek to eof */
  97.           if (f->f_flags & FAPPEND) 
  98.         {
  99.           SendPacket3(f,__rwport,ACTION_SEEK,f->f_fh->fh_Arg1,0,OFFSET_END);
  100.               __wait_packet(&f->f_sp);
  101.         }
  102.  
  103.       /* We need to save a copy of this buffer in our local buffer,
  104.        * because the caller is free to change buf after this function
  105.        * returns. */
  106.       if (len > f->f_async_len) 
  107.         {
  108. DP(("asl=%ld,l=%ld,b=$%lx ",f->f_async_len, len,f->f_async_buf));
  109.           f->f_async_len = len*2;    /* don't waste too much memory */
  110.           if (! (f->f_async_buf = (char *)krealloc (f->f_async_buf, f->f_async_len)))
  111.             {
  112.           f->f_async_len = 0;
  113.           /* in that case resort to sync write */
  114.           __release_file (f);
  115.           syscall (SYS_sigsetmask, omask);
  116.           errno = err;
  117.           return __sync_write (f, buf, len);
  118.         }
  119.         }
  120.       bcopy (buf, f->f_async_buf, len);
  121.           SendPacket3(f,__rwport,ACTION_WRITE,f->f_fh->fh_Arg1,(long)f->f_async_buf,len);
  122.         }
  123.     }
  124.  
  125.   __release_file (f);
  126.   syscall (SYS_sigsetmask, omask);
  127.   errno = err;
  128.   return res;
  129. }
  130. @
  131.  
  132.  
  133. 1.1
  134. log
  135. @Initial revision
  136. @
  137. text
  138. @d19 1
  139. a19 1
  140.  *  $Id$
  141. d21 4
  142. a24 1
  143.  *  $Log$
  144. d81 1
  145. a81 1
  146.           if (! (f->f_async_buf = krealloc (f->f_async_buf, f->f_async_len)))
  147. @
  148.