Last change
on this file since 444 was
444,
checked in by satin@…, 6 years ago
|
add newlib,libalmos-mkh, restructure shared_syscalls.h and mini-libc
|
File size:
1.2 KB
|
Line | |
---|
1 | /* 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 | argz_create_sep (const char *string, |
---|
15 | int sep, |
---|
16 | char **argz, |
---|
17 | size_t *argz_len) |
---|
18 | { |
---|
19 | int len = 0; |
---|
20 | int i = 0; |
---|
21 | int num_strings = 0; |
---|
22 | char delim[2]; |
---|
23 | char *running = 0; |
---|
24 | char *old_running = 0; |
---|
25 | char *token = 0; |
---|
26 | char *iter = 0; |
---|
27 | |
---|
28 | *argz_len = 0; |
---|
29 | |
---|
30 | if (!string || string[0] == '\0') |
---|
31 | { |
---|
32 | *argz= NULL; |
---|
33 | return 0; |
---|
34 | } |
---|
35 | |
---|
36 | delim[0] = sep; |
---|
37 | delim[1] = '\0'; |
---|
38 | |
---|
39 | running = strdup(string); |
---|
40 | old_running = running; |
---|
41 | |
---|
42 | while ((token = strsep(&running, delim))) |
---|
43 | { |
---|
44 | len = strlen(token); |
---|
45 | *argz_len += (len + 1); |
---|
46 | num_strings++; |
---|
47 | } |
---|
48 | |
---|
49 | if(!(*argz = (char *)malloc(*argz_len))) |
---|
50 | return ENOMEM; |
---|
51 | |
---|
52 | free(old_running); |
---|
53 | |
---|
54 | running = strdup(string); |
---|
55 | old_running = running; |
---|
56 | |
---|
57 | iter = *argz; |
---|
58 | for (i = 0; i < num_strings; i++) |
---|
59 | { |
---|
60 | token = strsep(&running, delim); |
---|
61 | len = strlen(token) + 1; |
---|
62 | memcpy(iter, token, len); |
---|
63 | iter += len; |
---|
64 | } |
---|
65 | |
---|
66 | free(old_running); |
---|
67 | return 0; |
---|
68 | } |
---|
Note: See
TracBrowser
for help on using the repository browser.