aboutsummaryrefslogtreecommitdiffstats
path: root/core.c
diff options
context:
space:
mode:
Diffstat (limited to 'core.c')
-rw-r--r--core.c36
1 files changed, 23 insertions, 13 deletions
diff --git a/core.c b/core.c
index 7de3085..1fe2891 100644
--- a/core.c
+++ b/core.c
@@ -98,7 +98,7 @@ file_t *file_init()
{
file_t *ret = NULL;
- ret = malloc( sizeof(file_t) );
+ ret = (file_t *)malloc( sizeof(file_t) );
memset( ret, 0, sizeof(file_t) );
ret->flags = FD_RO; //di we really need that?
@@ -123,7 +123,7 @@ int file_open_fn( file_t *ft, const char *filename, int flags )
ft->flags = flags;
uint8_t fn_sz = strlen( filename );
- char *fn = malloc( fn_sz );
+ char *fn = (char *)malloc( fn_sz );
memcpy( fn, filename, fn_sz );
ft->filename = fn;
@@ -230,7 +230,7 @@ int file_resize( file_t *ft, size_t size )
{
return -1;
}
- buf = malloc( size );
+ buf = (uint8_t *)malloc( size );
memset( buf, 0, size );
fd_seek( ft->fd, cur_size, FD_SEEK_SET );
resize = fd_write( ft->fd, buf, size );
@@ -251,7 +251,7 @@ 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_blk( file_t *ft, uint8_t *buf, int sz )
{
int ret = 0;
@@ -259,7 +259,12 @@ int file_read_blk( file_t *ft, uint8_t *buf )
return -1;
file_pos( ft );
- ret = fd_read( ft->fd, buf, ft->blk_size );
+ int read_sz = sz;
+ if (read_sz > ft->blk_size)
+ {
+ read_sz = ft->blk_size;
+ }
+ ret = fd_read( ft->fd, buf, read_sz );
fd_set_pos( ft->fd, ft->position ); //chck err?
if ( ret < 0)
@@ -288,21 +293,26 @@ 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_blk( file_t *ft, uint8_t *buf, int sz )
{
int ret = 0;
- unsigned int sz;
+ unsigned int write_sz;
file_pos( ft );
if ( ft->position + ft->blk_size <= ft->size )
{
- sz = ft->blk_size;
+ write_sz = ft->blk_size;
} else
{
- sz = ft->size - ft->position; //when pos 0 ans size 1 then will write 1 byte
+ write_sz = ft->size - ft->position; //when pos 0 ans size 1 then will write 1 byte
+ }
+
+ if (write_sz > sz)
+ {
+ write_sz = sz;
}
- ret = fd_write( ft->fd, buf, sz );
+ ret = fd_write( ft->fd, buf, write_sz );
if ( ret < 0 )
{
printf("Error while writing block to file\n");
@@ -394,12 +404,12 @@ uint8_t **dir_list( char *path)
//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) );
+ new_ptr = (uint8_t **)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 );
+ ret[cnt-1] = (uint8_t *)malloc( str_sz+1 );
memcpy( ret[cnt-1], ep->d_name, str_sz );
ret[cnt-1][str_sz] = 0;
}
@@ -412,7 +422,7 @@ uint8_t **dir_list( char *path)
}
//add NULL element at the end
- new_ptr = realloc( ret, sizeof(uint8_t*)*(cnt+1) );
+ new_ptr = (uint8_t **)realloc( ret, sizeof(uint8_t*)*(cnt+1) );
if ( new_ptr == NULL )
goto failed_add_entry;
ret = new_ptr;