- Timestamp:
- Dec 24, 2007, 2:53:11 AM (17 years ago)
- Branches:
- master, barnowl_perlaim, debian, release-1.10, release-1.4, release-1.5, release-1.6, release-1.7, release-1.8, release-1.9
- Children:
- 762512d
- Parents:
- 5bc0f68
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
util.c
r5bc0f68 r28ee32b 399 399 } 400 400 401 /* downcase the string 'foo' */402 void downstr(char *foo)403 {404 int i;405 for (i=0; foo[i]!='\0'; i++) {406 foo[i]=tolower(foo[i]);407 }408 }409 410 401 /* Caller must free response. 411 402 * Takes in strings which are space-separated lists of tokens … … 466 457 /* allocates memory and returns the string or null. 467 458 * caller must free the string. 468 * from Linux sprintf man page.469 459 */ 470 460 char *owl_sprintf(const char *fmt, ...) 471 461 { 472 int n, size = 100;473 char *p;474 462 va_list ap; 475 if ((p = owl_malloc (size)) == NULL) return (NULL); 476 while (1) { 477 /* Try to print in the allocated space. */ 478 va_start(ap, fmt); 479 n = vsnprintf (p, size, fmt, ap); 480 va_end(ap); 481 /* If that worked, return the string. */ 482 if (n > -1 && n < size) 483 return p; 484 /* Else try again with more space. */ 485 if (n > -1) /* glibc 2.1 */ 486 size = n+1; /* precisely what is needed */ 487 else /* glibc 2.0 */ 488 size *= 2; /* twice the old size */ 489 if ((p = owl_realloc (p, size)) == NULL) 490 return NULL; 491 } 492 } 463 char *ret = NULL; 464 va_start(ap, fmt); 465 ret = g_strdup_vprintf(fmt, ap); 466 va_end(ap); 467 return ret; 468 } 469 493 470 494 471 /* Return the owl color associated with the named color. Return -1
Note: See TracChangeset
for help on using the changeset viewer.