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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
|
#ifndef __IHE_CORE_H
#define __IHE_CORE_H
#include <stdlib.h>
#include <stdio.h>
#include <stdint.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <dirent.h>
#include <fcntl.h>
#include <unistd.h>
#include <string.h>
#include <errno.h>
/*******************************************************************************
BASIC FILE OPERATIONS ON FILE
******************************************************************************/
#define FD_RO O_RDONLY
#define FD_WO O_WRONLY
#define FD_RW O_RDWR
#define FD_MNONE 0
#define FD_SEEK_CUR SEEK_CUR
#define FD_SEEK_SET SEEK_SET
#define FD_SEEK_END SEEK_END
/*OPEN FILE BY FILE NAME*/
int fd_open( const char *filename, int flags );
/*CLOSE FILE BY FD*/
int fd_close( int fd );
/*SEEK FILE
FD - file descriptor
OFFSET - seek pos
WHENCE - seek mode
NEW_OFFSET - new pos, helps to detect if actualy moved to new pos
*/
int fd_seek( int fd, off_t offset, int whence );
off_t fd_pos( int fd );
off_t fd_set_pos( int fd, off_t offset );
off_t fd_size( int fd );
/*
READ from file
FD - file descriptor
BUF - where to write readed output
COUNT - how much to read
RETURN - size readed
*/
ssize_t fd_read( int fd, void *buf, size_t count );
ssize_t fd_write( int fd, void *buf, size_t count );
/*
FILE RELATED UTILITIES
*/
/*
CHECK IF YOU HAVE PERMISSIONS TO OPEN FILE
MAYBE THIS IS FILE OF USER OR LOWER PERMISSION USER
*/
/*
CHECK IF PATCH TO FILE EXCISTS
*/
/*
GET PATH FILE TYPE
COULD BE SOME DIRECTORY OR SOME LOOP FILE?
*/
/*
GET DEFAULT PATHES THAT WILL IS NOT SUPPORTED
/dev/radnom is not good to open
/dev/ttyUSB also steaming files
/dev/input/mice also is not good alt to open
/proc/<pid>/mmap also is not alterntice to open
search and check for more
*/
/*******************************************************************************
FILE OPERATION MANAGMENT STRUCTURE
******************************************************************************/
#define DEFAULT_BLK_SIZE 256
typedef struct file_t
{
const char *filename;
int fd; /* fd is fd */
int flags; /* file opening flags */
int mode; /* file opening mode */
off_t offset; /* last used offset */
long position; /* file cursor position */
off_t size; /* file size*/
unsigned int blk_size; /*default block size to operate with*/
} file_t;
file_t *file_init();
int file_open_fn( file_t *ft, const char *filename, int mode );
int file_open( file_t *ft, const char *filename, int flags, int mode );
int file_read_blk( file_t *ft, uint8_t *buf, int sz );
int file_read( file_t *ft, uint8_t *buf, size_t count );
int file_write_blk( file_t *ft, uint8_t *buf, int sz );
int file_write( file_t *ft, uint8_t *buf, size_t count );
int file_seek( file_t *ft, off_t offset ); //seek by offset
int file_seekp( file_t *ft, off_t offset );
int file_pos( file_t *ft );
int file_size( file_t *ft );
int file_resize( file_t *ft, size_t size );
int file_s_bufs( file_t *ft, unsigned int size );
int file_s_mode( file_t *ft, int mode );
int file_close( file_t *ft );
/*******************************************************************************
UTILITITIES
******************************************************************************/
/*
LIST DIRECTORY FILES
*/
uint8_t **dir_list( char *path );
#endif
|