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

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [rtos/] [rtems/] [c/] [src/] [lib/] [libc/] [fcntl.c] - Blame information for rev 745

Go to most recent revision | Details | Compare with Previous | View Log

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

powered by: WebSVN 2.1.0

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