diff options
author | FreeArtMan <=> | 2016-02-04 23:02:20 +0000 |
---|---|---|
committer | FreeArtMan <=> | 2016-02-04 23:02:20 +0000 |
commit | ebe6923b17de88d37d97846be2567fb75f53292c (patch) | |
tree | ca14f19a6634546d93a02775b407e8197c805760 /core.h | |
download | ihe-ebe6923b17de88d37d97846be2567fb75f53292c.tar.gz ihe-ebe6923b17de88d37d97846be2567fb75f53292c.zip |
Initial commit
Diffstat (limited to 'core.h')
-rw-r--r-- | core.h | 110 |
1 files changed, 110 insertions, 0 deletions
@@ -0,0 +1,110 @@ +#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 <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 file_read( file_t *ft, uint8_t *buf, size_t count ); +int file_write_blk( file_t *ft, uint8_t *buf ); +int file_write( file_t *ft, uint8_t *buf, size_t count ); +int file_seek( file_t *ft, off_t offset ); +int file_pos( file_t *ft ); +int file_size( file_t *ft ); +int file_s_mode( file_t *ft, int mode ); +int file_close( file_t *ft ); + +#endif
\ No newline at end of file |