Last change
on this file since 768 was 768, checked in by Bruno Cornec, 18 years ago |
mktest generates again good results with the new split of libraries.
|
File size:
836 bytes
|
Rev | Line | |
---|
[767] | 1 | /*
|
---|
| 2 | $Id$
|
---|
| 3 | */
|
---|
| 4 |
|
---|
[768] | 5 | #include <stdio.h>
|
---|
| 6 | #include <string.h>
|
---|
| 7 |
|
---|
[767] | 8 | /* New functions safe from a memory manageemnt point of view */
|
---|
| 9 | /* Developped by Andree Leidenfrost */
|
---|
| 10 | /**
|
---|
| 11 | * Build a partition name from a drive and a partition number.
|
---|
| 12 | * @param instr
|
---|
| 13 | * @param delims
|
---|
| 14 | * @param lastpos
|
---|
| 15 | * @return @p
|
---|
| 16 | * @note this function allocates memory that needs to be freed by caller
|
---|
| 17 | **/
|
---|
| 18 |
|
---|
| 19 |
|
---|
| 20 | char *mr_strtok(char *instr, const char *delims, int *lastpos) {
|
---|
| 21 |
|
---|
| 22 | char *token = NULL;
|
---|
| 23 | char *strptr = NULL;
|
---|
| 24 | size_t pos1 = 0;
|
---|
| 25 | size_t pos2 = 0;
|
---|
| 26 |
|
---|
| 27 | if (strlen(instr) <= *lastpos) {
|
---|
| 28 | *lastpos = 0;
|
---|
| 29 | return token;
|
---|
| 30 | }
|
---|
| 31 |
|
---|
| 32 | strptr = instr + *lastpos;
|
---|
| 33 | pos2 = strspn(strptr, delims);
|
---|
| 34 | strptr += pos2;
|
---|
| 35 | pos1 = strcspn(strptr, delims);
|
---|
| 36 | token = malloc(sizeof(*token)*(pos1+1));
|
---|
| 37 | strncpy(token, strptr, pos1);
|
---|
| 38 | token[pos1] = '\0';
|
---|
| 39 | *lastpos = *lastpos + pos1 + pos2 + 1;
|
---|
| 40 |
|
---|
| 41 | return token;
|
---|
| 42 | }
|
---|
Note:
See
TracBrowser
for help on using the repository browser.