Exemple #1
0
/*
 * newvstrallocf - free existing string and then vstrallocf a new one.
 */
char *
debug_newvstrallocf(
    const char *file,
    int		line,
    char *	oldstr,
    const char *fmt,
    ...)
{
    size_t	size;
    char *	result;
    va_list	argp;

    result = debug_alloc(file, line, MIN_ALLOC);
    if (result != NULL) {

	arglist_start(argp, fmt);
	size = g_vsnprintf(result, MIN_ALLOC, fmt, argp);
	arglist_end(argp);

	if (size >= MIN_ALLOC) {
	    amfree(result);
	    result = debug_alloc(file, line, size + 1);

	    arglist_start(argp, fmt);
	    (void)g_vsnprintf(result, size + 1, fmt, argp);
	    arglist_end(argp);
	}
    }
    amfree(oldstr);
    return result;
}
Exemple #2
0
static char *
internal_vstralloc(
    const char *file,
    int		line,
    const char *str,
    va_list argp)
{
    char *next;
    char *result;
    int a, b;
    size_t total_len;
    const char *arg[MAX_VSTRALLOC_ARGS+1];
    size_t len[MAX_VSTRALLOC_ARGS+1];
    size_t l;

    if (str == NULL) {
	errordump(_("internal_vstralloc: str is NULL"));
	/*NOTREACHED*/
    }

    a = 0;
    arg[a] = str;
    l = strlen(str);
    total_len = len[a] = l;
    a++;

    while ((next = arglist_val(argp, char *)) != NULL) {
	if ((l = strlen(next)) == 0) {
	    continue;				/* minor optimisation */
	}
	if (a >= MAX_VSTRALLOC_ARGS) {
	    errordump(_("%s@%d: more than %d args to vstralloc"),
		      file ? file : _("(unknown)"),
		      file ? line : -1,
		      MAX_VSTRALLOC_ARGS);
	    /*NOTREACHED*/
	}
	arg[a] = next;
	len[a] = l;
	total_len += l;
	a++;
    }

    result = debug_alloc(file, line, total_len+1);

    next = result;
    for (b = 0; b < a; b++) {
	memcpy(next, arg[b], len[b]);
	next += len[b];
    }
    *next = '\0';

    return result;
}
Exemple #3
0
/*
 * stralloc - copies the given string into newly allocated memory.
 *            Just like strdup()!
 */
char *
debug_stralloc(
    const char *file,
    int		line,
    const char *str)
{
    char *addr;

    addr = debug_alloc(file, line, strlen(str) + 1);
    strcpy(addr, str);
    return (addr);
}
Exemple #4
0
void *shell_allocdebug(const char *file, unsigned int line, unsigned long size) {
  void *ptr = debug_alloc(file, line, size);

  /* exit if failed */
  if(ptr == NULL) {
    shell_error("malloc");
    exit(1);
  }

  /* return pointer otherwise */
  return ptr;
}
Exemple #5
0
/*
 * newalloc - free existing buffer and then alloc a new one.
 */
void *
debug_newalloc(
    const char *file,
    int		line,
    void *	old,
    size_t	size)
{
    char *addr;

    addr = debug_alloc(file, line, size);
    amfree(old);
    return addr;
}