source: trunk/mondo/mondo/lib/mr_string.c @ 767

Last change on this file since 767 was 767, checked in by bruno, 13 years ago

Creating a new library common for all mondo binaries
This should become the only common library when we now which functions should go there

File size: 796 bytes
Line 
1/*
2   $Id$
3*/
4
5/* New functions safe from a memory manageemnt point of view */
6/* Developped by Andree Leidenfrost */
7/**
8 * Build a partition name from a drive and a partition number.
9 * @param instr
10 * @param delims
11 * @param lastpos
12 * @return @p
13 * @note this function allocates memory that needs to be freed by caller
14 **/
15
16
17char *mr_strtok(char *instr, const char *delims, int *lastpos) {
18
19char *token = NULL;
20char *strptr = NULL;
21size_t pos1 = 0;
22size_t pos2 = 0;
23
24if (strlen(instr) <= *lastpos) {
25    *lastpos = 0;
26    return token;
27}
28
29strptr = instr + *lastpos;
30pos2 = strspn(strptr, delims);
31strptr += pos2;
32pos1 = strcspn(strptr, delims);
33token = malloc(sizeof(*token)*(pos1+1));
34strncpy(token, strptr, pos1);
35token[pos1] = '\0';
36*lastpos = *lastpos + pos1 + pos2 + 1;
37
38return token;
39}
Note: See TracBrowser for help on using the repository browser.