Files
rtems/cpukit/libcsupport/src/libio_sockets.c
Ralf Corsepius 83c5fc1bb9 2004-03-23 Ralf Corsepius <ralf_corsepius@rtems.org>
* libcsupport/include/chain.h, libcsupport/include/clockdrv.h,
	libcsupport/include/ringbuf.h, libcsupport/include/spurious.h,
	libcsupport/include/timerdrv.h, libcsupport/include/vmeintr.h,
	libcsupport/include/motorola/mc68230.h,
	libcsupport/include/rtems/assoc.h, libcsupport/include/rtems/libio.h,
	libcsupport/include/rtems/libio_.h,
	libcsupport/include/rtems/termiostypes.h,
	libcsupport/include/zilog/z8036.h, libcsupport/include/zilog/z8530.h,
	libcsupport/include/zilog/z8536.h, libcsupport/src/__gettod.c,
	libcsupport/src/assoc.c, libcsupport/src/assocnamebad.c,
	libcsupport/src/error.c,  libcsupport/src/libio.c,
	libcsupport/src/libio_sockets.c, libcsupport/src/malloc.c,
	libcsupport/src/no_libc.c, libcsupport/src/termios.c,
	libcsupport/src/termiosreserveresources.c: Convert to using c99
	fixed-size types.
2004-03-23 06:07:53 +00:00

76 lines
1.5 KiB
C

/*
* This file contains the support infrastructure used to manage the
* table of integer style file descriptors used by the socket calls.
*
* COPYRIGHT (c) 1989-1999.
* On-Line Applications Research Corporation (OAR).
*
* The license and distribution terms for this file may be
* found in the file LICENSE in this distribution or at
* http://www.rtems.com/license/LICENSE.
*
* $Id$
*/
#if HAVE_CONFIG_H
#include "config.h"
#endif
#include <rtems/libio_.h> /* libio_.h pulls in rtems */
#include <rtems.h>
#include <errno.h>
/*
* Convert an RTEMS file descriptor to a BSD socket pointer.
*/
struct socket *rtems_bsdnet_fdToSocket(
int fd
)
{
rtems_libio_t *iop;
/* same as rtems_libio_check_fd(_fd) but different return */
if ((uint32_t )fd >= rtems_libio_number_iops) {
errno = EBADF;
return NULL;
}
iop = &rtems_libio_iops[fd];
/* same as rtems_libio_check_is_open(iop) but different return */
if ((iop->flags & LIBIO_FLAGS_OPEN) == 0) {
errno = EBADF;
return NULL;
}
if (iop->data1 == NULL)
errno = EBADF;
return iop->data1;
}
/*
* Create an RTEMS file descriptor for a socket
*/
int rtems_bsdnet_makeFdForSocket(
void *so,
const rtems_filesystem_file_handlers_r *h
)
{
rtems_libio_t *iop;
int fd;
iop = rtems_libio_allocate();
if (iop == 0) {
errno = ENFILE;
return -1;
}
fd = iop - rtems_libio_iops;
iop->flags |= LIBIO_FLAGS_WRITE | LIBIO_FLAGS_READ;
iop->data0 = fd;
iop->data1 = so;
iop->handlers = (rtems_filesystem_file_handlers_r *) h;
return fd;
}