Hello Cesar,
Friday, February 23, 2007, 11:19:23 AM, you wrote:
CR> good idea!! i didn't think in this!!
CR> On 23/02/07, Martin Jenkins <[EMAIL PROTECTED]> wrote:
>> Cesar Rodas wrote:
>> >while ( (n=fread(buff,Buffsize,1,file)) > 0)
>> >{
>> >if (i>0)
>> >*value = r
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, Buffs
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);
Wesley W. Terpstra wrote:
This segfaults because there is no null terminator on the value string.
I tested this and it crapped out in the memcpy, ie before it gets to the
sqlite3_mprintf. Not to say there isn't a problem there too but I don't
know the API details offhand so can't comment. I'
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 malloc
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
o
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 * len
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 err
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)
{
retur
Does any one has a C code to save a binary file into a blob, and wants
to share?
Because i am getting an "segmentation fault" error from a file that I
load into memory then I generate the query with a sqlite3_mprintf..
Thanks to all
--
Cesar Rodas
http://www.sf.net/projects/pagerank (The PageRan
11 matches
Mail list logo