VirtualBox

Changeset 501 in kBuild for vendor/gnumake/current/misc.c


Ignore:
Timestamp:
Sep 15, 2006 2:30:32 AM (19 years ago)
Author:
bird
Message:

Load make-3.81/ into vendor/gnumake/current.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • vendor/gnumake/current/misc.c

    r280 r501  
    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"
     
    153151
    154152
    155 /* Remove comments from LINE.
    156    This is done by copying the text at LINE onto itself.  */
    157 
    158 void
    159 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 
    171153/* Print N spaces (used in debug for target-depth).  */
    172154
     
    506488
    507489
     490
     491/* Allocate a new `struct dep' with all fields initialized to 0.   */
     492
     493struct dep *
     494alloc_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
     504void
     505free_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
    508516/* Copy a chain of `struct dep', making a new chain
    509517   with the same contents as the old one.  */
    510518
    511519struct dep *
    512 copy_dep_chain (struct dep *d)
     520copy_dep_chain (const struct dep *d)
    513521{
    514522  register struct dep *c;
     
    520528      c = (struct dep *) xmalloc (sizeof (struct dep));
    521529      bcopy ((char *) d, (char *) c, sizeof (struct dep));
     530
    522531      if (c->name != 0)
    523532        c->name = xstrdup (c->name);
     533      if (c->stem != 0)
     534        c->stem = xstrdup (c->stem);
     535
    524536      c->next = 0;
    525537      if (firstnew == 0)
     
    534546}
    535547
     548/* Free a chain of 'struct dep'.  */
     549
     550void
     551free_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
    536561
    537562/* 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.  */
    539564
    540565void
     
    621646
    622647static void
    623 log_access (char *flavor)
     648log_access (const char *flavor)
    624649{
    625650  if (! ISDB (DB_JOBS))
     
    836861}
    837862#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
     896void
     897close_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.

© 2025 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette