Imported Upstream version 4.4
[platform/upstream/make.git] / src / makeint.h
index c428a36..c726abe 100644 (file)
@@ -1,5 +1,5 @@
 /* Miscellaneous global declarations and portability cruft for GNU Make.
-Copyright (C) 1988-2020 Free Software Foundation, Inc.
+Copyright (C) 1988-2022 Free Software Foundation, Inc.
 This file is part of GNU Make.
 
 GNU Make is free software; you can redistribute it and/or modify it under the
@@ -12,7 +12,7 @@ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
 A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
 
 You should have received a copy of the GNU General Public License along with
-this program.  If not, see <http://www.gnu.org/licenses/>.  */
+this program.  If not, see <https://www.gnu.org/licenses/>.  */
 
 /* We use <config.h> instead of "config.h" so that a compilation
    using -I. -I$srcdir will use ./config.h rather than $srcdir/config.h
@@ -41,6 +41,21 @@ char *alloca ();
 # endif
 #endif
 
+/* Some versions of GCC (e.g., 10.x) set the warn_unused_result attribute on
+   __builtin_alloca.  This causes alloca(0) to fail and is not easily worked
+   around so avoid it via the preprocessor.
+   See https://gcc.gnu.org/bugzilla/show_bug.cgi?id=98055  */
+
+#if defined (__has_builtin)
+# if __has_builtin (__builtin_alloca)
+#   define free_alloca()
+# else
+#  define free_alloca() alloca (0)
+# endif
+#else
+# define free_alloca() alloca (0)
+#endif
+
 /* Disable assert() unless we're a maintainer.
    Some asserts are compute-intensive.  */
 #ifndef MAKE_MAINTAINER_MODE
@@ -79,16 +94,10 @@ char *alloca ();
    unless <sys/timeb.h> has been included first.  */
 # include <sys/timeb.h>
 #endif
-#if TIME_WITH_SYS_TIME
+#if HAVE_SYS_TIME_H
 # include <sys/time.h>
-# include <time.h>
-#else
-# if HAVE_SYS_TIME_H
-#  include <sys/time.h>
-# else
-#  include <time.h>
-# endif
 #endif
+#include <time.h>
 
 #include <errno.h>
 
@@ -115,7 +124,7 @@ extern int errno;
 #endif
 
 /* Some systems define _POSIX_VERSION but are not really POSIX.1.  */
-#if (defined (butterfly) || defined (__arm) || (defined (__mips) && defined (_SYSTYPE_SVR3)) || (defined (sequent) && defined (i386)))
+#if (defined (butterfly) || (defined (__mips) && defined (_SYSTYPE_SVR3)) || (defined (sequent) && defined (i386)))
 # undef POSIX
 #endif
 
@@ -123,10 +132,6 @@ extern int errno;
 # define POSIX 1
 #endif
 
-#ifndef RETSIGTYPE
-# define RETSIGTYPE     void
-#endif
-
 #ifndef sigmask
 # define sigmask(sig)   (1 << ((sig) - 1))
 #endif
@@ -147,13 +152,14 @@ extern int errno;
 #endif
 
 #ifndef PATH_MAX
-# ifndef POSIX
+# ifdef MAXPATHLEN
 #  define PATH_MAX      MAXPATHLEN
+# else
+/* Some systems (HURD) have fully dynamic pathnames with no maximum.
+   Ideally we'd support this but it will take some work.  */
+#  define PATH_MAX      4096
 # endif
 #endif
-#ifndef MAXPATHLEN
-# define MAXPATHLEN 1024
-#endif
 
 #ifdef  PATH_MAX
 # define GET_PATH_MAX   PATH_MAX
@@ -289,6 +295,21 @@ char *strerror (int errnum);
 #if HAVE_STDINT_H
 # include <stdint.h>
 #endif
+
+#if defined _MSC_VER || defined __MINGW32__
+# define MK_PRI64_PREFIX "I64"
+#else
+# define MK_PRI64_PREFIX "ll"
+#endif
+#ifndef PRIdMAX
+# define PRIdMAX MK_PRI64_PREFIX "d"
+#endif
+#ifndef PRIuMAX
+# define PRIuMAX MK_PRI64_PREFIX "u"
+#endif
+#ifndef SCNdMAX
+# define SCNdMAX PRIdMAX
+#endif
 #define FILE_TIMESTAMP uintmax_t
 
 #if !defined(HAVE_STRSIGNAL)
@@ -388,11 +409,13 @@ extern int unixy_shell;
 # define WIN32_LEAN_AND_MEAN
 #endif  /* WINDOWS32 */
 
+/* ALL_SET() evaluates the second argument twice.  */
 #define ANY_SET(_v,_m)  (((_v)&(_m)) != 0)
 #define NONE_SET(_v,_m) (! ANY_SET ((_v),(_m)))
+#define ALL_SET(_v,_m)  (((_v)&(_m)) == (_m))
 
 #define MAP_NUL         0x0001
-#define MAP_BLANK       0x0002
+#define MAP_BLANK       0x0002  /* space, TAB */
 #define MAP_NEWLINE     0x0004
 #define MAP_COMMENT     0x0008
 #define MAP_SEMI        0x0010
@@ -446,10 +469,16 @@ extern int unixy_shell;
 
 #define STOP_SET(_v,_m) ANY_SET(stopchar_map[(unsigned char)(_v)],(_m))
 
+/* True if C is a directory separator on the current system.  */
+#define ISDIRSEP(c)     STOP_SET((c),MAP_DIRSEP)
+/* True if C is whitespace but not newline.  */
 #define ISBLANK(c)      STOP_SET((c),MAP_BLANK)
+/* True if C is whitespace including newlines.  */
 #define ISSPACE(c)      STOP_SET((c),MAP_SPACE)
+/* True if C is nul or whitespace (including newline).  */
+#define END_OF_TOKEN(c) STOP_SET((c),MAP_SPACE|MAP_NUL)
+/* Move S past all whitespace (including newlines).  */
 #define NEXT_TOKEN(s)   while (ISSPACE (*(s))) ++(s)
-#define END_OF_TOKEN(s) while (! STOP_SET (*(s), MAP_SPACE|MAP_NUL)) ++(s)
 
 /* We can't run setrlimit when using posix_spawn.  */
 #if defined(HAVE_SYS_RESOURCE_H) && defined(HAVE_GETRLIMIT) && defined(HAVE_SETRLIMIT) && !defined(USE_POSIX_SPAWN)
@@ -464,11 +493,17 @@ extern struct rlimit stack_limit;
 
 #define NILF ((floc *)0)
 
+/* Number of characters in a string constant.  Does NOT include the \0 byte.  */
 #define CSTRLEN(_s)           (sizeof (_s)-1)
+
+/* Only usable when NOT calling a macro: only use it for local functions.  */
 #define STRING_SIZE_TUPLE(_s) (_s), CSTRLEN(_s)
 
-/* The number of bytes needed to represent the largest integer as a string.  */
-#define INTSTR_LENGTH         CSTRLEN ("18446744073709551616")
+/* The number of bytes needed to represent the largest signed and unsigned
+   integers as a string.
+   Does NOT include space for \0 so be sure to add it if needed.
+   Math suggested by Edward Welbourne <edward.welbourne@qt.io>  */
+#define INTSTR_LENGTH   (53 * sizeof(uintmax_t) / 22 + 3)
 
 #define DEFAULT_TTYNAME "true"
 #ifdef HAVE_TTYNAME
@@ -477,8 +512,19 @@ extern struct rlimit stack_limit;
 # define TTYNAME(_f) DEFAULT_TTYNAME
 #endif
 
+#ifdef VMS
+# define DEFAULT_TMPDIR     "/sys$scratch/"
+#elif defined(P_tmpdir)
+# define DEFAULT_TMPDIR     P_tmpdir
+#else
+# define DEFAULT_TMPDIR     "/tmp"
+#endif
+
+
 \f
 
+struct file;
+
 /* Specify the location of elements read from makefiles.  */
 typedef struct
   {
@@ -494,7 +540,7 @@ void error (const floc *flocp, size_t length, const char *fmt, ...)
             ATTRIBUTE ((__format__ (__printf__, 3, 4)));
 void fatal (const floc *flocp, size_t length, const char *fmt, ...)
             ATTRIBUTE ((noreturn, __format__ (__printf__, 3, 4)));
-void out_of_memory () NORETURN;
+void out_of_memory (void) NORETURN;
 
 /* When adding macros to this list be sure to update the value of
    XGETTEXT_OPTIONS in the po/Makevars file.  */
@@ -512,10 +558,18 @@ void out_of_memory () NORETURN;
 #define ONS(_t,_a,_f,_n,_s)   _t((_a), INTSTR_LENGTH + strlen (_s), \
                                  (_f), (_n), (_s))
 
+void decode_env_switches (const char*, size_t line);
+void temp_stdin_unlink (void);
 void die (int) NORETURN;
 void pfatal_with_name (const char *) NORETURN;
 void perror_with_name (const char *, const char *);
 #define xstrlen(_s) ((_s)==NULL ? 0 : strlen (_s))
+unsigned int make_toui (const char*, const char**);
+char *make_lltoa (long long, char *);
+char *make_ulltoa (unsigned long long, char *);
+void make_seed (unsigned int);
+unsigned int make_rand (void);
+pid_t make_pid (void);
 void *xmalloc (size_t);
 void *xcalloc (size_t);
 void *xrealloc (void *, size_t);
@@ -530,7 +584,9 @@ int alpha_compare (const void *, const void *);
 void print_spaces (unsigned int);
 char *find_percent (char *);
 const char *find_percent_cached (const char **);
-FILE *get_tmpfile (char **, const char *);
+const char *get_tmpdir (void);
+int get_tmpfd (char **);
+FILE *get_tmpfile (char **);
 ssize_t writebuf (int, const void *, size_t);
 ssize_t readbuf (int, void *, size_t);
 
@@ -544,13 +600,14 @@ void ar_parse_name (const char *, char **, char **);
 int ar_touch (const char *);
 time_t ar_member_date (const char *);
 
-typedef long int (*ar_member_func_t) (int desc, const char *mem, int truncated,
+typedef intmax_t (*ar_member_func_t) (int desc, const char *mem, int truncated,
                                       long int hdrpos, long int datapos,
-                                      long int size, long int date, int uid,
+                                      long int size, intmax_t date, int uid,
                                       int gid, unsigned int mode,
                                       const void *arg);
 
-long int ar_scan (const char *archive, ar_member_func_t function, const void *arg);
+intmax_t ar_scan (const char *archive, ar_member_func_t function,
+                  const void *arg);
 int ar_name_equal (const char *name, const char *mem, int truncated);
 #ifndef VMS
 int ar_member_touch (const char *arname, const char *memname);
@@ -580,10 +637,6 @@ int gpath_search (const char *file, size_t len);
 
 void construct_include_path (const char **arg_dirs);
 
-void user_access (void);
-void make_access (void);
-void child_access (void);
-
 char *strip_whitespace (const char **begpp, const char **endpp);
 
 void show_goal_error (void);
@@ -600,15 +653,19 @@ int guile_gmake_setup (const floc *flocp);
 
 /* Loadable object support.  Sets to the strcached name of the loaded file.  */
 typedef int (*load_func_t)(const floc *flocp);
-int load_file (const floc *flocp, const char **filename, int noerror);
-void unload_file (const char *name);
+int load_file (const floc *flocp, struct file *file, int noerror);
+int unload_file (const char *name);
 
 /* Maintainer mode support */
 #ifdef MAKE_MAINTAINER_MODE
 # define SPIN(_s) spin (_s)
 void spin (const char* suffix);
+# define DBG(_f) dbg _f
+void dbg (const char *fmt, ...);
 #else
 # define SPIN(_s)
+/* Never put this code into Git or a release.  */
+# define DBG(_f) compile-error
 #endif
 
 /* We omit these declarations on non-POSIX systems which define _POSIX_VERSION,
@@ -616,17 +673,16 @@ void spin (const char* suffix);
 
 #if !defined (__GNU_LIBRARY__) && !defined (POSIX) && !defined (_POSIX_VERSION) && !defined(WINDOWS32)
 
-long int atol ();
 # ifndef VMS
 long int lseek ();
 # endif
 
 # ifdef  HAVE_GETCWD
 #  if !defined(VMS) && !defined(__DECC)
-char *getcwd ();
+char *getcwd (void);
 #  endif
 # else
-char *getwd ();
+char *getwd (void);
 #  define getcwd(buf, len)       getwd (buf)
 # endif
 
@@ -650,10 +706,20 @@ int strcasecmp (const char *s1, const char *s2);
 #  define strncasecmp strncmpi
 # else
 /* Create our own, in misc.c */
-int strncasecmp (const char *s1, const char *s2, int n);
+int strncasecmp (const char *s1, const char *s2, size_t n);
 # endif
 #endif
 
+#if !HAVE_MEMPCPY
+/* Create our own, in misc.c */
+void *mempcpy (void *dest, const void *src, size_t n);
+#endif
+
+#if !HAVE_STPCPY
+/* Create our own, in misc.c */
+char *stpcpy (char *dest, const char *src);
+#endif
+
 #define OUTPUT_SYNC_NONE    0
 #define OUTPUT_SYNC_LINE    1
 #define OUTPUT_SYNC_TARGET  2
@@ -670,21 +736,28 @@ extern unsigned short stopchar_map[];
 extern int just_print_flag, run_silent, ignore_errors_flag, keep_going_flag;
 extern int print_data_base_flag, question_flag, touch_flag, always_make_flag;
 extern int env_overrides, no_builtin_rules_flag, no_builtin_variables_flag;
-extern int print_version_flag, print_directory_flag, check_symlink_flag;
-extern int warn_undefined_variables_flag, trace_flag, posix_pedantic;
+extern int print_version_flag, print_directory, check_symlink_flag;
+extern int warn_undefined_variables_flag, posix_pedantic;
 extern int not_parallel, second_expansion, clock_skew_detected;
 extern int rebuilding_makefiles, one_shell, output_sync, verify_flag;
+extern unsigned long command_count;
 
 extern const char *default_shell;
 
 /* can we run commands via 'sh -c xxx' or must we use batch files? */
 extern int batch_mode_shell;
 
+#define GNUMAKEFLAGS_NAME       "GNUMAKEFLAGS"
+#define MAKEFLAGS_NAME          "MAKEFLAGS"
+
 /* Resetting the command script introduction prefix character.  */
-#define RECIPEPREFIX_NAME          ".RECIPEPREFIX"
-#define RECIPEPREFIX_DEFAULT       '\t'
+#define RECIPEPREFIX_NAME       ".RECIPEPREFIX"
+#define RECIPEPREFIX_DEFAULT    '\t'
 extern char cmd_prefix;
 
+#define JOBSERVER_AUTH_OPT      "jobserver-auth"
+
+extern char *jobserver_auth;
 extern unsigned int job_slots;
 extern double max_load_average;
 
@@ -737,7 +810,7 @@ extern char *version_string, *remote_description, *make_host;
 
 extern unsigned int commands_started;
 
-extern int handling_fatal_signal;
+extern volatile sig_atomic_t handling_fatal_signal;
 
 #ifndef MIN
 #define MIN(_a,_b) ((_a)<(_b)?(_a):(_b))