source: rtems/cpukit/libcsupport/src/fcntl.c @ 5822f43

4.104.114.84.95
Last change on this file since 5822f43 was 5822f43, checked in by Jennifer Averett <Jennifer.Averett@…>, on 12/03/98 at 22:17:26

Added source for F_DUPFD.

  • Property mode set to 100644
File size: 2.4 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  /*
36   *  If this is not a file system based entity, it is an error.
37   */
38
39  if ( rtems_file_descriptor_type( fd ) )
40    set_errno_and_return_minus_one( EBADF );
41
42  /*
43   *  Now process the fcntl().
44   */
45
46  iop = rtems_libio_iop( fd );
47  rtems_libio_check_fd( fd );
48
49  /*
50   *  This switch should contain all the cases from POSIX.
51   */
52
53  switch ( cmd ) {
54    case F_DUPFD:        /* dup */
55      fd2 = va_arg( ap, int );
56      if ( fd2 )
57        diop = rtems_libio_iop( fd2 );
58      else {
59        /* allocate a file control block */
60        diop = rtems_libio_allocate();
61        if ( diop == 0 )
62          return -1;
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     
70      return 0;
71
72    case F_GETFD:        /* get f_flags */
73      if ( iop->flags & LIBIO_FLAGS_CLOSE_ON_EXEC )
74        return 1;
75      return 0;
76
77    case F_SETFD:        /* set f_flags */
78      /*
79       *  Interpret the third argument as the "close on exec()" flag.
80       *  If this argument is 1, then the file descriptor is to be closed
81       *  if a new process is exec()'ed.  Since RTEMS does not support
82       *  processes, then we can ignore this one except to make
83       *  F_GETFD work.
84       */
85
86      if ( va_arg( ap, int ) )
87        iop->flags |= LIBIO_FLAGS_CLOSE_ON_EXEC;
88      else
89        iop->flags &= ~LIBIO_FLAGS_CLOSE_ON_EXEC;
90      return 0;
91
92    case F_GETFL:        /* more flags (cloexec) */
93      return -1;
94
95    case F_SETFL:
96      return -1;
97
98    case F_GETLK:
99      return -1;
100
101    case F_SETLK:
102      return -1;
103
104    case F_SETLKW:
105      return -1;
106
107    case F_SETOWN:       /*  for sockets. */
108      return -1;
109
110    case F_GETOWN:       /*  for sockets. */
111      return -1;
112
113    default:
114      break;
115  }
116  return -1;
117}
Note: See TracBrowser for help on using the repository browser.