Changeset 8397 for branches/cu-security-branch/src/common/misc/str-utils.c
- Timestamp:
- 06/18/10 20:02:50 (3 years ago)
- Location:
- branches/cu-security-branch
- Files:
-
- 3 modified
-
. (modified) (1 prop)
-
src/common/misc (modified) (1 prop)
-
src/common/misc/str-utils.c (modified) (6 diffs)
Legend:
- Unmodified
- Added
- Removed
-
branches/cu-security-branch
- Property svn:ignore
-
old new 3 3 aclocal.m4 4 4 autom4te.cache 5 config.status6 Makefile7 pvfs2-config.h8 module.mk
-
- Property svn:ignore
-
branches/cu-security-branch/src/common/misc
- Property svn:ignore deleted
-
branches/cu-security-branch/src/common/misc/str-utils.c
r8330 r8397 144 144 145 145 /* initialize our starting position */ 146 if (*inout_segp == NULL) { 147 ptr = pathname; 148 } 149 else if (*opaquep != NULL) { 150 /* replace the '/', point just past it */ 151 ptr = (char *) *opaquep; 152 *ptr = '/'; 153 ptr++; 154 } 155 else return -1; /* NULL *opaquep indicates last segment returned last time */ 146 if (*inout_segp == NULL) 147 { 148 ptr = pathname; 149 } 150 else if (*opaquep != NULL) 151 { 152 /* replace the '/', point just past it */ 153 ptr = (char *) *opaquep; 154 *ptr = '/'; 155 ptr++; 156 } 157 else 158 return -1; /* NULL *opaquep indicates last segment returned last time */ 156 159 157 160 /* at this point, the string is back in its original state */ 158 161 159 162 /* jump past separators */ 160 while ((*ptr != '\0') && (*ptr == '/')) ptr++; 161 if (*ptr == '\0') return -1; /* all that was left was trailing '/'s */ 163 while ((*ptr != '\0') && (*ptr == '/')) 164 ptr++; 165 if (*ptr == '\0') 166 return -1; /* all that was left was trailing '/'s */ 162 167 163 168 *inout_segp = ptr; 164 169 165 170 /* find next separator */ 166 while ((*ptr != '\0') && (*ptr != '/')) ptr++; 167 if (*ptr == '\0') *opaquep = NULL; /* indicate last segment */ 168 else { 169 /* terminate segment and save position of terminator */ 170 *ptr = '\0'; 171 *opaquep = ptr; 171 while ((*ptr != '\0') && (*ptr != '/')) 172 ptr++; 173 if (*ptr == '\0') 174 *opaquep = NULL; /* indicate last segment */ 175 else 176 { 177 /* terminate segment and save position of terminator */ 178 *ptr = '\0'; 179 *opaquep = ptr; 172 180 } 173 181 return 0; … … 312 320 for(i =0; i < pathlen; i++) 313 321 { 314 if (path[i] == '/')315 {316 num_slashes_seen++;317 if (num_slashes_seen > skip)318 {319 break;320 }321 }322 if (path[i] == '/') 323 { 324 num_slashes_seen++; 325 if (num_slashes_seen > skip) 326 { 327 break; 328 } 329 } 322 330 } 323 331 … … 356 364 if (!comma_list || !tokens) 357 365 { 358 return (0);366 return (0); 359 367 } 360 368 … … 363 371 while ((holder = index(holder, ','))) 364 372 { 365 tokencount++;366 holder++;373 tokencount++; 374 holder++; 367 375 } 368 376 … … 380 388 if (!(*tokens)) 381 389 { 382 return 0;390 return 0; 383 391 } 384 392 385 393 if(1 == tokencount) 386 394 { 387 (*tokens)[0] = strdup(comma_list);388 if(!(*tokens)[0])389 {390 tokencount = 0;391 goto failure;392 }393 return tokencount;395 (*tokens)[0] = strdup(comma_list); 396 if(!(*tokens)[0]) 397 { 398 tokencount = 0; 399 goto failure; 400 } 401 return tokencount; 394 402 } 395 403 … … 399 407 for (i = 0; i < tokencount && holder; i++) 400 408 { 401 holder2 = index(holder, ',');402 if (!holder2)403 {404 holder2 = end;405 }409 holder2 = index(holder, ','); 410 if (!holder2) 411 { 412 holder2 = end; 413 } 406 414 if (holder2 - holder == 0) { 407 415 retval--; 408 goto out;409 } 410 (*tokens)[i] = (char *) malloc((holder2 - holder) + 1);411 if (!(*tokens)[i])412 {413 goto failure;414 }415 strncpy((*tokens)[i], holder, (holder2 - holder));416 (*tokens)[i][(holder2 - holder)] = '\0';416 return (retval); 417 } 418 (*tokens)[i] = (char *) malloc((holder2 - holder) + 1); 419 if (!(*tokens)[i]) 420 { 421 goto failure; 422 } 423 strncpy((*tokens)[i], holder, (holder2 - holder)); 424 (*tokens)[i][(holder2 - holder)] = '\0'; 417 425 assert(strlen((*tokens)[i]) != 0); 418 holder = holder2 + 1; 419 } 420 421 out: 426 holder = holder2 + 1; 427 } 428 422 429 return (retval); 423 430 424 failure:431 failure: 425 432 426 433 /* free up any memory we allocated if we failed */ 427 434 if (*tokens) 428 435 { 429 for (i = 0; i < tokencount; i++)430 {431 if ((*tokens)[i])432 {433 free((*tokens)[i]);434 }435 }436 free(*tokens);436 for (i = 0; i < tokencount; i++) 437 { 438 if ((*tokens)[i]) 439 { 440 free((*tokens)[i]); 441 } 442 } 443 free(*tokens); 437 444 } 438 445 return (0);
