cURL / Mailing Lists / curl-library / Single Mail

curl-library

Re: Problem with CURLOPT_WRITEDATA getting Binary data

From: Kalidoss Sivasamy <kalidoss2_at_gmail.com>
Date: Sun, 30 May 2010 11:46:12 -0500

You both are absolutely right. Tested with fwrite and the data looks good.

On Sun, May 30, 2010 at 10:46 AM, Tor Arntsen <tor_at_spacetec.no> wrote:

> opps, sent too early: Here's the rest:
>
> On Sun, May 30, 2010 at 17:44, Tor Arntsen <tor_at_spacetec.no> wrote:
> > On Sun, May 30, 2010 at 17:36, Kalidoss Sivasamy <kalidoss2_at_gmail.com>
> wrote:
> >> Ok, I modified the code, first not null terminate (
> //mem->memory[mem->size]
> >> = 0;). Also, changed the print routine to print each char at a time.
> >
> >>
> >> void printText(char* s){
> >> int len = strlen(s);
> >> for (int i = 0; i < len; i++) {
> >> printf("%c", *s++);
> >> }
> >> }
> >
> > It's the same trap you're falling into, you _can't_ handle binary data
> > as strings.
> >
> > The strlen() will return the number of bytes up to, but not including,
> > the first \0 (binary zero) in the data stream. You just can't do it
> > that way. Use fwrite, as Kamil suggested. Or at least anything not
> > using str* functions, or printf.
> >
> > If you have the size available then you could do e.g.
> s = chunk.memory;
> > for (i = 0; i < chunk.size; i++) {
> ..
> printf ("0x%02x", *s++);
>
> }
>
> something like that. Anything but strlen() and printf (%s)
> -------------------------------------------------------------------
> List admin: http://cool.haxx.se/list/listinfo/curl-library
> Etiquette: http://curl.haxx.se/mail/etiquette.html
>

-------------------------------------------------------------------
List admin: http://cool.haxx.se/list/listinfo/curl-library
Etiquette: http://curl.haxx.se/mail/etiquette.html
Received on 2010-05-30