source: rtems/cpukit/libcsupport/src/fcntl.c @ 92119ed

4.115
Last change on this file since 92119ed was 92119ed, checked in by Jennifer Averett <Jennifer.Averett@…>, on 07/01/10 at 15:12:38

2010-07-01 Jennifer Averett <Jennifer.Averett@…>

  • libcsupport/src/chdir.c, libcsupport/src/chmod.c, libcsupport/src/chown.c, libcsupport/src/close.c, libcsupport/src/eval.c, libcsupport/src/fchdir.c, libcsupport/src/fchmod.c, libcsupport/src/fchown.c, libcsupport/src/fcntl.c, libcsupport/src/fdatasync.c, libcsupport/src/freenode.c, libcsupport/src/fstat.c, libcsupport/src/fsync.c, libcsupport/src/ftruncate.c, libcsupport/src/ioctl.c, libcsupport/src/link.c, libcsupport/src/lseek.c, libcsupport/src/mknod.c, libcsupport/src/mount.c, libcsupport/src/open.c, libcsupport/src/read.c, libcsupport/src/readlink.c, libcsupport/src/readv.c, libcsupport/src/rmdir.c, libcsupport/src/stat.c, libcsupport/src/statvfs.c, libcsupport/src/symlink.c, libcsupport/src/unlink.c, libcsupport/src/unmount.c, libcsupport/src/write.c: Removed filesystem checks for NULL methods checks from the main posix rountines. These are now required to have at a miminum default routines in the tables.
  • Property mode set to 100644
File size: 3.6 KB
Line 
1/*
2 *   fcntl() - POSIX 1003.1b 6.5.2 - File Control
3 *
4 *  COPYRIGHT (c) 1989-1999.
5 *  On-Line Applications Research Corporation (OAR).
6 *
7 *  The license and distribution terms for this file may be
8 *  found in the file LICENSE in this distribution or at
9 *  http://www.rtems.com/license/LICENSE.
10 *
11 *  $Id$
12 */
13
14#if HAVE_CONFIG_H
15#include "config.h"
16#endif
17
18#include <stdarg.h>
19#include <unistd.h>
20#include <fcntl.h>
21#include <errno.h>
22
23#include <rtems.h>
24#include <rtems/libio_.h>
25
26static int vfcntl(
27  int fd,
28  int cmd,
29  va_list ap
30)
31{
32  rtems_libio_t *iop;
33  rtems_libio_t *diop;
34  int            fd2;
35  int            flags;
36  int            mask;
37  int            ret = 0;
38
39  rtems_libio_check_fd( fd );
40  iop = rtems_libio_iop( fd );
41  rtems_libio_check_is_open(iop);
42
43  /*
44   *  Now process the fcntl().
45   */
46
47  /*
48   *  This switch should contain all the cases from POSIX.
49   */
50
51  switch ( cmd ) {
52    case F_DUPFD:        /* dup */
53      fd2 = va_arg( ap, int );
54      if ( fd2 )
55        diop = rtems_libio_iop( fd2 );
56      else {
57        /* allocate a file control block */
58        diop = rtems_libio_allocate();
59        if ( diop == 0 ) {
60          ret = -1;
61          break;
62        }
63      }
64
65      diop->handlers   = iop->handlers;
66      diop->file_info  = iop->file_info;
67      diop->flags      = iop->flags;
68      diop->pathinfo   = iop->pathinfo;
69      ret = (int) (diop - rtems_libio_iops);
70      break;
71
72    case F_GETFD:        /* get f_flags */
73      ret = ((iop->flags & LIBIO_FLAGS_CLOSE_ON_EXEC) != 0);
74      break;
75
76    case F_SETFD:        /* set f_flags */
77      /*
78       *  Interpret the third argument as the "close on exec()" flag.
79       *  If this argument is 1, then the file descriptor is to be closed
80       *  if a new process is exec()'ed.  Since RTEMS does not support
81       *  processes, then we can ignore this one except to make
82       *  F_GETFD work.
83       */
84
85      if ( va_arg( ap, int ) )
86        iop->flags |= LIBIO_FLAGS_CLOSE_ON_EXEC;
87      else
88        iop->flags &= ~LIBIO_FLAGS_CLOSE_ON_EXEC;
89      break;
90
91    case F_GETFL:        /* more flags (cloexec) */
92      ret = rtems_libio_to_fcntl_flags( iop->flags );
93      break;
94
95    case F_SETFL:
96      flags = rtems_libio_fcntl_flags( va_arg( ap, int ) );
97      mask = LIBIO_FLAGS_NO_DELAY | LIBIO_FLAGS_APPEND;
98
99      /*
100       *  XXX If we are turning on append, should we seek to the end?
101       */
102
103      iop->flags = (iop->flags & ~mask) | (flags & mask);
104      break;
105
106    case F_GETLK:
107      errno = ENOTSUP;
108      ret = -1;
109      break;
110
111    case F_SETLK:
112      errno = ENOTSUP;
113      ret = -1;
114      break;
115
116    case F_SETLKW:
117      errno = ENOTSUP;
118      ret = -1;
119      break;
120
121    case F_SETOWN:       /*  for sockets. */
122      errno = ENOTSUP;
123      ret = -1;
124      break;
125
126    case F_GETOWN:       /*  for sockets. */
127      errno = ENOTSUP;
128      ret = -1;
129      break;
130
131    default:
132      errno = EINVAL;
133      ret = -1;
134      break;
135  }
136
137  /*
138   *  If we got this far successfully, then we give the optional
139   *  filesystem specific handler a chance to process this.
140   */
141
142  if (ret >= 0) {
143    int err = (*iop->handlers->fcntl_h)( cmd, iop );
144    if (err) {
145      errno = err;
146      ret = -1;
147    }
148  }
149  return ret;
150}
151
152int fcntl(
153  int fd,
154  int cmd,
155  ...
156)
157{
158  int            ret;
159  va_list        ap;
160  va_start( ap, cmd );
161  ret = vfcntl(fd,cmd,ap);
162  va_end(ap);
163  return ret;
164}
165
166
167/*
168 *  _fcntl_r
169 *
170 *  This is the Newlib dependent reentrant version of fcntl().
171 */
172
173#if defined(RTEMS_NEWLIB) && !defined(HAVE_FCNTL_R)
174
175#include <reent.h>
176
177int _fcntl_r(
178  struct _reent *ptr __attribute__((unused)),
179  int fd,
180  int cmd,
181  int arg
182)
183{
184  return fcntl( fd, cmd, arg );
185}
186#endif
Note: See TracBrowser for help on using the repository browser.