source: rtems/cpukit/libcsupport/src/close.c @ cca4400

4.104.114.84.95
Last change on this file since cca4400 was cca4400, checked in by Joel Sherrill <joel.sherrill@…>, on 12/10/98 at 23:31:54

Merged Eric Norum's select patch that was based on 4.0 and resolved
all conflicts.

  • Property mode set to 100644
File size: 1.3 KB
Line 
1/*
2 *  close() - POSIX 1003.1b 6.3.1 - Close a File
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 "libio_.h"
16
17int close(
18  int  fd
19)
20{
21  rtems_libio_t      *iop;
22  rtems_status_code   rc;
23  int                 status;
24
25  rtems_libio_check_fd(fd);
26  iop = rtems_libio_iop(fd);
27  if ( iop->flags & LIBIO_FLAGS_HANDLER_MASK ) {
28    int (*fp)(int  fd);
29
30    fp = rtems_libio_handlers[
31            (iop->flags >> LIBIO_FLAGS_HANDLER_SHIFT) - 1].close;
32    if ( fp == NULL )
33      set_errno_and_return_minus_one( EBADF );
34    status = (*fp)( fd );
35    return status;
36  }
37
38  if ( !iop->handlers )
39    set_errno_and_return_minus_one( EBADF );
40
41  if ( !iop->handlers->close )
42    set_errno_and_return_minus_one( ENOTSUP );
43
44  rc = (*iop->handlers->close)( iop );
45
46  rtems_libio_free( iop );
47
48  if (rc != RTEMS_SUCCESSFUL)
49    set_errno_and_return_minus_one( rc );
50
51  return rc;
52}
53
54/*
55 *  _close_r
56 *
57 *  This is the Newlib dependent reentrant version of close().
58 */
59
60#if defined(RTEMS_NEWLIB)
61
62#include <reent.h>
63
64int _close_r(
65  struct _reent *ptr,
66  int            fd
67)
68{
69  return close( fd );
70}
71#endif
Note: See TracBrowser for help on using the repository browser.