iPXE
posix_io.h
Go to the documentation of this file.
1#ifndef _IPXE_POSIX_IO_H
2#define _IPXE_POSIX_IO_H
3
4/** @file
5 *
6 * POSIX-like I/O
7 *
8 */
9
10FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
11
12#include <stdint.h>
13
14/** Minimum file descriptor that will ever be allocated */
15#define POSIX_FD_MIN ( 1 )
16
17/** Maximum file descriptor that will ever be allocated */
18#define POSIX_FD_MAX ( 31 )
19
20/** File descriptor set as used for select() */
22
23extern int open ( const char *uri_string );
24extern ssize_t read ( int fd, void *buf, size_t len );
25extern int select ( fd_set *readfds, int wait );
26extern ssize_t fsize ( int fd );
27extern int close ( int fd );
28
29/**
30 * Zero a file descriptor set
31 *
32 * @v set File descriptor set
33 */
34static inline __attribute__ (( always_inline )) void
35FD_ZERO ( fd_set *set ) {
36 *set = 0;
37}
38
39/**
40 * Set a bit within a file descriptor set
41 *
42 * @v fd File descriptor
43 * @v set File descriptor set
44 */
45static inline __attribute__ (( always_inline )) void
46FD_SET ( int fd, fd_set *set ) {
47 *set |= ( 1 << fd );
48}
49
50/**
51 * Clear a bit within a file descriptor set
52 *
53 * @v fd File descriptor
54 * @v set File descriptor set
55 */
56static inline __attribute__ (( always_inline )) void
57FD_CLR ( int fd, fd_set *set ) {
58 *set &= ~( 1 << fd );
59}
60
61/**
62 * Test a bit within a file descriptor set
63 *
64 * @v fd File descriptor
65 * @v set File descriptor set
66 * @ret is_set Corresponding bit is set
67 */
68static inline __attribute__ (( always_inline )) int
69FD_ISSET ( int fd, fd_set *set ) {
70 return ( *set & ( 1 << fd ) );
71}
72
73#endif /* _IPXE_POSIX_IO_H */
unsigned int uint32_t
Definition stdint.h:12
signed long ssize_t
Definition stdint.h:7
ring len
Length.
Definition dwmac.h:226
#define FILE_LICENCE(_licence)
Declare a particular licence as applying to a file.
Definition compiler.h:896
#define __attribute__(x)
Definition compiler.h:10
struct option_descriptor set[0]
Definition nvo_cmd.c:112
struct option_descriptor read[1]
Definition nvo_cmd.c:116
uint32_t fd_set
File descriptor set as used for select()
Definition posix_io.h:21
int select(fd_set *readfds, int wait)
Check file descriptors for readiness.
Definition posix_io.c:229
ssize_t fsize(int fd)
Determine file size.
Definition posix_io.c:310
int open(const char *uri_string)
Open file.
Definition posix_io.c:176
static struct evtchn_close * close
Definition xenevent.h:24