-
Notifications
You must be signed in to change notification settings - Fork 0
/
xnr_io.h
78 lines (65 loc) · 1.7 KB
/
xnr_io.h
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
#ifndef XNR_IO_H
#define XNR_IO_H
#include <stdio.h>
#include <stddef.h>
#include "xnr_conf.h"
#ifdef __cplusplus
extern "C" {
#endif
#ifndef XNR_PRINT_BUF_MAX_LENGTH
#define XNR_PRINT_BUF_MAX_LENGTH (128)
#endif
typedef int (*_io_write_t)(int fd, const char *buf, size_t len);
typedef int (*_io_read_t)(int fd, char *buf, size_t len);
typedef struct xnr_io
{
int in_fd;
int out_fd;
_io_write_t write;
_io_read_t read;
} xnr_io_t;
/**
* @description: 初始化
* @param io:xnr_io实例,write:写函数,read:读函数,in_fd:读fd, out_fd:写fd
*
* @return -1:失败,0:成功
*/
int xnr_io_init(xnr_io_t *io,
_io_write_t write,
_io_read_t read,
int in_fd, int out_fd);
/**
* @description: 设置读写fd
* @param io:xnr_io实例,in_fd:读编号, out_fd:写编号
* @return 无
*/
void xnr_io_set_in_fd(xnr_io_t *io, int in_fd);
void xnr_io_set_out_fd(xnr_io_t *io, int out_fd);
/**
* @description: 打印字符串
* @param io:xnr_io实例,fmt:格式化字符串,...:参数
* @return -1:失败,其他:字符串长度
*/
int xnr_io_printf(xnr_io_t *io, const char *fmt, ...);
/**
* @description: 打印字符串
* @param io:xnr_io实例,str:字符串
* @return -1:失败,其他:字符串长度
*/
int xnr_io_puts(xnr_io_t *io, const char *str);
/**
* @description: 打印字符
* @param io:xnr_io实例,c:字符
* @return -1:失败,其他:成功
*/
int xnr_io_putc(xnr_io_t *io, char c);
/**
* @description: 读取字符
* @param io:xnr_io实例
* @return -1:失败,其他:获取到的字符
*/
int xnr_io_getc(xnr_io_t *io);
#ifdef __cplusplus
}
#endif
#endif