2 Copyright © 1995-2001, The AROS Development Team. All rights reserved.
15 /*****************************************************************************
26 Perform operation specified in cmd on the file descriptor fd.
27 Some operations require additional arguments, in this case they
28 follow the cmd argument. The following operations are available:
30 F_DUPFD (int) - Duplicate file descriptor fd as the lowest numbered
31 file descriptor greater or equal to the operation
34 F_GETFD (void) - Read the file descriptor flags
36 F_SETFD (int) - Set the file descriptor flags to value given in
37 the operation argument
39 F_GETFL (void) - Read the file status flags
41 F_SETFL (int) - Set the file status flags to value given in the
44 File descriptor flags are zero or more ORed constants:
46 FD_CLOEXEC - File descriptor will be closed during execve()
48 File descriptor flags are not copied during duplication of file
51 File status flags are the flags given as mode parameter to open()
52 function call. You can change only a few file status flags in opened
53 file descriptor: O_NONBLOCK, O_APPEND and O_ASYNC. Any other file
54 status flags passed in F_SETFL argument will be ignored.
56 All duplicated file descriptors share the same set of file status
60 fd - File descriptor to perform operation on.
61 cmd - Operation specifier.
62 ... - Operation arguments.
65 The return value of the function depends on the performed operation:
67 F_DUPFD - New duplicated file descriptor
69 F_GETFD - File descriptor flags
73 F_GETFL - File status flags
75 F_SETFL - 0 on success, -1 on error. In case of error a global errno
89 ******************************************************************************/
91 fdesc
*desc
= __getfdesc(fd
);
107 arg
= va_arg(ap
, int);
111 FIXME: FD_CLOEXEC must be off on the copy, once this flag
112 is supported (related to F_GETFD and F_SETFD).
115 return dup2(fd
, __getfirstfd(arg
));
118 return desc
->fdflags
;
126 arg
= va_arg(ap
, int);
134 return desc
->fcb
->flags
& (O_NONBLOCK
|O_APPEND
|O_ASYNC
);
140 int oldmode
= __oflags2amode(desc
->fcb
->flags
& ~(O_NONBLOCK
|O_APPEND
|O_ASYNC
));
143 arg
= va_arg(ap
, int);
146 arg
&= (O_NONBLOCK
|O_APPEND
|O_ASYNC
);
148 if (ChangeMode(CHANGE_FH
, desc
->fcb
->fh
, oldmode
| __oflags2amode(arg
)) == DOSTRUE
)
150 desc
->fcb
->flags
&= ~(O_NONBLOCK
|O_APPEND
|O_ASYNC
);
151 desc
->fcb
->flags
|= arg
;
155 errno
= IoErr2errno(IoErr());