1 /* Reentrant versions of open system call. */
2 
3 #include <reent.h>
4 #include <unistd.h>
5 #include <fcntl.h>
6 #include <_syslist.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 /* We use the errno variable used by the system dependent layer.  */
20 #undef errno
21 extern int errno;
22 
23 /*
24 FUNCTION
25 	<<_open_r>>---Reentrant version of open
26 
27 INDEX
28 	_open_r
29 
30 ANSI_SYNOPSIS
31 	#include <reent.h>
32 	int _open_r(struct _reent *<[ptr]>,
33 		    const char *<[file]>, int <[flags]>, int <[mode]>);
34 
35 TRAD_SYNOPSIS
36 	#include <reent.h>
37 	int _open_r(<[ptr]>, <[file]>, <[flags]>, <[mode]>)
38 	struct _reent *<[ptr]>;
39 	char *<[file]>;
40 	int <[flags]>;
41 	int <[mode]>;
42 
43 DESCRIPTION
44 	This is a reentrant version of <<open>>.  It
45 	takes a pointer to the global data block, which holds
46 	<<errno>>.
47 */
48 
49 int
50 _DEFUN (_open_r, (ptr, file, flags, mode),
51      struct _reent *ptr _AND
52      _CONST char *file _AND
53      int flags _AND
54      int mode)
55 {
56   int ret;
57 
58   errno = 0;
59   if ((ret = _open (file, flags, mode)) == -1 && errno != 0)
60     ptr->_errno = errno;
61   return ret;
62 }
63 
64 
65 #endif /* ! defined (REENTRANT_SYSCALLS_PROVIDED) */
66