Files
rtems/cpukit/libcsupport/src/libio_sockets.c
Sebastian Huber fd2b1634bb 2010-07-16 Sebastian Huber <sebastian.huber@embedded-brains.de>
* libcsupport/include/rtems/libio.h: Removed file_info and handlers
	fields in rtems_libio_t.
	* libcsupport/src/close.c, libcsupport/src/fcntl.c,
	libcsupport/src/fdatasync.c, libcsupport/src/fstat.c,
	libcsupport/src/fsync.c, libcsupport/src/ftruncate.c,
	libcsupport/src/getdents.c, libcsupport/src/ioctl.c,
	libcsupport/src/libio_sockets.c, libcsupport/src/lseek.c,
	libcsupport/src/open.c, libcsupport/src/read.c,
	libcsupport/src/readv.c, libcsupport/src/write.c,
	libcsupport/src/writev.c, libfs/src/devfs/devclose.c,
	libfs/src/devfs/devioctl.c, libfs/src/devfs/devopen.c,
	libfs/src/devfs/devread.c, libfs/src/devfs/devwrite.c
	libfs/src/dosfs/msdos_dir.c libfs/src/dosfs/msdos_file.c
	libfs/src/imfs/deviceio.c libfs/src/imfs/imfs_directory.c
	libfs/src/imfs/imfs_fifo.c libfs/src/imfs/memfile.c
	libfs/src/nfsclient/src/nfs.c libfs/src/rfs/rtems-rfs-rtems-file.c
	libfs/src/rfs/rtems-rfs-rtems.h libnetworking/lib/ftpfs.c: Reflect
	changes above.
2010-07-15 08:10:48 +00:00

74 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>
#include <rtems/seterr.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)
rtems_set_errno_and_return_minus_one( ENFILE );
fd = iop - rtems_libio_iops;
iop->flags |= LIBIO_FLAGS_WRITE | LIBIO_FLAGS_READ;
iop->data0 = fd;
iop->data1 = so;
iop->pathinfo.handlers = h;
iop->pathinfo.ops = &rtems_filesystem_operations_default;
return fd;
}