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

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [gnu-old/] [newlib-1.17.0/] [newlib/] [libc/] [argz/] [argz_create.c] - Blame information for rev 148

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

Line No. Rev Author Line
1 148 jeremybenn
/* Copyright (C) 2002 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 <argz.h>
8
#include <errno.h>
9
#include <sys/types.h>
10
#include <string.h>
11
#include <stdlib.h>
12
 
13
error_t
14
_DEFUN (argz_create, (argv, argz, argz_len),
15
       char *const argv[] _AND
16
       char **argz _AND
17
       size_t *argz_len)
18
{
19
  int argc = 0;
20
  int i = 0;
21
  int len = 0;
22
  char *iter;
23
 
24
  *argz_len = 0;
25
 
26
  if (*argv == NULL)
27
    {
28
      *argz = NULL;
29
      return 0;
30
    }
31
 
32
  while (argv[argc])
33
    {
34
      *argz_len += (strlen(argv[argc]) + 1);
35
      argc++;
36
    }
37
 
38
  /* There are argc strings to copy into argz. */
39
  if(!(*argz = (char *)malloc(*argz_len)))
40
    return ENOMEM;
41
 
42
  iter = *argz;
43
  for(i = 0; i < argc; i++)
44
    {
45
      len = strlen(argv[i]) + 1;
46
      memcpy(iter, argv[i], len);
47
      iter += len;
48
    }
49
  return 0;
50
}

powered by: WebSVN 2.1.0

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