1 /* Copyright (C) 1991 Free Software Foundation, Inc.
2 This file is part of the GNU C Library.
4 The GNU C Library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Library General Public License as
6 published by the Free Software Foundation; either version 2 of the
7 License, or (at your option) any later version.
9 The GNU C Library is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 Library General Public License for more details.
14 You should have received a copy of the GNU Library General Public
15 License along with the GNU C Library; see the file COPYING.LIB. If
16 not, write to the Free Software Foundation, Inc., 675 Mass Ave,
17 Cambridge, MA 02139, USA. */
25 /* Open FILE with access OFLAG. If OFLAG includes O_CREAT,
26 a third argument is the file protection. */
28 DEFUN(__open
, (file
, oflag
), CONST
char *file AND
int oflag DOTS
)
36 switch (oflag
& O_ACCMODE
)
45 fl
= FS_LOOKUP_READ
| FS_LOOKUP_WRITE
;
55 va_start (arg
, oflag
);
56 mode
= va_arg (arg
, mode_t
);
58 fl
|= FS_LOOKUP_CREATE
;
64 fl
|= FS_LOOKUP_NDELAY
;
66 fl
|= FS_LOOKUP_APPEND
;
68 fl
|= FS_LOOKUP_CREATE
;
70 fl
|= FS_LOOKUP_TRUNC
;
74 __mutex_lock (&_hurd_dtable
.lock
);
78 __mutex_unlock (&_hurd_dtable
.lock
);
82 port
= __hurd_path_lookup (file
, fl
, mode
);
84 if (port
!= MACH_PORT_NULL
&& !_hurd_hasctty
&& !(oflag
& O_NOCTTY
))
89 err
= __io_stat (port
, &stb
);
91 err
= __term_getctty (port
, &cttyid
);
94 err
= __proc_set_ctty (_hurd_proc
, cttyid
);
95 __mach_port_deallocate (__mach_task_self (), cttyid
);
98 _hurd_dtable
.d
[fd
].isctty
= 1;
100 _hurd_ctty_fstype
= stb
.stb_fstype
;
101 _hurd_ctty_fsid
= stb
.stb_fsid
;
102 _hurd_ctty_fileid
= stb
.stb_file_id
;
107 _hurd_dtable
.d
[fd
].server
= port
;
108 __mutex_unlock (&_hurd_dtable
.lock
);
109 return port
== MACH_PORT_NULL
? -1 : fd
;