blob: 4bee6662d8d33e882c3360c36ff3338b026053b1 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
|
// SIMPLE FILE DESCRIPTOR //
#ifndef FD_H
#define FD_H
#include <stdint.h>
#include <stdbool.h>
#include "fifo.h"
#include "ringbuffer.h"
enum FD_TYPE{
FD_TYPE_FIFO=1,
FD_TYPE_EXT2_FILE=2,
FD_TYPE_EXT2_DIR=3,
FD_TYPE_SYSFS=4,
FD_TYPE_PIPE=5
};
typedef struct fd_struct
{
bool (*write)(struct fd_struct*,uint8_t);
uint8_t (*read)(struct fd_struct*);
bool (*has)(struct fd_struct*);
bool (*can_write)(struct fd_struct*);
bool (*eof)(struct fd_struct*);
bool (*close)(struct fd_struct*);
struct fd_struct (*dupl)(struct fd_struct *);
uint8_t type;
void *data; // opaque data
}fd;
uint8_t fd_read(fd*);
bool fd_has(fd*);
bool fd_eof(fd*);
bool fd_write(fd*,uint8_t);
bool fd_can_write(fd*);
bool fd_close(fd*);
fd fd_dupl(fd*);
fd fd_from_fifo(fifo* f);
fd fd_from_path(char *path);
fd fd_from_sysfs(void(*g)(ringbuffer *r,void (*f)(ringbuffer *r,char *fmt, ...)),void(*h)(uint32_t in));
int fds_from_pipe(fd pipefds[2]);
#endif
|