Subversion Repositories Kolibri OS

Rev

Rev 4872 | Rev 4921 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | RSS feed

  1. /* Reentrant version of close system call.  */
  2.  
  3. #include <reent.h>
  4. #include <unistd.h>
  5. #include <_syslist.h>
  6. #include <errno.h>
  7.  
  8. /* Some targets provides their own versions of this functions.  Those
  9.    targets should define REENTRANT_SYSCALLS_PROVIDED in TARGET_CFLAGS.  */
  10.  
  11. #ifdef _REENT_ONLY
  12. #ifndef REENTRANT_SYSCALLS_PROVIDED
  13. #define REENTRANT_SYSCALLS_PROVIDED
  14. #endif
  15. #endif
  16.  
  17. #ifndef REENTRANT_SYSCALLS_PROVIDED
  18.  
  19.  
  20. /*
  21. FUNCTION
  22.         <<_close_r>>---Reentrant version of close
  23.  
  24. INDEX
  25.         _close_r
  26.  
  27. ANSI_SYNOPSIS
  28.         #include <reent.h>
  29.         int _close_r(struct _reent *<[ptr]>, int <[fd]>);
  30.  
  31. TRAD_SYNOPSIS
  32.         #include <reent.h>
  33.         int _close_r(<[ptr]>, <[fd]>)
  34.         struct _reent *<[ptr]>;
  35.         int <[fd]>;
  36.  
  37. DESCRIPTION
  38.         This is a reentrant version of <<close>>.  It
  39.         takes a pointer to the global data block, which holds
  40.         <<errno>>.
  41. */
  42. extern unsigned  __NFiles;
  43.  
  44.  
  45. #define __handle_check( __h, __r )                \
  46.         if( (__h) < 0  ||  (__h) > __NFiles ) {   \
  47.            ptr->_errno =  EBADF ;                 \
  48.            return( __r );                         \
  49.         }
  50.  
  51.  
  52.  
  53.  
  54. int
  55. _DEFUN(_close_r, (ptr, fd),
  56.      struct _reent *ptr _AND
  57.      int fd)
  58. {
  59.     int ret;
  60.     int h;
  61.  
  62.     __file_handle *fh;
  63.  
  64.     __handle_check( fd, -1 );
  65.  
  66.     fh = (__file_handle*) __getOSHandle( fd );
  67.  
  68.     if( fd > STDERR_FILENO )
  69.     {
  70.         _free_r(ptr, fh->name);
  71.         _free_r(ptr, fh);
  72.         __freePOSIXHandle( fd );
  73.         __SetIOMode_nogrow( fd, 0 );
  74.     }
  75.  
  76.     return 0;
  77. }
  78.  
  79.  
  80. int
  81. _DEFUN( close,(fd),
  82.      int fd)
  83. {
  84.     return _close_r(_REENT, fd);
  85. }
  86.  
  87. #endif /* ! defined (REENTRANT_SYSCALLS_PROVIDED) */
  88.