Changeset 503 for trunk/src/gmake/misc.c
- Timestamp:
- Sep 15, 2006, 7:09:38 AM (19 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/gmake/misc.c
r429 r503 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" … … 157 155 158 156 159 /* Remove comments from LINE.160 This is done by copying the text at LINE onto itself. */161 162 void163 remove_comments (char *line)164 {165 char *comment;166 167 comment = find_char_unquote (line, '#', 0, 0);168 169 if (comment != 0)170 /* Cut off the line at the #. */171 *comment = '\0';172 }173 174 175 157 /* Print N spaces (used in debug for target-depth). */ 176 158 … … 512 494 513 495 496 497 /* Allocate a new `struct dep' with all fields initialized to 0. */ 498 499 struct dep * 500 alloc_dep () 501 { 502 struct dep *d = (struct dep *) xmalloc (sizeof (struct dep)); 503 bzero ((char *) d, sizeof (struct dep)); 504 return d; 505 } 506 507 508 /* Free `struct dep' along with `name' and `stem'. */ 509 510 void 511 free_dep (struct dep *d) 512 { 513 if (d->name != 0) 514 free (d->name); 515 516 if (d->stem != 0) 517 free (d->stem); 518 519 free ((char *)d); 520 } 521 514 522 /* Copy a chain of `struct dep', making a new chain 515 523 with the same contents as the old one. */ 516 524 517 525 struct dep * 518 copy_dep_chain ( struct dep *d)526 copy_dep_chain (const struct dep *d) 519 527 { 520 528 register struct dep *c; … … 526 534 c = (struct dep *) xmalloc (sizeof (struct dep)); 527 535 bcopy ((char *) d, (char *) c, sizeof (struct dep)); 536 528 537 if (c->name != 0) 529 538 c->name = xstrdup (c->name); 539 if (c->stem != 0) 540 c->stem = xstrdup (c->stem); 541 530 542 c->next = 0; 531 543 if (firstnew == 0) … … 540 552 } 541 553 554 /* Free a chain of 'struct dep'. */ 555 556 void 557 free_dep_chain (struct dep *d) 558 { 559 while (d != 0) 560 { 561 struct dep *df = d; 562 d = d->next; 563 free_dep (df); 564 } 565 } 566 542 567 543 568 /* Free a chain of `struct nameseq'. Each nameseq->name is freed 544 as well. Can be used on `struct dep' chains.*/569 as well. For `struct dep' chains use free_dep_chain. */ 545 570 546 571 void … … 627 652 628 653 static void 629 log_access (c har *flavor)654 log_access (const char *flavor) 630 655 { 631 656 if (! ISDB (DB_JOBS)) … … 842 867 } 843 868 #endif 869 870 871 872 /* This code is stolen from gnulib. 873 If/when we abandon the requirement to work with K&R compilers, we can 874 remove this (and perhaps other parts of GNU make!) and migrate to using 875 gnulib directly. 876 877 This is called only through atexit(), which means die() has already been 878 invoked. So, call exit() here directly. Apparently that works...? 879 */ 880 881 /* Close standard output, exiting with status 'exit_failure' on failure. 882 If a program writes *anything* to stdout, that program should close 883 stdout and make sure that it succeeds before exiting. Otherwise, 884 suppose that you go to the extreme of checking the return status 885 of every function that does an explicit write to stdout. The last 886 printf can succeed in writing to the internal stream buffer, and yet 887 the fclose(stdout) could still fail (due e.g., to a disk full error) 888 when it tries to write out that buffered data. Thus, you would be 889 left with an incomplete output file and the offending program would 890 exit successfully. Even calling fflush is not always sufficient, 891 since some file systems (NFS and CODA) buffer written/flushed data 892 until an actual close call. 893 894 Besides, it's wasteful to check the return value from every call 895 that writes to stdout -- just let the internal stream state record 896 the failure. That's what the ferror test is checking below. 897 898 It's important to detect such failures and exit nonzero because many 899 tools (most notably `make' and other build-management systems) depend 900 on being able to detect failure in other tools via their exit status. */ 901 902 void 903 close_stdout (void) 904 { 905 int prev_fail = ferror (stdout); 906 int fclose_fail = fclose (stdout); 907 908 if (prev_fail || fclose_fail) 909 { 910 if (fclose_fail) 911 error (NILF, _("write error: %s"), strerror (errno)); 912 else 913 error (NILF, _("write error")); 914 exit (EXIT_FAILURE); 915 } 916 }
Note:
See TracChangeset
for help on using the changeset viewer.