home *** CD-ROM | disk | FTP | other *** search
/ The CDPD Public Domain Collection for CDTV 3 / CDPDIII.bin / pd / programming / gnuc / library / rcs / __swrite.c,v < prev    next >
Encoding:
Text File  |  1992-07-04  |  2.0 KB  |  88 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 synchronous write function 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. int
  52. __sync_write(struct file *f, char *buf, int len)
  53. {
  54.   int err=errno, res = 0;
  55.   int omask;
  56.  
  57.   if (HANDLER_NIL(f)) return len;
  58.  
  59.   omask = syscall (SYS_sigsetmask, ~0);
  60.   __get_file (f);
  61.   /* this allows intermixing different modes.. we wouldn't need to
  62.    * wait, if we knew the user only used FSYNC-mode */
  63.   __wait_packet(&f->f_sp);
  64.  
  65.   if (len > 0)
  66.     {
  67.       /* full append-mode means, before each write do an explicit
  68.        * seek to eof */
  69.       if (f->f_flags & FAPPEND)
  70.     {
  71.       SendPacket3(f,__rwport,ACTION_SEEK,f->f_fh->fh_Arg1,0,OFFSET_END);
  72.           __wait_packet(&f->f_sp);
  73.     }
  74.  
  75.       SendPacket3(f,__rwport,ACTION_WRITE,f->f_fh->fh_Arg1,(long)buf,len);
  76.       __wait_packet(&f->f_sp);
  77.       res = LastResult(f);
  78.       if (res == -1) err = __ioerr_to_errno(LastError(f));
  79.     }
  80.  
  81.   LastResult(f) = 0;
  82.   __release_file (f);
  83.   syscall (SYS_sigsetmask, omask);
  84.   errno = err;
  85.   return res;
  86. }
  87. @
  88.