OpenCores
URL https://opencores.org/ocsvn/or1k/or1k/trunk

Subversion Repositories or1k

[/] [or1k/] [trunk/] [rtems-20020807/] [cpukit/] [libcsupport/] [src/] [fcntl.c] - Blame information for rev 1765

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 1026 ivang
/*
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.OARcorp.com/rtems/license.html.
10
 *
11
 *  fcntl.c,v 1.19 2002/01/06 20:11:37 joel Exp
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
 
26
int fcntl(
27
  int fd,
28
  int cmd,
29
  ...
30
)
31
{
32
  va_list        ap;
33
  rtems_libio_t *iop;
34
  rtems_libio_t *diop;
35
  int            fd2;
36
  int            flags;
37
  int            mask;
38
  int            ret = 0;
39
 
40
  va_start( ap, cmd );
41
 
42
  rtems_libio_check_fd( fd );
43
  iop = rtems_libio_iop( fd );
44
  rtems_libio_check_is_open(iop);
45
 
46
  /*
47
   *  Now process the fcntl().
48
   */
49
 
50
  /*
51
   *  This switch should contain all the cases from POSIX.
52
   */
53
 
54
  switch ( cmd ) {
55
    case F_DUPFD:        /* dup */
56
      fd2 = va_arg( ap, int );
57
      if ( fd2 )
58
        diop = rtems_libio_iop( fd2 );
59
      else {
60
        /* allocate a file control block */
61
        diop = rtems_libio_allocate();
62
        if ( diop == 0 ) {
63
          ret = -1;
64
          break;
65
        }
66
      }
67
 
68
      diop->handlers   = iop->handlers;
69
      diop->file_info  = iop->file_info;
70
      diop->flags      = iop->flags;
71
      diop->pathinfo   = iop->pathinfo;
72
      ret = (int) (diop - rtems_libio_iops);
73
      break;
74
 
75
    case F_GETFD:        /* get f_flags */
76
      ret = ((iop->flags & LIBIO_FLAGS_CLOSE_ON_EXEC) != 0);
77
      break;
78
 
79
    case F_SETFD:        /* set f_flags */
80
      /*
81
       *  Interpret the third argument as the "close on exec()" flag.
82
       *  If this argument is 1, then the file descriptor is to be closed
83
       *  if a new process is exec()'ed.  Since RTEMS does not support
84
       *  processes, then we can ignore this one except to make
85
       *  F_GETFD work.
86
       */
87
 
88
      if ( va_arg( ap, int ) )
89
        iop->flags |= LIBIO_FLAGS_CLOSE_ON_EXEC;
90
      else
91
        iop->flags &= ~LIBIO_FLAGS_CLOSE_ON_EXEC;
92
      break;
93
 
94
    case F_GETFL:        /* more flags (cloexec) */
95
      ret = rtems_libio_to_fcntl_flags( iop->flags );
96
      break;
97
 
98
    case F_SETFL:
99
      flags = rtems_libio_fcntl_flags( va_arg( ap, int ) );
100
      mask = LIBIO_FLAGS_NO_DELAY | LIBIO_FLAGS_APPEND;
101
 
102
      /*
103
       *  XXX If we are turning on append, should we seek to the end?
104
       */
105
 
106
      iop->flags = (iop->flags & ~mask) | (flags & mask);
107
      break;
108
 
109
    case F_GETLK:
110
      errno = ENOTSUP;
111
      ret = -1;
112
      break;
113
 
114
    case F_SETLK:
115
      errno = ENOTSUP;
116
      ret = -1;
117
      break;
118
 
119
    case F_SETLKW:
120
      errno = ENOTSUP;
121
      ret = -1;
122
      break;
123
 
124
    case F_SETOWN:       /*  for sockets. */
125
      errno = ENOTSUP;
126
      ret = -1;
127
      break;
128
 
129
    case F_GETOWN:       /*  for sockets. */
130
      errno = ENOTSUP;
131
      ret = -1;
132
      break;
133
 
134
    default:
135
      errno = EINVAL;
136
      ret = -1;
137
      break;
138
  }
139
 
140
  /*
141
   *  If we got this far successfully, then we give the optional
142
   *  filesystem specific handler a chance to process this.
143
   */
144
 
145
  if (ret >= 0) {
146
    if (iop->handlers->fcntl_h) {
147
      int err = (*iop->handlers->fcntl_h)( cmd, iop );
148
      if (err) {
149
        errno = err;
150
        ret = -1;
151
      }
152
    }
153
  }
154
  return ret;
155
}

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.