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 
10 FILE_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() */
21 typedef uint32_t fd_set;
22 
23 extern int open ( const char *uri_string );
24 extern ssize_t read ( int fd, void *buf, size_t len );
25 extern int select ( fd_set *readfds, int wait );
26 extern ssize_t fsize ( int fd );
27 extern int close ( int fd );
28 
29 /**
30  * Zero a file descriptor set
31  *
32  * @v set File descriptor set
33  */
34 static inline __attribute__ (( always_inline )) void
35 FD_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  */
45 static inline __attribute__ (( always_inline )) void
46 FD_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  */
56 static inline __attribute__ (( always_inline )) void
57 FD_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  */
68 static inline __attribute__ (( always_inline )) int
69 FD_ISSET ( int fd, fd_set *set ) {
70  return ( *set & ( 1 << fd ) );
71 }
72 
73 #endif /* _IPXE_POSIX_IO_H */
int open(const char *uri_string)
Open file.
Definition: posix_io.c:176
ssize_t read(int fd, void *buf, size_t len)
Read data from file.
Definition: posix_io.c:264
static fd_set * set
Definition: posix_io.h:46
ring len
Length.
Definition: dwmac.h:231
FILE_LICENCE(GPL2_OR_LATER_OR_UBDL)
static __attribute__((always_inline)) void FD_ZERO(fd_set *set)
Zero a file descriptor set.
Definition: posix_io.h:34
uint32_t fd_set
File descriptor set as used for select()
Definition: posix_io.h:21
unsigned int uint32_t
Definition: stdint.h:12
int select(fd_set *readfds, int wait)
Check file descriptors for readiness.
Definition: posix_io.c:229
signed long ssize_t
Definition: stdint.h:7
ssize_t fsize(int fd)
Determine file size.
Definition: posix_io.c:310
int close(int fd)
Close file.
Definition: posix_io.c:327