purge remaining gpl code from clib, and make clib build again
[tangerine.git] / compiler / clib / fcntl.c
blob528ccbe16efb1287a8837cda08284290a89246ed
1 /*
2 Copyright © 1995-2001, The AROS Development Team. All rights reserved.
3 $Id$
4 */
6 #include <proto/dos.h>
8 #include <fcntl.h>
9 #include <errno.h>
10 #include <stdarg.h>
12 #include "__errno.h"
13 #include "__open.h"
15 int fcntl(int fd, int cmd, ...)
17 fdesc *desc = __getfdesc(fd);
19 if (!desc)
21 errno = EBADF;
22 return -1;
25 switch (cmd)
27 case F_DUPFD:
29 va_list ap;
30 int arg;
32 va_start(ap, cmd);
33 arg = va_arg(ap, int);
34 va_end(ap);
37 FIXME: FD_CLOEXEC must be off on the copy, once this flag
38 is supported (related to F_GETFD and F_SETFD).
41 return dup2(fd, __getfirstfd(arg));
44 case F_GETFL:
45 return desc->flags & (O_NONBLOCK|O_APPEND|O_ASYNC);
47 case F_SETFL:
49 va_list ap;
50 int arg;
51 int oldmode = __oflags2amode(desc->flags & ~(O_NONBLOCK|O_APPEND|O_ASYNC));
53 va_start(ap, cmd);
54 arg = va_arg(ap, int);
55 va_end(ap);
57 arg &= (O_NONBLOCK|O_APPEND|O_ASYNC);
59 if (ChangeMode(CHANGE_FH, desc->fh, oldmode | __oflags2amode(arg)) == DOSTRUE)
61 desc->flags &= ~(O_NONBLOCK|O_APPEND|O_ASYNC);
62 desc->flags |= arg;
63 return 0;
66 errno = IoErr2errno(IoErr());
67 return -1;
70 default:
71 errno = EINVAL;
72 return -1;