good idea!! i didn't think in this!!
On 23/02/07, Martin Jenkins <[EMAIL PROTECTED]> wrote:
Cesar Rodas wrote:
>while ( (n=fread(buff,Buffsize,1,file)) > 0)
>{
>if (i>0)
>*value = realloc(*value, (i+1) * Buffsize);
>memcpy(*value + (i * Buffsize), buff,
I would make your routine more like this. It avoids the needless buffer
shadowing you get by using fopen and also avoids unecessary mallocs.
I haven't tested the code, it just presents the method.
unsigned char *bp;
int fd;
long fsize;
fd = open(path, O_RDWR);
Cesar Rodas wrote:
while ( (n=fread(buff,Buffsize,1,file)) > 0)
{
if (i>0)
*value = realloc(*value, (i+1) * Buffsize);
memcpy(*value + (i * Buffsize), buff, Buffsize);
*len += n;
i++;
}
An afterthought, why don't you just stat the file and
Sorry I copy bad
when I wanted to write "#define uchar unsigned char" but I did
"#define uchar unsigned char *"
On 23/02/07, Martin Jenkins <[EMAIL PROTECTED]> wrote:
Cesar Rodas wrote:
> #define uchar unsigned char *
suggests it's a char but is in fact a pointer to a char so the signature
I found the answer!! http://www.sqlite.org/cvstrac/wiki?p=BlobExample
thanks for you help too Wesley
On 23/02/07, Cesar Rodas <[EMAIL PROTECTED]> wrote:
#define E_IO_COULDNT_OPEN - 1
#define E_IO_ERRO -2
#define uchar unsigned char *
int LoadFileContent(uchar *path, uchar ** value, long *
Cesar Rodas wrote:
> #define uchar unsigned char *
suggests it's a char but is in fact a pointer to a char so the signature
of LoadFileContent is actually
int LoadFileContent(unsigned char **path, unsigned char ***value, ...
and that triggers my "three levels of indirection is usually an
A couple of comments.
On Feb 23, 2007, at 3:03 PM, Cesar Rodas wrote:
while ( (n=fread(buff,Buffsize,1,file)) > 0)
{
if (i>0)
*value = realloc(*value, (i+1) * Buffsize);
memcpy(*value + (i * Buffsize), buff, Buffsize);
*len += n;
i++;
}
You are
#define E_IO_COULDNT_OPEN - 1
#define E_IO_ERRO -2
#define uchar unsigned char *
int LoadFileContent(uchar *path, uchar ** value, long * len)
{
#define Buffsize 1024*4
int n;
long i=0;
FILE *file;
unsigned char buff[Buffsize];
if ( (file=fopen(path,"rb"))==0)
{
8 matches
Mail list logo