Changeset 900 for vendor/gnumake/current/misc.c
- Timestamp:
- May 23, 2007, 5:13:11 AM (18 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
vendor/gnumake/current/misc.c
r501 r900 162 162 163 163 164 /* Return a newly-allocated string whose contents165 concatenate those of s1, s2, s3. */164 /* Return a string whose contents concatenate those of s1, s2, s3. 165 This string lives in static, re-used memory. */ 166 166 167 167 char * … … 169 169 { 170 170 unsigned int len1, len2, len3; 171 char *result; 172 173 len1 = *s1 != '\0' ? strlen (s1) : 0; 174 len2 = *s2 != '\0' ? strlen (s2) : 0; 175 len3 = *s3 != '\0' ? strlen (s3) : 0; 176 177 result = (char *) xmalloc (len1 + len2 + len3 + 1); 178 179 if (*s1 != '\0') 180 bcopy (s1, result, len1); 181 if (*s2 != '\0') 182 bcopy (s2, result + len1, len2); 183 if (*s3 != '\0') 184 bcopy (s3, result + len1 + len2, len3); 185 *(result + len1 + len2 + len3) = '\0'; 171 static unsigned int rlen = 0; 172 static char *result = NULL; 173 174 len1 = (s1 && *s1 != '\0') ? strlen (s1) : 0; 175 len2 = (s2 && *s2 != '\0') ? strlen (s2) : 0; 176 len3 = (s3 && *s3 != '\0') ? strlen (s3) : 0; 177 178 if (len1 + len2 + len3 + 1 > rlen) 179 result = xrealloc (result, (rlen = len1 + len2 + len3 + 10)); 180 181 if (len1) 182 memcpy (result, s1, len1); 183 if (len2) 184 memcpy (result + len1, s2, len2); 185 if (len3) 186 memcpy (result + len1 + len2, s3, len3); 187 188 result[len1+len2+len3] = '\0'; 186 189 187 190 return result; … … 341 344 #undef xstrdup 342 345 343 char*346 void * 344 347 xmalloc (unsigned int size) 345 348 { 346 349 /* Make sure we don't allocate 0, for pre-ANSI libraries. */ 347 char *result = (char *)malloc (size ? size : 1);350 void *result = malloc (size ? size : 1); 348 351 if (result == 0) 349 352 fatal (NILF, _("virtual memory exhausted")); … … 352 355 353 356 354 char*355 xrealloc ( char*ptr, unsigned int size)356 { 357 char*result;357 void * 358 xrealloc (void *ptr, unsigned int size) 359 { 360 void *result; 358 361 359 362 /* Some older implementations of realloc() don't conform to ANSI. */ … … 375 378 result = strdup (ptr); 376 379 #else 377 result = (char *)malloc (strlen (ptr) + 1);380 result = malloc (strlen (ptr) + 1); 378 381 #endif 379 382 … … 384 387 return result; 385 388 #else 386 return strcpy (result, ptr);389 return strcpy (result, ptr); 387 390 #endif 388 391 } … … 393 396 savestring (const char *str, unsigned int length) 394 397 { 395 register char *out = (char *)xmalloc (length + 1);398 char *out = xmalloc (length + 1); 396 399 if (length > 0) 397 bcopy (str, out, length);400 memcpy (out, str, length); 398 401 out[length] = '\0'; 399 402 return out; … … 434 437 */ 435 438 char * 436 end_of_token_w32 (c har *s, char stopchar)437 { 438 registerchar *p = s;439 registerint backslash = 0;439 end_of_token_w32 (const char *s, char stopchar) 440 { 441 const char *p = s; 442 int backslash = 0; 440 443 441 444 while (*p != '\0' && *p != stopchar … … 455 458 } 456 459 457 return p;460 return (char *)p; 458 461 } 459 462 #endif … … 469 472 } 470 473 471 /* Find the next token in PTR; return the address of it, and store the 472 length of the token into *LENGTHPTR if LENGTHPTR is not nil. */ 474 /* Find the next token in PTR; return the address of it, and store the length 475 of the token into *LENGTHPTR if LENGTHPTR is not nil. Set *PTR to the end 476 of the token, so this function can be called repeatedly in a loop. */ 473 477 474 478 char * 475 find_next_token (char **ptr, unsigned int *lengthptr) 476 { 477 char *p = next_token (*ptr); 478 char *end; 479 find_next_token (const char **ptr, unsigned int *lengthptr) 480 { 481 const char *p = next_token (*ptr); 479 482 480 483 if (*p == '\0') 481 484 return 0; 482 485 483 *ptr = end = end_of_token (p);486 *ptr = end_of_token (p); 484 487 if (lengthptr != 0) 485 *lengthptr = end - p; 486 return p; 488 *lengthptr = *ptr - p; 489 490 return (char *)p; 487 491 } 488 492 … … 494 498 alloc_dep () 495 499 { 496 struct dep *d = (struct dep *)xmalloc (sizeof (struct dep));497 bzero ((char *) d, sizeof (struct dep));500 struct dep *d = xmalloc (sizeof (struct dep)); 501 memset (d, '\0', sizeof (struct dep)); 498 502 return d; 499 503 } … … 505 509 free_dep (struct dep *d) 506 510 { 507 if (d->name != 0) 508 free (d->name); 509 510 if (d->stem != 0) 511 free (d->stem); 512 513 free ((char *)d); 511 free (d); 514 512 } 515 513 … … 520 518 copy_dep_chain (const struct dep *d) 521 519 { 522 register struct dep *c;523 520 struct dep *firstnew = 0; 524 521 struct dep *lastnew = 0; … … 526 523 while (d != 0) 527 524 { 528 c = (struct dep *) xmalloc (sizeof (struct dep)); 529 bcopy ((char *) d, (char *) c, sizeof (struct dep)); 530 531 if (c->name != 0) 532 c->name = xstrdup (c->name); 533 if (c->stem != 0) 534 c->stem = xstrdup (c->stem); 525 struct dep *c = xmalloc (sizeof (struct dep)); 526 memcpy (c, d, sizeof (struct dep)); 535 527 536 528 c->next = 0; … … 559 551 } 560 552 561 562 /* Free a chain of `struct nameseq'. Each nameseq->name is freed 563 as well. For `struct dep' chains use free_dep_chain. */ 564 565 void 566 free_ns_chain (struct nameseq *n) 567 { 568 register struct nameseq *tmp; 569 570 while (n != 0) 571 { 572 if (n->name != 0) 573 free (n->name); 574 575 tmp = n; 576 577 n = n->next; 578 579 free (tmp); 580 } 581 582 } 583 584 #ifdef iAPX286 585 /* The losing compiler on this machine can't handle this macro. */ 586 587 char * 588 dep_name (struct dep *dep) 589 { 590 return dep->name == 0 ? dep->file->name : dep->name; 553 /* Free a chain of struct nameseq. 554 For struct dep chains use free_dep_chain. */ 555 556 void 557 free_ns_chain (struct nameseq *ns) 558 { 559 while (ns != 0) 560 { 561 struct nameseq *t = ns; 562 ns = ns->next; 563 free (t); 564 } 565 } 566 567 568 569 #if !HAVE_STRCASECMP && !HAVE_STRICMP && !HAVE_STRCMPI 570 571 /* If we don't have strcasecmp() (from POSIX), or anything that can substitute 572 for it, define our own version. */ 573 574 int 575 strcasecmp (const char *s1, const char *s2) 576 { 577 while (1) 578 { 579 int c1 = (int) *(s1++); 580 int c2 = (int) *(s2++); 581 582 if (isalpha (c1)) 583 c1 = tolower (c1); 584 if (isalpha (c2)) 585 c2 = tolower (c2); 586 587 if (c1 != '\0' && c1 == c2) 588 continue; 589 590 return (c1 - c2); 591 } 591 592 } 592 593 #endif
Note:
See TracChangeset
for help on using the changeset viewer.