Last change
on this file since 767 was 767, checked in by Bruno Cornec, 18 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 |
|
---|
17 | char *mr_strtok(char *instr, const char *delims, int *lastpos) {
|
---|
18 |
|
---|
19 | char *token = NULL;
|
---|
20 | char *strptr = NULL;
|
---|
21 | size_t pos1 = 0;
|
---|
22 | size_t pos2 = 0;
|
---|
23 |
|
---|
24 | if (strlen(instr) <= *lastpos) {
|
---|
25 | *lastpos = 0;
|
---|
26 | return token;
|
---|
27 | }
|
---|
28 |
|
---|
29 | strptr = instr + *lastpos;
|
---|
30 | pos2 = strspn(strptr, delims);
|
---|
31 | strptr += pos2;
|
---|
32 | pos1 = strcspn(strptr, delims);
|
---|
33 | token = malloc(sizeof(*token)*(pos1+1));
|
---|
34 | strncpy(token, strptr, pos1);
|
---|
35 | token[pos1] = '\0';
|
---|
36 | *lastpos = *lastpos + pos1 + pos2 + 1;
|
---|
37 |
|
---|
38 | return token;
|
---|
39 | }
|
---|
Note:
See
TracBrowser
for help on using the repository browser.