Subversion Repositories Kolibri OS

Rev

Rev 4874 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 4874 Rev 4921
Line 1... Line 1...
1
/* Reentrant version of close system call.  */
1
/* Reentrant version of close system call.  */
Line 2... Line 2...
2
 
2
 
3
#include 
3
#include 
4
#include 
4
#include 
5
#include <_syslist.h>
-
 
Line 6... Line 5...
6
#include 
5
#include <_syslist.h>
7
 
6
 
Line 8... Line 7...
8
/* Some targets provides their own versions of this functions.  Those
7
/* Some targets provides their own versions of this functions.  Those
Line 14... Line 13...
14
#endif
13
#endif
15
#endif
14
#endif
Line 16... Line 15...
16
 
15
 
Line -... Line 16...
-
 
16
#ifndef REENTRANT_SYSCALLS_PROVIDED
-
 
17
 
-
 
18
/* We use the errno variable used by the system dependent layer.  */
Line 17... Line 19...
17
#ifndef REENTRANT_SYSCALLS_PROVIDED
19
#undef errno
18
 
20
extern int errno;
19
 
21
 
Line 37... Line 39...
37
DESCRIPTION
39
DESCRIPTION
38
	This is a reentrant version of <>.  It
40
	This is a reentrant version of <>.  It
39
	takes a pointer to the global data block, which holds
41
	takes a pointer to the global data block, which holds
40
	<>.
42
	<>.
41
*/
43
*/
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
 
-
 
Line 53... Line 44...
53
 
44
 
54
int
45
int
55
_DEFUN(_close_r, (ptr, fd),
46
_close_r (ptr, fd)
56
     struct _reent *ptr _AND
47
     struct _reent *ptr;
57
     int fd)
48
     int fd;
58
{
49
{
59
    int ret;
-
 
60
    int h;
-
 
61
 
-
 
62
    __file_handle *fh;
-
 
63
 
-
 
64
    __handle_check( fd, -1 );
-
 
65
 
-
 
Line 66... Line -...
66
    fh = (__file_handle*) __getOSHandle( fd );
-
 
67
 
50
  int ret;
68
    if( fd > STDERR_FILENO )
51
 
69
    {
52
  errno = 0;
70
        _free_r(ptr, fh->name);
-
 
71
        _free_r(ptr, fh);
-
 
72
        __freePOSIXHandle( fd );
-
 
73
        __SetIOMode_nogrow( fd, 0 );
-
 
74
    }
53
  if ((ret = _close (fd)) == -1 && errno != 0)
75
 
-
 
76
    return 0;
-
 
77
}
-
 
78
 
-
 
79
 
-
 
80
int
-
 
81
_DEFUN( close,(fd),
-
 
82
     int fd)
-
 
83
{
54
    ptr->_errno = errno;
Line 84... Line 55...
84
    return _close_r(_REENT, fd);
55
  return ret;