summaryrefslogtreecommitdiff
path: root/cmd/cmd_read.c
blob: 8c1c594784ee39246b552c90eb5d8e126fc0084b (plain) (blame)
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
#include "buf.h"
#include "core.h"

#include "libcmd/cmd.h"
#include "libcmd/cmd_parse.h"

extern file_t *g_file;
extern Buf *g_buf;
extern int g_flags;

int c_read( cmd_arg_t *arg )
{
	int ret;

	//if ( g_buf->buf == NULL )
	if (g_buf->isempty())
	{
		//buf_resize( g_buf, g_file->blk_size );
		g_buf->realloc(g_file->blk_size);
	}

	char *buf_ptr;
	int sz;
	g_buf->get_ptr(&buf_ptr,&sz);
	sz = g_buf->size();
	//printf("sz %d ptr %lx",sz,buf_ptr);
	ret = file_read_blk( g_file, (uint8_t *)buf_ptr, sz );
	printf("Readed %d bytes\n", ret);
	if ( (ret >= 0) && (ret <= g_buf->size()) )
	{
		g_buf->set_size(ret);
	}

	return 0;
}

int h_read( cmd_arg_t *arg )
{
	printf(" - read data from file");
	return 0;
}