Changeset 2591 for trunk/src/kmk/misc.c
- Timestamp:
- Jun 17, 2012, 10:45:31 PM (13 years ago)
- Location:
- trunk/src/kmk
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/kmk
- Property svn:ignore
-
old new 13 13 stamp-* 14 14 makebook* 15 15 16 .*gdbinit 17 .gdb_history 18 16 19 *.dep 17 20 *.dvi … … 31 34 *.pg 32 35 *.pgs 36 33 37 README 34 38 README.DOS 35 39 README.W32 40 README.OS2 36 41 aclocal.m4 37 42 autom4te.cache … … 52 57 config.h.W32 53 58 config.h-vms 59 54 60 loadavg 55 61 loadavg.c 56 62 make 63 57 64 .deps 58 65 .dep_segment 66 ID 67 TAGS 68 59 69 _* 60 70 sun4 … … 72 82 sol2 73 83 i486-linux 84 74 85 customs 86 75 87 install-sh 76 88 mkinstalldirs 89 90 .directive.asc
-
- Property svn:ignore
-
trunk/src/kmk/misc.c
r2548 r2591 1 1 /* Miscellaneous generic support functions for GNU Make. 2 2 Copyright (C) 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997, 3 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007 Free Software4 Foundation, Inc.3 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 4 2010 Free Software Foundation, Inc. 5 5 This file is part of GNU Make. 6 6 … … 166 166 ++in; 167 167 168 /* If the newline is quoted, discard following whitespace 169 and any preceding whitespace; leave just one space. */ 168 /* If the newline is escaped, discard following whitespace leaving just 169 one space. POSIX requires that each backslash/newline/following 170 whitespace sequence be reduced to a single space. */ 170 171 if (backslash) 171 172 { 172 173 in = next_token (in); 174 /* Removing this loop will fix Savannah bug #16670: do we want to? */ 173 175 while (out > line && isblank ((unsigned char)out[-1])) 174 176 --out; … … 218 220 219 221 220 /* Return a string whose contents concatenate th ose of s1, s2, s3.222 /* Return a string whose contents concatenate the NUM strings provided 221 223 This string lives in static, re-used memory. */ 222 224 223 char * 224 concat (const char *s1, const char *s2, const char *s3) 225 { 226 unsigned int len1, len2, len3; 225 const char * 226 #if HAVE_ANSI_COMPILER && USE_VARIADIC && HAVE_STDARG_H 227 concat (unsigned int num, ...) 228 #else 229 concat (num, va_alist) 230 unsigned int num; 231 va_dcl 232 #endif 233 { 227 234 static unsigned int rlen = 0; 228 235 static char *result = NULL; 229 230 len1 = (s1 && *s1 != '\0') ? strlen (s1) : 0; 231 len2 = (s2 && *s2 != '\0') ? strlen (s2) : 0; 232 len3 = (s3 && *s3 != '\0') ? strlen (s3) : 0; 233 234 if (len1 + len2 + len3 + 1 > rlen) 235 result = xrealloc (result, (rlen = len1 + len2 + len3 + 10)); 236 237 if (len1) 238 memcpy (result, s1, len1); 239 if (len2) 240 memcpy (result + len1, s2, len2); 241 if (len3) 242 memcpy (result + len1 + len2, s3, len3); 243 244 result[len1+len2+len3] = '\0'; 236 unsigned int ri = 0; /* bird: must be unsigned */ 237 238 #if USE_VARIADIC 239 va_list args; 240 #endif 241 242 VA_START (args, num); 243 244 while (num-- > 0) 245 { 246 const char *s = va_arg (args, const char *); 247 unsigned int l = s ? strlen (s) : 0; 248 249 if (l == 0) 250 continue; 251 252 if (ri + l > rlen) 253 { 254 rlen = ((rlen ? rlen : 60) + l) * 2; 255 result = xrealloc (result, rlen); 256 } 257 258 memcpy (result + ri, s, l); 259 ri += l; 260 } 261 262 VA_END (args); 263 264 /* Get some more memory if we don't have enough space for the 265 terminating '\0'. */ 266 if (ri == rlen) 267 { 268 rlen = (rlen ? rlen : 60) * 2; 269 result = xrealloc (result, rlen); 270 } 271 272 result[ri] = '\0'; 245 273 246 274 return result; … … 397 425 398 426 #undef xmalloc 427 #undef xcalloc 399 428 #undef xrealloc 400 429 #undef xstrdup … … 403 432 xmalloc (unsigned int size) 404 433 { 405 /* Make sure we don't allocate 0, for pre- ANSI libraries. */434 /* Make sure we don't allocate 0, for pre-ISO implementations. */ 406 435 void *result = malloc (size ? size : 1); 407 436 if (result == 0) … … 415 444 make_stats_allocated += size; 416 445 #endif 446 return result; 447 } 448 449 450 void * 451 xcalloc (unsigned int size) 452 { 453 /* Make sure we don't allocate 0, for pre-ISO implementations. */ 454 void *result = calloc (size ? size : 1, 1); 455 if (result == 0) 456 fatal (NILF, _("virtual memory exhausted")); 417 457 return result; 418 458 } … … 432 472 #endif 433 473 434 /* Some older implementations of realloc() don't conform to ANSI. */474 /* Some older implementations of realloc() don't conform to ISO. */ 435 475 if (! size) 436 476 size = 1; … … 480 520 481 521 char * 482 savestring (const char *str, unsigned int length) 483 { 484 char *out = xmalloc (length + 1); 522 xstrndup (const char *str, unsigned int length) 523 { 524 char *result; 525 526 #if defined(HAVE_STRNDUP) && !defined(KMK) 527 result = strndup (str, length); 528 if (result == 0) 529 fatal (NILF, _("virtual memory exhausted")); 530 #else 531 result = xmalloc (length + 1); 485 532 if (length > 0) 486 memcpy (out, str, length); 487 out[length] = '\0'; 488 return out; 533 strncpy (result, str, length); 534 result[length] = '\0'; 535 #endif 536 537 return result; 489 538 } 490 539 … … 786 835 787 836 788 /* Allocate a new `struct dep' with all fields initialized to 0. */ 789 790 struct dep * 791 alloc_dep () 792 { 793 #ifndef CONFIG_WITH_ALLOC_CACHES 794 struct dep *d = xmalloc (sizeof (struct dep)); 795 memset (d, '\0', sizeof (struct dep)); 796 return d; 797 #else 798 return (struct dep *) alloccache_calloc (&dep_cache); 799 #endif 800 } 801 802 803 /* Free `struct dep' along with `name' and `stem'. */ 804 805 void 806 free_dep (struct dep *d) 807 { 808 #ifndef CONFIG_WITH_ALLOC_CACHES 809 free (d); 810 #else 811 alloccache_free (&dep_cache, d); 812 #endif 813 } 814 815 /* Copy a chain of `struct dep', making a new chain 816 with the same contents as the old one. */ 837 /* Copy a chain of `struct dep'. For 2nd expansion deps, dup the name. */ 817 838 818 839 struct dep * … … 827 848 struct dep *c = xmalloc (sizeof (struct dep)); 828 849 #else 829 struct dep *c = (struct dep *) alloccache_alloc(&dep_cache);850 struct dep *c = alloccache_alloc(&dep_cache); 830 851 #endif 831 852 memcpy (c, d, sizeof (struct dep)); 853 854 /** @todo KMK: Check if we need this duplication! */ 855 if (c->need_2nd_expansion) 856 c->name = xstrdup (c->name); 832 857 833 858 c->next = 0; … … 852 877 struct dep *df = d; 853 878 d = d->next; 854 #ifndef CONFIG_WITH_ALLOC_CACHES855 879 free_dep (df); 856 #else857 alloccache_free (&dep_cache, df);858 #endif859 880 } 860 881 } … … 903 924 return (c1 - c2); 904 925 } 926 } 927 #endif 928 929 #if !HAVE_STRNCASECMP && !HAVE_STRNICMP && !HAVE_STRNCMPI 930 931 /* If we don't have strncasecmp() (from POSIX), or anything that can 932 substitute for it, define our own version. */ 933 934 int 935 strncasecmp (const char *s1, const char *s2, int n) 936 { 937 while (n-- > 0) 938 { 939 int c1 = (int) *(s1++); 940 int c2 = (int) *(s2++); 941 942 if (isalpha (c1)) 943 c1 = tolower (c1); 944 if (isalpha (c2)) 945 c2 = tolower (c2); 946 947 if (c1 != '\0' && c1 == c2) 948 continue; 949 950 return (c1 - c2); 951 } 952 953 return 0; 905 954 } 906 955 #endif … … 1234 1283 1235 1284 malloc_zone_statistics (NULL, &s); 1236 printf (_("\n# CRT Heap: %zu bytes in use, in %u blocks, avg %zu bytes/block\n"), 1237 s.size_in_use, s.blocks_in_use, s.size_in_use / s.blocks_in_use); 1238 printf (_("# %zu bytes max in use (high water mark)\n"), 1239 s.max_size_in_use); 1240 printf (_("# %zu bytes reserved, %zu bytes free (estimate)\n"), 1241 s.size_allocated, s.size_allocated - s.size_in_use); 1285 printf (_("\n# CRT Heap: %u bytes in use, in %u blocks, avg %u bytes/block\n"), 1286 (unsigned)s.size_in_use, (unsigned)s.blocks_in_use, 1287 (unsigned)(s.size_in_use / s.blocks_in_use)); 1288 printf (_("# %u bytes max in use (high water mark)\n"), 1289 (unsigned)s.max_size_in_use); 1290 printf (_("# %u bytes reserved, %u bytes free (estimate)\n"), 1291 (unsigned)s.size_allocated, 1292 (unsigned)(s.size_allocated - s.size_in_use)); 1242 1293 # endif /* __APPLE__ */ 1243 1294 … … 1374 1425 format_elapsed_nano (char *buf, size_t size, big_int ts) 1375 1426 { 1376 intsz;1427 unsigned sz; 1377 1428 if (ts < 1000) 1378 1429 sz = sprintf (buf, "%uns", (unsigned)ts); … … 1407 1458 } 1408 1459 if (sz >= size) 1409 fatal (NILF, _("format_elapsed_nano buffer overflow: % d written, %dbuffer"),1410 sz, size);1460 fatal (NILF, _("format_elapsed_nano buffer overflow: %u written, %lu buffer"), 1461 sz, (unsigned long)size); 1411 1462 return sz; 1412 1463 }
Note:
See TracChangeset
for help on using the changeset viewer.