OpenCores
URL https://opencores.org/ocsvn/openrisc_me/openrisc_me/trunk

Subversion Repositories openrisc_me

[/] [openrisc/] [trunk/] [gnu-src/] [newlib-1.17.0/] [newlib/] [libc/] [argz/] [argz_insert.c] - Blame information for rev 326

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 148 jeremybenn
/* Copyright (C) 2002, 2005 by  Red Hat, Incorporated. All rights reserved.
2
 *
3
 * Permission to use, copy, modify, and distribute this software
4
 * is freely granted, provided that this notice is preserved.
5
 */
6
 
7
#include <errno.h>
8
#include <sys/types.h>
9
#include <string.h>
10
#include <stdlib.h>
11
#include <argz.h>
12
#define __need_ptrdiff_t
13
#include <stddef.h>
14
 
15
error_t
16
_DEFUN (argz_insert, (argz, argz_len, before, entry),
17
       char **argz _AND
18
       size_t *argz_len _AND
19
       char *before _AND
20
       const char *entry)
21
{
22
  int len = 0;
23
  ptrdiff_t delta;
24
 
25
  if (before == NULL)
26
    return argz_add(argz, argz_len, entry);
27
 
28
  if (before < *argz || before >= *argz + *argz_len)
29
    return EINVAL;
30
 
31
  while (before != *argz && before[-1])
32
    before--;
33
 
34
  /* delta will always be non-negative, and < *argz_len */
35
  delta = before - *argz;
36
 
37
  len = strlen(entry) + 1;
38
 
39
  if(!(*argz = (char *)realloc(*argz, *argz_len + len)))
40
    return ENOMEM;
41
 
42
  memmove(*argz + delta + len, *argz + delta,  *argz_len - delta);
43
  memcpy(*argz + delta, entry, len);
44
 
45
  *argz_len += len;
46
 
47
  return 0;
48
}

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.