2013-09-21 15:23:40 +02:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2013 INRIA.
|
|
|
|
*
|
2014-08-23 15:43:13 +02:00
|
|
|
* This file is subject to the terms and conditions of the GNU Lesser
|
|
|
|
* General Public License v2.1. See the file LICENSE in the top level
|
|
|
|
* directory for more details.
|
2013-09-21 15:23:40 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @addtogroup posix
|
|
|
|
* @{
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
2015-05-22 07:34:41 +02:00
|
|
|
* @file
|
2013-09-21 15:23:40 +02:00
|
|
|
* @brief Unifies diverse identifiers of RIOT to POSIX like file descriptors.
|
|
|
|
*
|
2015-02-08 18:51:25 +01:00
|
|
|
* @author Martine Lenders <mlenders@inf.fu-berlin.de>
|
2013-09-21 15:23:40 +02:00
|
|
|
* @author Christian Mehlis <mehlis@inf.fu-berlin.de>
|
|
|
|
*/
|
|
|
|
#ifndef FD_H
|
|
|
|
#define FD_H
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <sys/types.h>
|
2014-07-06 22:57:56 +02:00
|
|
|
#include "kernel_types.h"
|
2014-01-20 13:48:37 +01:00
|
|
|
#include "cpu.h"
|
2013-09-21 15:23:40 +02:00
|
|
|
|
2014-10-10 11:51:11 +02:00
|
|
|
#ifdef __cplusplus
|
|
|
|
extern "C" {
|
|
|
|
#endif
|
|
|
|
|
2013-09-21 15:23:40 +02:00
|
|
|
/**
|
|
|
|
* File descriptor table.
|
|
|
|
*/
|
|
|
|
typedef struct {
|
|
|
|
/** private status of this fd_t */
|
2015-03-11 17:13:26 +01:00
|
|
|
int internal_active;
|
2013-09-21 15:23:40 +02:00
|
|
|
|
2015-03-11 17:13:26 +01:00
|
|
|
/** Stores the RIOT internal value for the file descriptor (not POSIX). */
|
|
|
|
int internal_fd;
|
2013-09-21 15:23:40 +02:00
|
|
|
|
|
|
|
/**
|
2015-03-11 17:13:26 +01:00
|
|
|
* Read *n* bytes into *buf* from *fd*. Return the
|
2013-09-21 15:23:40 +02:00
|
|
|
* number read, -1 for errors or 0 for EOF.
|
|
|
|
*/
|
|
|
|
ssize_t (*read)(int fd, void *buf, size_t n);
|
|
|
|
|
|
|
|
/** Write *n* bytes of *buf* to *fd*. Return the number written, or -1. */
|
|
|
|
ssize_t (*write)(int fd, const void *buf, size_t n);
|
|
|
|
|
|
|
|
/** Close the file descriptor *fd*. */
|
2014-08-11 13:10:12 +02:00
|
|
|
int (*close)(int fd);
|
2013-09-21 15:23:40 +02:00
|
|
|
} fd_t;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Initializes file descriptors
|
|
|
|
*
|
|
|
|
* @return maximum number of available file descriptors.
|
|
|
|
*/
|
|
|
|
int fd_init(void);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Creates a new file descriptor.
|
|
|
|
*
|
|
|
|
* @param[in] internal_fd RIOT-internal identifier for the new FD.
|
|
|
|
* @param[in] internal_read Function to read from new FD.
|
|
|
|
* @param[in] internal_write Function to write into new FD.
|
|
|
|
* @param[in] internal_close Function to close new FD.
|
|
|
|
*
|
|
|
|
* @return 0 on success, -1 otherwise. *errno* is set accordingly.
|
|
|
|
*/
|
|
|
|
int fd_new(int internal_fd, ssize_t (*internal_read)(int, void *, size_t),
|
|
|
|
ssize_t (*internal_write)(int, const void *, size_t),
|
2014-08-11 13:10:12 +02:00
|
|
|
int (*internal_close)(int));
|
2013-09-21 15:23:40 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Gets the file descriptor table entry associated with file
|
|
|
|
* descriptor *fd*.
|
|
|
|
*
|
|
|
|
* @param[in] fd A POSIX-like file descriptor.
|
|
|
|
*
|
|
|
|
* @return The file descriptor table entry associated with file descriptor
|
|
|
|
*fd* or NULL if there is non.
|
|
|
|
*/
|
|
|
|
fd_t *fd_get(int fd);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Removes file descriptor table entry associated with *fd* from table.
|
|
|
|
*
|
|
|
|
* @param[in] fd A POSIX-like file descriptor.
|
|
|
|
*/
|
|
|
|
void fd_destroy(int fd);
|
|
|
|
|
2014-10-10 11:51:11 +02:00
|
|
|
#ifdef __cplusplus
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2013-09-21 15:23:40 +02:00
|
|
|
#endif /* FD_H */
|
2014-11-30 21:16:41 +01:00
|
|
|
/** @} */
|