xref: /aosp_15_r20/external/ltp/pan/splitstr.h (revision 49cdfc7efb34551c7342be41a7384b9c40d7cab7)
1*49cdfc7eSAndroid Build Coastguard Worker #ifndef _SPLITSTR_H_
2*49cdfc7eSAndroid Build Coastguard Worker #define _SPLITSTR_H_
3*49cdfc7eSAndroid Build Coastguard Worker /*
4*49cdfc7eSAndroid Build Coastguard Worker  * Synopsis
5*49cdfc7eSAndroid Build Coastguard Worker  *
6*49cdfc7eSAndroid Build Coastguard Worker  * const char **splitstr(const char *str, const char *separator, int *argcount)
7*49cdfc7eSAndroid Build Coastguard Worker  *
8*49cdfc7eSAndroid Build Coastguard Worker  * Description
9*49cdfc7eSAndroid Build Coastguard Worker  * This function splits a string (str) into components that are separated by
10*49cdfc7eSAndroid Build Coastguard Worker  * one or more of the characters in the (separator) string.  An array of
11*49cdfc7eSAndroid Build Coastguard Worker  * strings is returned, along with argcount being set to the number of strings
12*49cdfc7eSAndroid Build Coastguard Worker  * found.  Argcount can be NULL.  There will always be a NULL element in the
13*49cdfc7eSAndroid Build Coastguard Worker  * array after the last valid element.  If an error occurs, NULL will be
14*49cdfc7eSAndroid Build Coastguard Worker  * returned and argcount will be set to zero.
15*49cdfc7eSAndroid Build Coastguard Worker  *
16*49cdfc7eSAndroid Build Coastguard Worker  * To rid yourself of the memory allocated for splitstr(), pass the return
17*49cdfc7eSAndroid Build Coastguard Worker  * value from splitstr() unmodified to splitstr_free():
18*49cdfc7eSAndroid Build Coastguard Worker  *
19*49cdfc7eSAndroid Build Coastguard Worker  * void splitstr_free( const char ** return_from_splitstr );
20*49cdfc7eSAndroid Build Coastguard Worker  *
21*49cdfc7eSAndroid Build Coastguard Worker  */
22*49cdfc7eSAndroid Build Coastguard Worker const char **
23*49cdfc7eSAndroid Build Coastguard Worker splitstr(const char *, const char *, int *);
24*49cdfc7eSAndroid Build Coastguard Worker 
25*49cdfc7eSAndroid Build Coastguard Worker /*
26*49cdfc7eSAndroid Build Coastguard Worker  * splitster_free( const char ** )
27*49cdfc7eSAndroid Build Coastguard Worker  *
28*49cdfc7eSAndroid Build Coastguard Worker  * This takes the return value from splitster() and free()s memory
29*49cdfc7eSAndroid Build Coastguard Worker  * allocated by splitster.  Assuming: ret=splitster(...), this
30*49cdfc7eSAndroid Build Coastguard Worker  * requires that ret and *ret returned from splitster() have not
31*49cdfc7eSAndroid Build Coastguard Worker  * been modified.
32*49cdfc7eSAndroid Build Coastguard Worker  */
33*49cdfc7eSAndroid Build Coastguard Worker void
34*49cdfc7eSAndroid Build Coastguard Worker splitstr_free( const char ** );
35*49cdfc7eSAndroid Build Coastguard Worker 
36*49cdfc7eSAndroid Build Coastguard Worker #endif
37