- 01
- 02
- 03
- 04
- 05
- 06
- 07
- 08
- 09
- 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
- 47
- 48
- 49
- 50
- 51
- 52
int parse_path(const char *path,char ***names,int *size)
{
int ch=0; ch='/';
*size=0;
char *q; q=path+1;
char *s=0;
while(1)
{
s=strchr(q,ch);
if(s!=NULL)
{
(*size)++;
if(*size==1)
{
(*names)=malloc(sizeof(char*)*(*size));
if(!(*names)) return -1;
}
else
{
(*names)=realloc(*names,(*size)*sizeof(char*));
if(!(*names)) return -1;
}
*(*names+(*size)-1)=malloc((s-q+1)*sizeof(char));
if(!(*(*names+(*size)-1))) return -1;
memset(*(*names+(*size)-1),0,(s-q+1)*sizeof(char));
strncpy(*(*names+(*size)-1),q,s-q);
q=s+1;
}
else
{
if(*q!='\0')
{
ch='\0';
s=strchr(q,ch);
(*size)++;
(*names)=realloc(*names,(*size)*sizeof(char*));
if(!(*names)) return -1;
*(*names+(*size)-1)=malloc((s-q+1)*sizeof(char));
if(!(*(*names+(*size)-1))) return -1;
memset(*(*names+(*size)-1),0,(s-q+1)*sizeof(char));
strncpy(*(*names+(*size)-1),q,s-q);
}
break;
}
}
return 0;
}