home *** CD-ROM | disk | FTP | other *** search
/ Aminet 18 / aminetcdnumber181997.iso / Aminet / misc / emu / AROSdev.lha / AROS / compiler / clib / close.c < prev    next >
Encoding:
C/C++ Source or Header  |  1997-01-15  |  1.1 KB  |  69 lines

  1. /*
  2.     (C) 1995-96 AROS - The Amiga Replacement OS
  3.     $Id: close.c,v 1.1 1997/01/15 17:48:49 digulla Exp $
  4.  
  5.     Desc: ANSI C function close()
  6.     Lang: english
  7. */
  8. #define AROS_ALMOST_COMPATIBLE
  9. #include <proto/exec.h>
  10. #include <proto/dos.h>
  11. #include <errno.h>
  12. #include "__stdio.h"
  13.  
  14. /*****************************************************************************
  15.  
  16.     NAME */
  17. #include <unistd.h>
  18.  
  19.     int close (
  20.  
  21. /*  SYNOPSIS */
  22.     int fd)
  23.  
  24. /*  FUNCTION
  25.     Closes an open file. If this is the last file descriptor
  26.     associated with this file, then all allocated resources
  27.     are freed, too.
  28.  
  29.     INPUTS
  30.     fd - The result of a successful open()
  31.  
  32.     RESULT
  33.     -1 for error or zero on success.
  34.  
  35.     NOTES
  36.  
  37.     EXAMPLE
  38.  
  39.     BUGS
  40.  
  41.     SEE ALSO
  42.     open(), read(), write(), fopen()
  43.  
  44.     INTERNALS
  45.  
  46.     HISTORY
  47.     15.01.97 digulla created
  48.  
  49. ******************************************************************************/
  50. {
  51.     FILENODE * fn;
  52.  
  53.     ForeachNode (&__stdio_files,fn)
  54.     {
  55.     if (fn->fd == fd)
  56.     {
  57.         Remove ((struct Node *)fn);
  58.         Close (fn->File.fh);
  59.         FreeMem (fn, sizeof (FILENODE));
  60.  
  61.         return 0;
  62.     }
  63.     }
  64.  
  65.     errno = EBADF;
  66.     return -1;
  67. } /* close */
  68.  
  69.