File: strsep.c

package info (click to toggle)
loki 2.4.7.4-12
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 4,172 kB
  • sloc: ansic: 38,653; yacc: 4,974; lex: 946; makefile: 333; sh: 100
file content (46 lines) | stat: -rw-r--r-- 1,667 bytes parent folder | download | duplicates (7)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
/****************************************************************************
 *                                                                          *
 *     Loki - Programs for genetic analysis of complex traits using MCMC    *
 *                                                                          *
 *                   Simon Heath - CNG, Evry                                *
 *                                                                          *
 *                        March 2003                                        *
 *                                                                          *
 * strsep.c:                                                                *
 *                                                                          *
 * Find first occurrence of a token in a string                             *
 *                                                                          *
 * Copyright (C) Simon C. Heath 2003                                        *
 * This is free software.  You can distribute it and/or modify it           *
 * under the terms of the Modified BSD license, see the file COPYING        *
 *                                                                          *
 ****************************************************************************/

#include <stdlib.h>
#include <stdio.h>
#include "libhdr.h"

char *my_strsep(char **s,const char *d)
{
	char *p,*s1,c,c1;
	const char *dp;
	
	p=*s;
	if(p) {
		s1=p;
		for(;;) {
			c=*p++;
			dp=d;
			do {
				c1=*dp++;
				if(c1==c) {
					if(!c) p=0;
					else p[-1]=0;
					*s=p;
					return s1;
				}
			} while(c1);
		}
	}
	return p;
}