Changeset 501 in kBuild for vendor/gnumake/current/misc.c
- Timestamp:
- Sep 15, 2006 2:30:32 AM (19 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
vendor/gnumake/current/misc.c
r280 r501 1 1 /* Miscellaneous generic support functions for GNU Make. 2 Copyright (C) 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995, 1997, 3 2002 Free Software Foundation, Inc. 2 Copyright (C) 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997, 3 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006 Free Software 4 Foundation, Inc. 4 5 This file is part of GNU Make. 5 6 6 GNU Make is free software; you can redistribute it and/or modify 7 it under the terms of the GNU General Public License as published by 8 the Free Software Foundation; either version 2, or (at your option) 9 any later version. 10 11 GNU Make is distributed in the hope that it will be useful, 12 but WITHOUT ANY WARRANTY; without even the implied warranty of 13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 GNU General Public License for more details. 15 16 You should have received a copy of the GNU General Public License 17 along with GNU Make; see the file COPYING. If not, write to 18 the Free Software Foundation, Inc., 59 Temple Place - Suite 330, 19 Boston, MA 02111-1307, USA. */ 7 GNU Make is free software; you can redistribute it and/or modify it under the 8 terms of the GNU General Public License as published by the Free Software 9 Foundation; either version 2, or (at your option) any later version. 10 11 GNU Make is distributed in the hope that it will be useful, but WITHOUT ANY 12 WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR 13 A PARTICULAR PURPOSE. See the GNU General Public License for more details. 14 15 You should have received a copy of the GNU General Public License along with 16 GNU Make; see the file COPYING. If not, write to the Free Software 17 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. */ 20 18 21 19 #include "make.h" … … 153 151 154 152 155 /* Remove comments from LINE.156 This is done by copying the text at LINE onto itself. */157 158 void159 remove_comments (char *line)160 {161 char *comment;162 163 comment = find_char_unquote (line, '#', 0, 0);164 165 if (comment != 0)166 /* Cut off the line at the #. */167 *comment = '\0';168 }169 170 171 153 /* Print N spaces (used in debug for target-depth). */ 172 154 … … 506 488 507 489 490 491 /* Allocate a new `struct dep' with all fields initialized to 0. */ 492 493 struct dep * 494 alloc_dep () 495 { 496 struct dep *d = (struct dep *) xmalloc (sizeof (struct dep)); 497 bzero ((char *) d, sizeof (struct dep)); 498 return d; 499 } 500 501 502 /* Free `struct dep' along with `name' and `stem'. */ 503 504 void 505 free_dep (struct dep *d) 506 { 507 if (d->name != 0) 508 free (d->name); 509 510 if (d->stem != 0) 511 free (d->stem); 512 513 free ((char *)d); 514 } 515 508 516 /* Copy a chain of `struct dep', making a new chain 509 517 with the same contents as the old one. */ 510 518 511 519 struct dep * 512 copy_dep_chain ( struct dep *d)520 copy_dep_chain (const struct dep *d) 513 521 { 514 522 register struct dep *c; … … 520 528 c = (struct dep *) xmalloc (sizeof (struct dep)); 521 529 bcopy ((char *) d, (char *) c, sizeof (struct dep)); 530 522 531 if (c->name != 0) 523 532 c->name = xstrdup (c->name); 533 if (c->stem != 0) 534 c->stem = xstrdup (c->stem); 535 524 536 c->next = 0; 525 537 if (firstnew == 0) … … 534 546 } 535 547 548 /* Free a chain of 'struct dep'. */ 549 550 void 551 free_dep_chain (struct dep *d) 552 { 553 while (d != 0) 554 { 555 struct dep *df = d; 556 d = d->next; 557 free_dep (df); 558 } 559 } 560 536 561 537 562 /* Free a chain of `struct nameseq'. Each nameseq->name is freed 538 as well. Can be used on `struct dep' chains.*/563 as well. For `struct dep' chains use free_dep_chain. */ 539 564 540 565 void … … 621 646 622 647 static void 623 log_access (c har *flavor)648 log_access (const char *flavor) 624 649 { 625 650 if (! ISDB (DB_JOBS)) … … 836 861 } 837 862 #endif 863 864 865 866 /* This code is stolen from gnulib. 867 If/when we abandon the requirement to work with K&R compilers, we can 868 remove this (and perhaps other parts of GNU make!) and migrate to using 869 gnulib directly. 870 871 This is called only through atexit(), which means die() has already been 872 invoked. So, call exit() here directly. Apparently that works...? 873 */ 874 875 /* Close standard output, exiting with status 'exit_failure' on failure. 876 If a program writes *anything* to stdout, that program should close 877 stdout and make sure that it succeeds before exiting. Otherwise, 878 suppose that you go to the extreme of checking the return status 879 of every function that does an explicit write to stdout. The last 880 printf can succeed in writing to the internal stream buffer, and yet 881 the fclose(stdout) could still fail (due e.g., to a disk full error) 882 when it tries to write out that buffered data. Thus, you would be 883 left with an incomplete output file and the offending program would 884 exit successfully. Even calling fflush is not always sufficient, 885 since some file systems (NFS and CODA) buffer written/flushed data 886 until an actual close call. 887 888 Besides, it's wasteful to check the return value from every call 889 that writes to stdout -- just let the internal stream state record 890 the failure. That's what the ferror test is checking below. 891 892 It's important to detect such failures and exit nonzero because many 893 tools (most notably `make' and other build-management systems) depend 894 on being able to detect failure in other tools via their exit status. */ 895 896 void 897 close_stdout (void) 898 { 899 int prev_fail = ferror (stdout); 900 int fclose_fail = fclose (stdout); 901 902 if (prev_fail || fclose_fail) 903 { 904 if (fclose_fail) 905 error (NILF, _("write error: %s"), strerror (errno)); 906 else 907 error (NILF, _("write error")); 908 exit (EXIT_FAILURE); 909 } 910 }
Note:
See TracChangeset
for help on using the changeset viewer.