Cygwin: mmap: allow remapping part of an existing anonymous mapping
[newlib-cygwin.git] / newlib / libc / argz / argz_create.c
blob4ab622d28301320b7b4d61cede06b4a2181650a6
1 /* Copyright (C) 2002 by Red Hat, Incorporated. All rights reserved.
3 * Permission to use, copy, modify, and distribute this software
4 * is freely granted, provided that this notice is preserved.
5 */
7 #include <argz.h>
8 #include <errno.h>
9 #include <sys/types.h>
10 #include <string.h>
11 #include <stdlib.h>
13 error_t
14 argz_create (char *const argv[],
15 char **argz,
16 size_t *argz_len)
18 int argc = 0;
19 int i = 0;
20 int len = 0;
21 char *iter;
23 *argz_len = 0;
25 if (*argv == NULL)
27 *argz = NULL;
28 return 0;
31 while (argv[argc])
33 *argz_len += (strlen(argv[argc]) + 1);
34 argc++;
37 /* There are argc strings to copy into argz. */
38 if(!(*argz = (char *)malloc(*argz_len)))
39 return ENOMEM;
41 iter = *argz;
42 for(i = 0; i < argc; i++)
44 len = strlen(argv[i]) + 1;
45 memcpy(iter, argv[i], len);
46 iter += len;
48 return 0;