Changeset 503 for trunk/src/gmake/misc.c


Ignore:
Timestamp:
Sep 15, 2006, 7:09:38 AM (19 years ago)
Author:
bird
Message:

Untested merge with GNU Make v3.81 (vendor/gnumake/2005-05-16 -> vendor/gnumake/current).

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/gmake/misc.c

    r429 r503  
    11/* 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.
     2Copyright (C) 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997,
     31998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006 Free Software
     4Foundation, Inc.
    45This file is part of GNU Make.
    56
    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.  */
     7GNU Make is free software; you can redistribute it and/or modify it under the
     8terms of the GNU General Public License as published by the Free Software
     9Foundation; either version 2, or (at your option) any later version.
     10
     11GNU Make is distributed in the hope that it will be useful, but WITHOUT ANY
     12WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
     13A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
     14
     15You should have received a copy of the GNU General Public License along with
     16GNU Make; see the file COPYING.  If not, write to the Free Software
     17Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.  */
    2018
    2119#include "make.h"
     
    157155
    158156
    159 /* Remove comments from LINE.
    160    This is done by copying the text at LINE onto itself.  */
    161 
    162 void
    163 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 
    175157/* Print N spaces (used in debug for target-depth).  */
    176158
     
    512494
    513495
     496
     497/* Allocate a new `struct dep' with all fields initialized to 0.   */
     498
     499struct dep *
     500alloc_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
     510void
     511free_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
    514522/* Copy a chain of `struct dep', making a new chain
    515523   with the same contents as the old one.  */
    516524
    517525struct dep *
    518 copy_dep_chain (struct dep *d)
     526copy_dep_chain (const struct dep *d)
    519527{
    520528  register struct dep *c;
     
    526534      c = (struct dep *) xmalloc (sizeof (struct dep));
    527535      bcopy ((char *) d, (char *) c, sizeof (struct dep));
     536
    528537      if (c->name != 0)
    529538        c->name = xstrdup (c->name);
     539      if (c->stem != 0)
     540        c->stem = xstrdup (c->stem);
     541
    530542      c->next = 0;
    531543      if (firstnew == 0)
     
    540552}
    541553
     554/* Free a chain of 'struct dep'.  */
     555
     556void
     557free_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
    542567
    543568/* 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.  */
    545570
    546571void
     
    627652
    628653static void
    629 log_access (char *flavor)
     654log_access (const char *flavor)
    630655{
    631656  if (! ISDB (DB_JOBS))
     
    842867}
    843868#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
     902void
     903close_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.