CNDP  22.08.0
cli_file.h
Go to the documentation of this file.
1 /* SPDX-License-Identifier: BSD-3-Clause
2  * Copyright (c) 2019-2022 Intel Corporation.
3  */
4 
5 #ifndef _CLI_FILE_H_
6 #define _CLI_FILE_H_
7 
14 #include <stdint.h> // for uint32_t
15 
16 #include "cli.h"
17 #include "cne_common.h" // for CNDP_API
18 
19 // IWYU pragma: no_forward_declare ci_node
20 struct cli_node;
21 
22 #ifdef __cplusplus
23 extern "C" {
24 #endif
25 
26 #define CLI_FILE_SIZE 1024
27 
28 enum {
29  /* File operations opt */
30  CLI_FILE_RD = 0x0001,
31  CLI_FILE_WR = 0x0002,
32  CLI_FILE_APPEND = 0x0004,
33  CLI_FILE_OPEN = 0x0008,
34  CLI_FILE_CLOSE = 0x0010,
35  CLI_FILE_CREATE = 0x0020,
37  /* File seek operations */
38  CLI_SEEK_SET = 0x0100,
39  CLI_SEEK_CUR = 0x0200,
40  CLI_SEEK_END = 0x0400,
42  /* File information in cli_node.fflags */
43  CLI_DATA_RDONLY = 0x1000,
44  CLI_FREE_DATA = 0x2000,
45  CLI_DATA_EXPAND = 0x4000
46 };
47 
48 #define file_set(f, v) \
49  do { \
50  (f) |= (v); \
51  } while ((0))
52 #define file_clr(f, v) \
53  do { \
54  (f) &= ~(v); \
55  } while ((0))
56 
67 static inline int
68 is_file_set(uint32_t opt, uint32_t cmpflags)
69 {
70  return opt & cmpflags;
71 }
72 
81 static inline int
82 is_file_rd(uint32_t opt)
83 {
84  return is_file_set(opt, CLI_FILE_RD);
85 }
86 
95 static inline int
96 is_file_wr(uint32_t opt)
97 {
98  return is_file_set(opt, CLI_FILE_WR);
99 }
100 
109 static inline int
110 is_file_append(uint32_t opt)
111 {
112  return is_file_set(opt, CLI_FILE_APPEND);
113 }
114 
123 static inline int
124 is_file_open(uint32_t opt)
125 {
126  return is_file_set(opt, CLI_FILE_OPEN);
127 }
128 
137 static inline int
138 is_file_close(uint32_t opt)
139 {
140  return is_file_set(opt, CLI_FILE_CLOSE);
141 }
142 
143 static inline int
144 is_file_create(uint32_t opt)
145 {
146  return is_file_set(opt, CLI_FILE_CREATE);
147 }
148 
157 static inline int
158 is_data_rdonly(uint32_t flags)
159 {
160  return is_file_set(flags, CLI_DATA_RDONLY);
161 }
162 
173 static inline int
174 is_file_eq(uint32_t opt, uint32_t cmpflags)
175 {
176  return ((opt & cmpflags) == cmpflags);
177 }
178 
187 static inline int
188 is_seek_set(uint32_t opt)
189 {
190  return is_file_set(opt, CLI_SEEK_SET);
191 }
192 
201 static inline int
202 is_seek_cur(uint32_t opt)
203 {
204  return is_file_set(opt, CLI_SEEK_CUR);
205 }
206 
215 static inline int
216 is_seek_end(uint32_t opt)
217 {
218  return is_file_set(opt, CLI_SEEK_END);
219 }
220 
231 CNDP_API struct cli_node *cli_file_open(const char *path, const char *type);
232 
241 CNDP_API int cli_file_close(struct cli_node *node);
242 
255 CNDP_API int cli_file_read(struct cli_node *node, char *buff, int len);
256 
269 CNDP_API int cli_file_write(struct cli_node *node, char *buff, int len);
270 
283 CNDP_API int cli_file_seek(struct cli_node *node, int offset, uint32_t whence);
284 
297 CNDP_API int cli_readline(struct cli_node *node, char *buff, int len);
298 
309 CNDP_API struct cli_node *cli_file_create(const char *path, const char *type);
310 
325 CNDP_API int cli_file_handler(struct cli_node *node, char *buff, int len, uint32_t opt);
326 
335 CNDP_API int cli_system(char *p);
336 
337 #ifdef __cplusplus
338 }
339 #endif
340 
341 #endif /* _CLI_FILE_H_ */
static int is_seek_cur(uint32_t opt)
Definition: cli_file.h:202
static int is_seek_set(uint32_t opt)
Definition: cli_file.h:188
CNDP_API int cli_readline(struct cli_node *node, char *buff, int len)
CNDP_API struct cli_node * cli_file_create(const char *path, const char *type)
static int is_seek_end(uint32_t opt)
Definition: cli_file.h:216
CNDP_API int cli_file_read(struct cli_node *node, char *buff, int len)
CNDP_API int cli_file_handler(struct cli_node *node, char *buff, int len, uint32_t opt)
static int is_file_rd(uint32_t opt)
Definition: cli_file.h:82
CNDP_API int cli_file_seek(struct cli_node *node, int offset, uint32_t whence)
static int is_file_close(uint32_t opt)
Definition: cli_file.h:138
CNDP_API int cli_file_close(struct cli_node *node)
static int is_file_eq(uint32_t opt, uint32_t cmpflags)
Definition: cli_file.h:174
static int is_data_rdonly(uint32_t flags)
Definition: cli_file.h:158
@ CLI_FREE_DATA
Definition: cli_file.h:44
@ CLI_FILE_APPEND
Definition: cli_file.h:32
@ CLI_FILE_CLOSE
Definition: cli_file.h:34
@ CLI_SEEK_END
Definition: cli_file.h:40
@ CLI_SEEK_SET
Definition: cli_file.h:38
@ CLI_FILE_CREATE
Definition: cli_file.h:35
@ CLI_SEEK_CUR
Definition: cli_file.h:39
@ CLI_FILE_WR
Definition: cli_file.h:31
@ CLI_DATA_RDONLY
Definition: cli_file.h:43
@ CLI_FILE_OPEN
Definition: cli_file.h:33
@ CLI_DATA_EXPAND
Definition: cli_file.h:45
CNDP_API int cli_system(char *p)
static int is_file_open(uint32_t opt)
Definition: cli_file.h:124
CNDP_API struct cli_node * cli_file_open(const char *path, const char *type)
CNDP_API int cli_file_write(struct cli_node *node, char *buff, int len)
static int is_file_set(uint32_t opt, uint32_t cmpflags)
Definition: cli_file.h:68
static int is_file_wr(uint32_t opt)
Definition: cli_file.h:96
static int is_file_append(uint32_t opt)
Definition: cli_file.h:110