2 Copyright © 1995-2011, The AROS Development Team. All rights reserved.
15 /*****************************************************************************
28 Perform operation specified in cmd on the file descriptor fd.
29 Some operations require additional arguments, in this case they
30 follow the cmd argument. The following operations are available:
32 F_DUPFD (int) - Duplicate file descriptor fd as the lowest numbered
33 file descriptor greater or equal to the operation
36 F_GETFD (void) - Read the file descriptor flags
38 F_SETFD (int) - Set the file descriptor flags to value given in
39 the operation argument
41 F_GETFL (void) - Read the file status flags
43 F_SETFL (int) - Set the file status flags to value given in the
46 File descriptor flags are zero or more ORed constants:
48 FD_CLOEXEC - File descriptor will be closed during execve()
50 File descriptor flags are not copied during duplication of file
53 File status flags are the flags given as mode parameter to open()
54 function call. You can change only a few file status flags in opened
55 file descriptor: O_NONBLOCK, O_APPEND and O_ASYNC. Any other file
56 status flags passed in F_SETFL argument will be ignored.
58 All duplicated file descriptors share the same set of file status
62 fd - File descriptor to perform operation on.
63 cmd - Operation specifier.
64 ... - Operation arguments.
67 The return value of the function depends on the performed operation:
69 F_DUPFD - New duplicated file descriptor
71 F_GETFD - File descriptor flags
75 F_GETFL - File status flags
77 F_SETFL - 0 on success, -1 on error. In case of error a global errno
91 ******************************************************************************/
93 fdesc
*desc
= __getfdesc(fd
);
109 arg
= va_arg(ap
, int);
113 FIXME: FD_CLOEXEC must be off on the copy, once this flag
114 is supported (related to F_GETFD and F_SETFD).
117 return dup2(fd
, __getfirstfd(arg
));
120 return desc
->fdflags
;
128 arg
= va_arg(ap
, int);
136 return desc
->fcb
->flags
& (O_NONBLOCK
|O_APPEND
|O_ASYNC
);
142 int oldmode
= __oflags2amode(desc
->fcb
->flags
& ~(O_NONBLOCK
|O_APPEND
|O_ASYNC
));
145 arg
= va_arg(ap
, int);
148 arg
&= (O_NONBLOCK
|O_APPEND
|O_ASYNC
);
150 if (ChangeMode(CHANGE_FH
, desc
->fcb
->fh
, oldmode
| __oflags2amode(arg
)) == DOSTRUE
)
152 desc
->fcb
->flags
&= ~(O_NONBLOCK
|O_APPEND
|O_ASYNC
);
153 desc
->fcb
->flags
|= arg
;
157 errno
= IoErr2errno(IoErr());