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_create_sep.c] - Blame information for rev 365

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_sep, (string, sep, argz, argz_len),
15
       const char *string _AND
16
       int sep _AND
17
       char **argz _AND
18
       size_t *argz_len)
19
{
20
  int len = 0;
21
  int i = 0;
22
  int num_strings = 0;
23
  char delim[2];
24
  char *running = 0;
25
  char *old_running = 0;
26
  char *token = 0;
27
  char *iter = 0;
28
 
29
  *argz_len = 0;
30
 
31
  if (!string || string[0] == '\0')
32
    {
33
      *argz= NULL;
34
      return 0;
35
    }
36
 
37
  delim[0] = sep;
38
  delim[1] = '\0';
39
 
40
  running = strdup(string);
41
  old_running = running;
42
 
43
  while ((token = strsep(&running, delim)))
44
    {
45
      len = strlen(token);
46
      *argz_len += (len + 1);
47
      num_strings++;
48
    }
49
 
50
  if(!(*argz = (char *)malloc(*argz_len)))
51
    return ENOMEM;
52
 
53
  free(old_running);
54
 
55
  running = strdup(string);
56
  old_running = running;
57
 
58
  iter = *argz;
59
  for (i = 0; i < num_strings; i++)
60
    {
61
      token = strsep(&running, delim);
62
      len = strlen(token) + 1;
63
      memcpy(iter, token, len);
64
      iter += len;
65
    }
66
 
67
  free(old_running);
68
  return 0;
69
}

powered by: WebSVN 2.1.0

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