~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to libdrizzle/query.c

  • Committer: Monty Taylor
  • Author(s): Andrew Hutchings
  • Date: 2011-03-14 16:54:30 UTC
  • mto: (2235.2.1 build)
  • mto: This revision was merged to the branch mainline in revision 2237.
  • Revision ID: mordred@inaugust.com-20110314165430-sfnwk7ek1b9nytb2
Add drizzle_safe_escape_string() function

Show diffs side-by-side

added added

removed removed

Lines of Context:
348
348
  return DRIZZLE_RETURN_OK;
349
349
}
350
350
 
351
 
size_t drizzle_escape_string(char *to, const char *from, size_t from_size)
 
351
ssize_t drizzle_safe_escape_string(char *to, size_t max_to_size, const char *from, size_t from_size)
352
352
{
353
 
  size_t to_size= 0;
 
353
  ssize_t to_size= 0;
354
354
  char newchar;
355
355
  const char *end;
356
356
 
389
389
    }
390
390
    if (newchar != '\0')
391
391
    {
 
392
      if ((size_t)to_size + 2 > max_to_size)
 
393
        return -1;
 
394
 
392
395
      *to++= '\\';
393
396
      *to++= newchar;
394
397
      to_size++;
395
398
    }
396
399
    else
397
 
    { 
 
400
    {
 
401
      if ((size_t)to_size + 1 > max_to_size)
 
402
        return -1;
 
403
 
398
404
      *to++= *from;
399
405
    }
400
406
    to_size++;
405
411
  return to_size;
406
412
}
407
413
 
 
414
size_t drizzle_escape_string(char *to, const char *from, size_t from_size)
 
415
{
 
416
  return (size_t) drizzle_safe_escape_string(to, (from_size * 2), from, from_size);
 
417
}
 
418
 
408
419
size_t drizzle_hex_string(char *to, const char *from, size_t from_size)
409
420
{
410
421
  static const char hex_map[]= "0123456789ABCDEF";