1 | /* |
---|
2 | * fcntl() - POSIX 1003.1b 6.5.2 - File Control |
---|
3 | * |
---|
4 | * COPYRIGHT (c) 1989-1998. |
---|
5 | * On-Line Applications Research Corporation (OAR). |
---|
6 | * Copyright assigned to U.S. Government, 1994. |
---|
7 | * |
---|
8 | * The license and distribution terms for this file may be |
---|
9 | * found in the file LICENSE in this distribution or at |
---|
10 | * http://www.OARcorp.com/rtems/license.html. |
---|
11 | * |
---|
12 | * $Id$ |
---|
13 | */ |
---|
14 | |
---|
15 | #include <unistd.h> |
---|
16 | #include <fcntl.h> |
---|
17 | #include <errno.h> |
---|
18 | |
---|
19 | #include <rtems.h> |
---|
20 | #include "libio_.h" |
---|
21 | |
---|
22 | int fcntl( |
---|
23 | int fd, |
---|
24 | int cmd, |
---|
25 | ... |
---|
26 | ) |
---|
27 | { |
---|
28 | va_list ap; |
---|
29 | rtems_libio_t *iop; |
---|
30 | |
---|
31 | va_start( ap, cmd ); |
---|
32 | |
---|
33 | /* |
---|
34 | * If this is not a file system based entity, it is an error. |
---|
35 | */ |
---|
36 | |
---|
37 | if ( rtems_file_descriptor_type( fd ) ) |
---|
38 | set_errno_and_return_minus_one( EBADF ); |
---|
39 | |
---|
40 | /* |
---|
41 | * Now process the fcntl(). |
---|
42 | */ |
---|
43 | |
---|
44 | iop = rtems_libio_iop( fd ); |
---|
45 | rtems_libio_check_fd( fd ); |
---|
46 | |
---|
47 | /* |
---|
48 | * This switch should contain all the cases from POSIX. |
---|
49 | */ |
---|
50 | |
---|
51 | switch ( cmd ) { |
---|
52 | case F_DUPFD: /* dup */ |
---|
53 | /* |
---|
54 | * This is how it appears that this case should work: |
---|
55 | * |
---|
56 | * filedes2 = va_arg( ap, int ) |
---|
57 | * if filedes2 is 0 |
---|
58 | * duplicate fd into a new descriptor |
---|
59 | * else |
---|
60 | * duplicate fd into specified descriptor after error checking it |
---|
61 | * |
---|
62 | * See dup2() in case we can eliminate stuff in there. |
---|
63 | */ |
---|
64 | return -1; |
---|
65 | |
---|
66 | case F_GETFD: /* get f_flags */ |
---|
67 | if ( iop->flags & LIBIO_FLAGS_CLOSE_ON_EXEC ) |
---|
68 | return 1; |
---|
69 | return 0; |
---|
70 | |
---|
71 | case F_SETFD: /* set f_flags */ |
---|
72 | /* |
---|
73 | * Interpret the third argument as the "close on exec()" flag. |
---|
74 | * If this argument is 1, then the file descriptor is to be closed |
---|
75 | * if a new process is exec()'ed. Since RTEMS does not support |
---|
76 | * processes, then we can ignore this one except to make |
---|
77 | * F_GETFD work. |
---|
78 | */ |
---|
79 | |
---|
80 | if ( va_arg( ap, int ) ) |
---|
81 | iop->flags |= LIBIO_FLAGS_CLOSE_ON_EXEC; |
---|
82 | else |
---|
83 | iop->flags &= ~LIBIO_FLAGS_CLOSE_ON_EXEC; |
---|
84 | return 0; |
---|
85 | |
---|
86 | case F_GETFL: /* more flags (cloexec) */ |
---|
87 | return -1; |
---|
88 | |
---|
89 | case F_SETFL: |
---|
90 | return -1; |
---|
91 | |
---|
92 | case F_GETLK: |
---|
93 | return -1; |
---|
94 | |
---|
95 | case F_SETLK: |
---|
96 | return -1; |
---|
97 | |
---|
98 | case F_SETLKW: |
---|
99 | return -1; |
---|
100 | |
---|
101 | case F_SETOWN: /* for sockets. */ |
---|
102 | return -1; |
---|
103 | |
---|
104 | case F_GETOWN: /* for sockets. */ |
---|
105 | return -1; |
---|
106 | |
---|
107 | default: |
---|
108 | break; |
---|
109 | } |
---|
110 | return -1; |
---|
111 | } |
---|