diff options
author | FreeArtMan <dos21h@gmail.com> | 2016-05-10 22:42:11 +0100 |
---|---|---|
committer | FreeArtMan <dos21h@gmail.com> | 2016-05-10 22:42:11 +0100 |
commit | 44dedb90f005bb0de9bddbd592a5c78f28bc67d1 (patch) | |
tree | 274b9cea44df3f96a965c564e26cdac42d3af94f /core.c | |
parent | bb426577c85f6d97cc28ab677e98e2b1f73eadac (diff) | |
download | ihe-44dedb90f005bb0de9bddbd592a5c78f28bc67d1.tar.gz ihe-44dedb90f005bb0de9bddbd592a5c78f28bc67d1.zip |
Replace cmd first part
Diffstat (limited to 'core.c')
-rw-r--r-- | core.c | 71 |
1 files changed, 67 insertions, 4 deletions
@@ -32,6 +32,7 @@ int fd_seek( int fd, off_t offset, int whence ) errno = 0; //why i need to reset it? return -1; } + ret = off_new; return ret; } @@ -82,7 +83,6 @@ ssize_t fd_write( int fd, void *buf, size_t count ) { ssize_t ret; - printf("%d %x %d\n", fd, buf, count); ret = write( fd, buf, count ); if ( errno != 0) { @@ -165,6 +165,18 @@ int file_seek( file_t *ft, off_t offset ) } +int file_seekp( file_t *ft, off_t offset ) +{ + int ret = 0; + off_t new_off = 0; + + ret = fd_seek( ft->fd, offset, FD_SEEK_SET ); + ft->offset = fd_seek( ft->fd, 0, FD_SEEK_CUR ); //cul be errors? + + return ret; +} + + int file_pos( file_t *ft ) { int ret = 0; @@ -239,7 +251,7 @@ int file_read( file_t *ft, uint8_t *buf, size_t count ) printf("Cannot read\n"); } else if ( ret < count ) { - printf("Requestd %d readed %d\n", count, ret); + printf("Requestd %zu readed %d\n", count, ret); } return ret; @@ -259,7 +271,7 @@ int file_write_blk( file_t *ft, uint8_t *buf ) { sz = ft->size - ft->position; //when pos 0 ans size 1 then will write 1 byte } - printf(" %d %x %u \n", ft->fd, buf, sz); + ret = fd_write( ft->fd, buf, sz ); if ( ret < 0 ) { @@ -283,7 +295,7 @@ int file_write( file_t *ft, uint8_t *buf, size_t count ) printf("Cannot write\n"); } else if ( ret < count ) { - printf("Requested %d written %d\n", count, ret); + printf("Requested %zu written %d\n", count, ret); } return ret; @@ -324,3 +336,54 @@ int file_close( file_t *ft ) return ret; } + + +uint8_t **dir_list( char *path) +{ + uint8_t **ret = NULL, **new_ptr; + int cnt=0; + DIR *dp; + struct dirent *ep; + int str_sz = 0; + + /* lets use libc example. they know what they are doing */ + dp = opendir( path ); + if ( dp != NULL ) + { + while ( (ep = readdir( dp )) != NULL ) + { + //count one more in da list + cnt += 1; + //lets alloc pointer on pointer where we put pointer + new_ptr = realloc( ret, sizeof(uint8_t*)*(cnt) ); + if ( new_ptr == NULL ) + goto failed_realloc; + ret = new_ptr; + str_sz = strlen(ep->d_name); + ret[cnt-1] = malloc( str_sz+1 ); + memcpy( ret[cnt-1], ep->d_name, str_sz ); + ret[cnt-1][str_sz] = 0; + } + closedir( dp ); + dp = NULL; + } else + { + perror("Couldnt list directory files"); + *ret = NULL; + } + + //add NULL element at the end + new_ptr = realloc( ret, sizeof(uint8_t*)*(cnt+1) ); + if ( new_ptr == NULL ) + goto failed_add_entry; + ret = new_ptr; + ret[cnt] = NULL; + + return ret; + +failed_realloc: + closedir( dp ); +failed_add_entry: + //forgot to free ret + return NULL; +}
\ No newline at end of file |