2005-09-09 05:07:43 +08:00
|
|
|
/* Copyright (C) 2002, 2005 by Red Hat, Incorporated. All rights reserved.
|
2002-06-15 04:51:09 +08:00
|
|
|
*
|
|
|
|
* Permission to use, copy, modify, and distribute this software
|
|
|
|
* is freely granted, provided that this notice is preserved.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <errno.h>
|
|
|
|
#include <sys/types.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <argz.h>
|
|
|
|
|
|
|
|
error_t
|
2003-06-07 03:57:51 +08:00
|
|
|
_DEFUN (argz_insert, (argz, argz_len, before, entry),
|
|
|
|
char **argz _AND
|
|
|
|
size_t *argz_len _AND
|
|
|
|
char *before _AND
|
|
|
|
const char *entry)
|
2002-06-15 04:51:09 +08:00
|
|
|
{
|
|
|
|
int len = 0;
|
|
|
|
|
|
|
|
if (before == NULL)
|
2005-09-09 05:07:43 +08:00
|
|
|
return argz_add(argz, argz_len, entry);
|
2002-06-15 04:51:09 +08:00
|
|
|
|
|
|
|
if (before < *argz || before >= *argz + *argz_len)
|
|
|
|
return EINVAL;
|
|
|
|
|
|
|
|
while (before != *argz && before[-1])
|
|
|
|
before--;
|
|
|
|
|
|
|
|
len = strlen(entry) + 1;
|
|
|
|
|
|
|
|
if(!(*argz = (char *)realloc(*argz, *argz_len + len)))
|
|
|
|
return ENOMEM;
|
|
|
|
|
|
|
|
memmove(before + len, before, *argz + *argz_len - before);
|
|
|
|
memcpy(before, entry, len);
|
|
|
|
|
|
|
|
*argz_len += len;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|