source: rtems/c/src/exec/libcsupport/src/fcntl.c @ 3ef8798

4.104.114.84.95
Last change on this file since 3ef8798 was 3ef8798, checked in by Joel Sherrill <joel.sherrill@…>, on 03/06/99 at 18:09:15

Added F_GETFL support so the fdopen() implementation in newlib 1.8.1
would work. At the same time, the initial implementation of F_SETFL
was added. A support routine was added to convert internal libio
flags back to the POSIX style. Eventually the internal representation
should be eliminated in the interest of simplicity and code reduction.
This problem was reported by Jake Janovetz <janovetz@…>.

  • Property mode set to 100644
File size: 2.7 KB
RevLine 
[07a3253d]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
22int fcntl(
23  int fd,
24  int cmd,
25  ...
26)
27{
28  va_list        ap;
29  rtems_libio_t *iop;
[5822f43]30  rtems_libio_t *diop;
31  int            fd2;
[3ef8798]32  int            flags;
[07a3253d]33 
34  va_start( ap, cmd );
35
[cca4400]36  rtems_libio_check_fd( fd );
37  iop = rtems_libio_iop( fd );
[2d733c42]38  rtems_libio_check_is_open(iop);
[cca4400]39
[07a3253d]40  /*
41   *  Now process the fcntl().
42   */
43
44  /*
45   *  This switch should contain all the cases from POSIX.
46   */
47
48  switch ( cmd ) {
49    case F_DUPFD:        /* dup */
[5822f43]50      fd2 = va_arg( ap, int );
51      if ( fd2 )
52        diop = rtems_libio_iop( fd2 );
53      else {
54        /* allocate a file control block */
55        diop = rtems_libio_allocate();
56        if ( diop == 0 )
57          return -1;
58      }
59
60      diop->handlers   = iop->handlers;
61      diop->file_info  = iop->file_info;
62      diop->flags      = iop->flags;
63      diop->pathinfo   = iop->pathinfo;
64     
65      return 0;
[07a3253d]66
67    case F_GETFD:        /* get f_flags */
68      if ( iop->flags & LIBIO_FLAGS_CLOSE_ON_EXEC )
69        return 1;
70      return 0;
71
72    case F_SETFD:        /* set f_flags */
73      /*
74       *  Interpret the third argument as the "close on exec()" flag.
75       *  If this argument is 1, then the file descriptor is to be closed
76       *  if a new process is exec()'ed.  Since RTEMS does not support
77       *  processes, then we can ignore this one except to make
78       *  F_GETFD work.
79       */
80
81      if ( va_arg( ap, int ) )
82        iop->flags |= LIBIO_FLAGS_CLOSE_ON_EXEC;
83      else
84        iop->flags &= ~LIBIO_FLAGS_CLOSE_ON_EXEC;
85      return 0;
86
87    case F_GETFL:        /* more flags (cloexec) */
[3ef8798]88      return rtems_libio_to_fcntl_flags( iop->flags );
[07a3253d]89
90    case F_SETFL:
[3ef8798]91      flags = rtems_libio_fcntl_flags( va_arg( ap, int ) );
92
93      /*
94       *  XXX Double check this in the POSIX spec.  According to the Linux
95       *  XXX man page, only these flags can be added.
96       */
97
98      flags &= ~(O_APPEND | O_NONBLOCK);
99
100      /*
101       *  XXX If we are turning on append, should we seek to the end?
102       */
103
104      iop->flags |= flags;
105      return 0;
[07a3253d]106
107    case F_GETLK:
108      return -1;
109
110    case F_SETLK:
111      return -1;
112
113    case F_SETLKW:
114      return -1;
115
116    case F_SETOWN:       /*  for sockets. */
117      return -1;
118
119    case F_GETOWN:       /*  for sockets. */
120      return -1;
121
122    default:
123      break;
124  }
125  return -1;
126}
Note: See TracBrowser for help on using the repository browser.