source: rtems/c/src/lib/libc/libio_sockets.c @ 2782e69

4.104.114.84.95
Last change on this file since 2782e69 was 707d4d0, checked in by Joel Sherrill <joel.sherrill@…>, on 03/30/99 at 17:42:25

Removed warning for const removal.

  • Property mode set to 100644
File size: 1.3 KB
Line 
1/*
2 *  This file contains the support infrastructure used to manage the
3 *  table of integer style file descriptors used by the socket calls.
4 *
5 *  COPYRIGHT (c) 1989-1998.
6 *  On-Line Applications Research Corporation (OAR).
7 *  Copyright assigned to U.S. Government, 1994.
8 *
9 *  The license and distribution terms for this file may be
10 *  found in the file LICENSE in this distribution or at
11 *  http://www.OARcorp.com/rtems/license.html.
12 *
13 *  $Id$
14 */
15
16#include "libio_.h"                   /* libio_.h pulls in rtems */
17#include <rtems.h>
18
19#include <errno.h>
20
21/*
22 * Convert an RTEMS file descriptor to a BSD socket pointer.
23 */
24
25struct socket *rtems_bsdnet_fdToSocket(
26  int fd
27)
28{
29  rtems_libio_t *iop;
30
31  if ((unsigned32)fd >= rtems_libio_number_iops) {
32    errno = EBADF;
33    return NULL;
34  }
35  iop = &rtems_libio_iops[fd];
36  if (iop->data1 == NULL)
37    errno = EBADF;
38  return iop->data1;
39}
40
41/*
42 * Create an RTEMS file descriptor for a socket
43 */
44
45int rtems_bsdnet_makeFdForSocket(
46  void *so,
47  const rtems_filesystem_file_handlers_r *h
48)
49{
50  rtems_libio_t *iop;
51  int fd;
52
53  iop = rtems_libio_allocate();
54  if (iop == 0) {
55      errno = ENFILE;
56      return -1;
57  }
58  fd = iop - rtems_libio_iops;
59  iop->flags |= LIBIO_FLAGS_WRITE | LIBIO_FLAGS_READ;
60  iop->data0 = fd;
61  iop->data1 = so;
62  iop->handlers = (rtems_filesystem_file_handlers_r *) h;
63  return fd;
64}
Note: See TracBrowser for help on using the repository browser.