source: rtems/c/src/lib/libc/fcntl.c @ 73f6236

4.104.114.84.95
Last change on this file since 73f6236 was 73f6236, checked in by Joel Sherrill <joel.sherrill@…>, on 03/01/99 at 22:40:08

Patch from Eric Norum <eric@…> to eliminate external
IO handlers scheme that was implemented originally just to support
sockets. The file system IO switch is more general and works fine.

  • Property mode set to 100644
File size: 2.3 KB
Line 
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;
30  rtems_libio_t *diop;
31  int            fd2;
32 
33  va_start( ap, cmd );
34
35  rtems_libio_check_fd( fd );
36  iop = rtems_libio_iop( fd );
37  rtems_libio_check_is_open(iop);
38
39  /*
40   *  Now process the fcntl().
41   */
42
43  /*
44   *  This switch should contain all the cases from POSIX.
45   */
46
47  switch ( cmd ) {
48    case F_DUPFD:        /* dup */
49      fd2 = va_arg( ap, int );
50      if ( fd2 )
51        diop = rtems_libio_iop( fd2 );
52      else {
53        /* allocate a file control block */
54        diop = rtems_libio_allocate();
55        if ( diop == 0 )
56          return -1;
57      }
58
59      diop->handlers   = iop->handlers;
60      diop->file_info  = iop->file_info;
61      diop->flags      = iop->flags;
62      diop->pathinfo   = iop->pathinfo;
63     
64      return 0;
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}
Note: See TracBrowser for help on using the repository browser.