[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: new module proposal: split

From: Mark D. Baushke
Subject: Re: new module proposal: split
Date: Tue, 05 Sep 2006 21:24:42 -0700

Hash: SHA1

Davide Angelocola <address@hidden> writes:

> On Tuesday 05 September 2006 22:01, Ben Pfaff wrote:
> > Davide Angelocola <address@hidden> writes:
> > > I'm proposing another new module for gnulib: split.
> > >
> > > The function signature is:
> > >   char *split(const char *str, char sep, int *argc);
> > >
> > > what do you think about?
> >
> > What does it do?
> split() splits the string "str" into an array of strings accordingly "sep" 
> and returns that array and it's size in *argc. The array is allocated via 
> malloc().

It is not clear, will this split do something like
like creating an *argv[] list which has a NULL
pointer as the last element in the array?

> > The function signature is:
> >   char *split(const char *str, char sep, int *argc);
> this signature is wrong:
> char **split(const char *str, char sep, int *argc);

Hmmm... is argc guarenteed to be positive? If not,
what does a negative argc mean? If so, would
'size_t *' be a better type for argc?

Does split() ever return NULL? Or, is it like the
functions that call error () when there are problems?

That is, does this code just core dump with the
NULL dereference:

    int argc;
    char **foo = split (NULL, '\0', &argc);

or is errno set and/or error() called?

    char **bar = split ("abcd", ' ', &argc);

Have you considered the desirability of multiple break characters?

Possibly something like strtok_r semantics to
break a string into a number of argv tokens based
on a string of possible break characters 
(e.g., " \t\n\r")

        -- Mark
Version: GnuPG v1.4.4 (FreeBSD)


reply via email to

[Prev in Thread] Current Thread [Next in Thread]