xref: /netbsd-src/external/ibm-public/postfix/dist/src/util/split_at.c (revision 41fbaed053f8fbfdf9d2a4ee0a7386a3c83f8505)
1*41fbaed0Stron /*	$NetBSD: split_at.c,v 1.1.1.1 2009/06/23 10:09:01 tron Exp $	*/
2*41fbaed0Stron 
3*41fbaed0Stron /*++
4*41fbaed0Stron /* NAME
5*41fbaed0Stron /*	split_at 3
6*41fbaed0Stron /* SUMMARY
7*41fbaed0Stron /*	trivial token splitter
8*41fbaed0Stron /* SYNOPSIS
9*41fbaed0Stron /*	#include <split_at.h>
10*41fbaed0Stron /*
11*41fbaed0Stron /*	char	*split_at(string, delimiter)
12*41fbaed0Stron /*	char	*string;
13*41fbaed0Stron /*	int	delimiter
14*41fbaed0Stron /*
15*41fbaed0Stron /*	char	*split_at_right(string, delimiter)
16*41fbaed0Stron /*	char	*string;
17*41fbaed0Stron /*	int	delimiter
18*41fbaed0Stron /* DESCRIPTION
19*41fbaed0Stron /*	split_at() null-terminates the \fIstring\fR at the first
20*41fbaed0Stron /*	occurrence of the \fIdelimiter\fR character found, and
21*41fbaed0Stron /*	returns a pointer to the remainder.
22*41fbaed0Stron /*
23*41fbaed0Stron /*	split_at_right() looks for the rightmost delimiter
24*41fbaed0Stron /*	occurrence, but is otherwise identical to split_at().
25*41fbaed0Stron /* DIAGNOSTICS
26*41fbaed0Stron /*	The result is a null pointer when the delimiter character
27*41fbaed0Stron /*	was not found.
28*41fbaed0Stron /* HISTORY
29*41fbaed0Stron /* .ad
30*41fbaed0Stron /* .fi
31*41fbaed0Stron /*	A split_at() routine appears in the TCP Wrapper software
32*41fbaed0Stron /*	by Wietse Venema.
33*41fbaed0Stron /* LICENSE
34*41fbaed0Stron /* .ad
35*41fbaed0Stron /* .fi
36*41fbaed0Stron /*	The Secure Mailer license must be distributed with this software.
37*41fbaed0Stron /* AUTHOR(S)
38*41fbaed0Stron /*	Wietse Venema
39*41fbaed0Stron /*	IBM T.J. Watson Research
40*41fbaed0Stron /*	P.O. Box 704
41*41fbaed0Stron /*	Yorktown Heights, NY 10598, USA
42*41fbaed0Stron /*--*/
43*41fbaed0Stron 
44*41fbaed0Stron /* System libraries */
45*41fbaed0Stron 
46*41fbaed0Stron #include <sys_defs.h>
47*41fbaed0Stron #include <string.h>
48*41fbaed0Stron 
49*41fbaed0Stron /* Utility library. */
50*41fbaed0Stron 
51*41fbaed0Stron #include "split_at.h"
52*41fbaed0Stron 
53*41fbaed0Stron /* split_at - break string at first delimiter, return remainder */
54*41fbaed0Stron 
split_at(char * string,int delimiter)55*41fbaed0Stron char   *split_at(char *string, int delimiter)
56*41fbaed0Stron {
57*41fbaed0Stron     char   *cp;
58*41fbaed0Stron 
59*41fbaed0Stron     if ((cp = strchr(string, delimiter)) != 0)
60*41fbaed0Stron 	*cp++ = 0;
61*41fbaed0Stron     return (cp);
62*41fbaed0Stron }
63*41fbaed0Stron 
64*41fbaed0Stron /* split_at_right - break string at last delimiter, return remainder */
65*41fbaed0Stron 
split_at_right(char * string,int delimiter)66*41fbaed0Stron char   *split_at_right(char *string, int delimiter)
67*41fbaed0Stron {
68*41fbaed0Stron     char   *cp;
69*41fbaed0Stron 
70*41fbaed0Stron     if ((cp = strrchr(string, delimiter)) != 0)
71*41fbaed0Stron 	*cp++ = 0;
72*41fbaed0Stron     return (cp);
73*41fbaed0Stron }
74