#include <stdio.h>#include <stdlib.h>#include <string.h>#include <stdarg.h>#include "utility.h"#include "xnprintf.h"
Go to the source code of this file.
Defines | |
| #define | DO_FREE 1 |
| #define | DO_NOT_FREE 0 |
Functions | |
| char * | dstring_sprintf (const char *fmt,...) |
| char * | dstring_append_common (char *s1, char *s2, int do_free) |
| char * | dstring_append (char *s1, char *s2) |
| char * | dstring_append_free (char *s1, char *s2) |
This file contains dynamic string handling functions.
Definition in file dstring_sprintf.c.
| #define DO_FREE 1 |
Definition at line 43 of file dstring_sprintf.c.
| #define DO_NOT_FREE 0 |
Definition at line 44 of file dstring_sprintf.c.
| char* dstring_append | ( | char * | s1, | |
| char * | s2 | |||
| ) |
Appends s2 to s1 without freeing s2.
| s1 | -- the string to which we will append | |
| s2 | -- the string to append to s1 |
Definition at line 76 of file dstring_sprintf.c.
{
return(dstring_append_common(s1,s2,DO_NOT_FREE));
}


| char* dstring_append_common | ( | char * | s1, | |
| char * | s2, | |||
| int | do_free | |||
| ) |
Common routine for the dstring_append functions. Appends s2 to s1.
| s1 | -- the string to which we will append | |
| s2 | -- the string to append to s1 | |
| do_free | -- if TRUE, free s2 after appending. otherwise, do not free s2. |
Definition at line 58 of file dstring_sprintf.c.
{
if ((s1 = realloc(s1, strlen(s1)+strlen(s2)+1)) == NULL)
return NULL;
s1 = strcat(s1,s2);
if (do_free && s2!=NULL) free(s2);
return(s1);
}

| char* dstring_append_free | ( | char * | s1, | |
| char * | s2 | |||
| ) |
Appends s2 to s1 and frees s2.
| s1 | -- the string to which we will append | |
| s2 | -- the string to append to s1 |
Definition at line 90 of file dstring_sprintf.c.
{
return(dstring_append_common(s1,s2,DO_FREE));
}


| char* dstring_sprintf | ( | const char * | fmt, | |
| ... | ||||
| ) |
Taken from the Linux man page of snprintf. To allocate a sufficiently large string and print into it (code correct for both glibc 2.0 and glibc 2.1). This string needs to be deallocated manually.
| fmt | -- the format string (same as printf) | |
| ... | -- the arguments to be printed |
Definition at line 31 of file dstring_sprintf.c.
{
char *buf;
int status;
va_list ap;
va_start (ap, fmt);
status = vasprintf (&buf, fmt, ap);
va_end (ap);
return(buf);
}
1.6.3-20100507