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

Last change on this file since 768 was 768, checked in by Bruno Cornec, 14 years ago

mktest generates again good results with the new split of libraries.

File size: 836 bytes
Line 
1/*
2   $Id$
3*/
4
5#include <stdio.h>
6#include <string.h>
7
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
20char *mr_strtok(char *instr, const char *delims, int *lastpos) {
21
22char *token = NULL;
23char *strptr = NULL;
24size_t pos1 = 0;
25size_t pos2 = 0;
26
27if (strlen(instr) <= *lastpos) {
28    *lastpos = 0;
29    return token;
30}
31
32strptr = instr + *lastpos;
33pos2 = strspn(strptr, delims);
34strptr += pos2;
35pos1 = strcspn(strptr, delims);
36token = malloc(sizeof(*token)*(pos1+1));
37strncpy(token, strptr, pos1);
38token[pos1] = '\0';
39*lastpos = *lastpos + pos1 + pos2 + 1;
40
41return token;
42}
Note: See TracBrowser for help on using the repository browser.