Back to index

glibc  2.9
Functions
argz-insert.c File Reference
#include <argz.h>
#include <string.h>
#include <stdlib.h>

Go to the source code of this file.

Functions

error_t __argz_insert (char **argz, size_t *argz_len, char *before, const char *entry)

Function Documentation

error_t __argz_insert ( char **  argz,
size_t argz_len,
char *  before,
const char *  entry 
)

Definition at line 32 of file argz-insert.c.

{
  if (! before)
    return __argz_add (argz, argz_len, entry);

  if (before < *argz || before >= *argz + *argz_len)
    return EINVAL;

  if (before > *argz)
    /* Make sure before is actually the beginning of an entry.  */
    while (before[-1])
      before--;

  {
    size_t after_before = *argz_len - (before - *argz);
    size_t entry_len = strlen  (entry) + 1;
    size_t new_argz_len = *argz_len + entry_len;
    char *new_argz = realloc (*argz, new_argz_len);

    if (new_argz)
      {
       before = new_argz + (before - *argz);
       memmove (before + entry_len, before, after_before);
       memmove (before, entry, entry_len);
       *argz = new_argz;
       *argz_len = new_argz_len;
       return 0;
      }
    else
      return ENOMEM;
  }
}

Here is the call graph for this function:

Here is the caller graph for this function: