* Define and use xstrdup() instead of strdup().
authorPaul Smith <psmith@gnu.org>
Fri, 5 Mar 1999 07:13:12 +0000 (07:13 +0000)
committerPaul Smith <psmith@gnu.org>
Fri, 5 Mar 1999 07:13:12 +0000 (07:13 +0000)
ChangeLog
configure.in
dir.c
job.c
main.c
make.h
misc.c
remake.c
rule.c

index 021562b..b0d344d 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,15 @@
 1999-03-05  Paul D. Smith  <psmith@gnu.org>
 
+       * configure.in: Check for a system strdup().
+       * misc.c (xstrdup): Created.  Suggestion by Han-Wen Nienhuys
+       <hanwen@cs.uu.nl>.
+       * make.h: Prototype xstrdup().
+       * remake.c (library_search): Use it.
+       * main.c (main): Use it.
+       (find_and_set_default_shell): Use it.
+       * job.c (construct_command_argv_internal): Use it.
+       * dir.c (find_directory): Use it.
+
        * Makefile.am, configure.in: Use AC_SUBST_FILE to insert the
        maintMakefile instead of "include", to avoid automake 1.4
        incompatibility.
 
        * read.c (record_files): Clean up some indentation.
 
+1998-11-08  Han-Wen Nienhuys  <hanwen@cs.uu.nl>
+
+       * rule.c (print_rule_data_base): Fix arguments to fatal() call.
+
 1998-10-13  Paul D. Smith  <psmith@gnu.org>
 
        * job.c (new_job): If the command list resolves to empty (through
index 87d8062..651387e 100644 (file)
@@ -55,7 +55,7 @@ AC_MSG_RESULT($ac_cv_check_symbol_$1)])dnl
 # clock_gettime is in -lposix4 in Solaris 2.6.
 AC_CHECK_LIB(posix4, clock_gettime)
 
-AC_CHECK_FUNCS(memmove psignal mktemp pstat_getdynamic \
+AC_CHECK_FUNCS(memmove strdup psignal mktemp pstat_getdynamic \
               clock_gettime dup2 getcwd sigsetmask getgroups setlinebuf \
               seteuid setegid setreuid setregid strerror strsignal)
 AC_CHECK_SYMBOL(sys_siglist)
diff --git a/dir.c b/dir.c
index 9f79a4d..f93a9ba 100644 (file)
--- a/dir.c
+++ b/dir.c
@@ -385,7 +385,7 @@ find_directory (name)
              /* Enter it in the contents hash table.  */
              dc->dev = st.st_dev;
 #ifdef WINDOWS32
-              dc->path_key = strdup(w32_path);
+              dc->path_key = xstrdup(w32_path);
               dc->mtime = st.st_mtime;
 
               /*
diff --git a/job.c b/job.c
index 5ea6067..87f22a2 100644 (file)
--- a/job.c
+++ b/job.c
@@ -2291,10 +2291,10 @@ construct_command_argv_internal (line, restp, shell, ifs, batch_filename_ptr)
       /* create argv */
       new_argv = (char **) xmalloc(3 * sizeof(char *));
       if (unixy_shell) {
-        new_argv[0] = strdup (shell);
+        new_argv[0] = xstrdup (shell);
         new_argv[1] = *batch_filename_ptr; /* only argv[0] gets freed later */
       } else {
-        new_argv[0] = strdup (*batch_filename_ptr);
+        new_argv[0] = xstrdup (*batch_filename_ptr);
         new_argv[1] = NULL;
       }
       new_argv[2] = NULL;
diff --git a/main.c b/main.c
index 7c141e8..4bae415 100644 (file)
--- a/main.c
+++ b/main.c
@@ -568,7 +568,7 @@ find_and_set_default_shell(char *token)
   } else if (file_exists_p(search_token)) {
     /* search token path was found */
     sprintf(sh_path, "%s", search_token);
-    default_shell = strdup(w32ify(sh_path,0));
+    default_shell = xstrdup(w32ify(sh_path,0));
     if (debug_flag)
       printf("find_and_set_shell setting default_shell = %s\n", default_shell);
     sh_found = 1;
@@ -590,7 +590,7 @@ find_and_set_default_shell(char *token)
 
         if (dir_file_exists_p(p, search_token)) {
           sprintf(sh_path, "%s/%s", p, search_token);
-          default_shell = strdup(w32ify(sh_path,0));
+          default_shell = xstrdup(w32ify(sh_path,0));
           sh_found = 1;
           *ep = PATH_SEPARATOR_CHAR;
 
@@ -607,7 +607,7 @@ find_and_set_default_shell(char *token)
       /* be sure to check last element of Path */
       if (p && *p && dir_file_exists_p(p, search_token)) {
           sprintf(sh_path, "%s/%s", p, search_token);
-          default_shell = strdup(w32ify(sh_path,0));
+          default_shell = xstrdup(w32ify(sh_path,0));
           sh_found = 1;
       }
 
@@ -941,7 +941,7 @@ int main (int argc, char ** argv)
   if (strpbrk(argv[0], "/:\\") ||
       strstr(argv[0], "..") ||
       !strncmp(argv[0], "//", 2))
-    argv[0] = strdup(w32ify(argv[0],1));
+    argv[0] = xstrdup(w32ify(argv[0],1));
 #else /* WINDOWS32 */
   if (current_directory[0] != '\0'
       && argv[0] != 0 && argv[0][0] != '/' && index (argv[0], '/') != 0)
diff --git a/make.h b/make.h
index ee7721d..d5bbe7e 100644 (file)
--- a/make.h
+++ b/make.h
@@ -374,6 +374,7 @@ extern char *savestring PARAMS ((char *, unsigned int));
 extern char *concat PARAMS ((char *, char *, char *));
 extern char *xmalloc PARAMS ((unsigned int));
 extern char *xrealloc PARAMS ((char *, unsigned int));
+extern char *xstrdup PARAMS ((const char *));
 extern char *find_next_token PARAMS ((char **, unsigned int *));
 extern char *next_token PARAMS ((char *));
 extern char *end_of_token PARAMS ((char *));
diff --git a/misc.c b/misc.c
index 87694e2..505b186 100644 (file)
--- a/misc.c
+++ b/misc.c
@@ -378,6 +378,29 @@ xrealloc (ptr, size)
   return result;
 }
 
+
+const char *
+xstrdup (ptr)
+     const char *ptr;
+{
+  char *result;
+
+#ifdef HAVE_STRDUP
+  result = strdup (ptr);
+#else
+  result = (char *) malloc (strlen (ptr) + 1);
+#endif
+
+  if (result == 0)
+    fatal (NILF, "virtual memory exhausted");
+
+#ifdef HAVE_STRDUP
+  return result;
+#else
+  return strcpy(result, ptr);
+#endif
+}
+
 char *
 savestring (str, length)
      char *str;
index 4604ea5..b8b5c7f 100644 (file)
--- a/remake.c
+++ b/remake.c
@@ -1208,7 +1208,7 @@ library_search (lib, mtime_ptr)
       int save = warn_undefined_variables_flag;
       warn_undefined_variables_flag = 0;
 
-      libpatterns = strdup (variable_expand ("$(strip $(.LIBPATTERNS))"));
+      libpatterns = xstrdup (variable_expand ("$(strip $(.LIBPATTERNS))"));
 
       warn_undefined_variables_flag = save;
     }
@@ -1249,7 +1249,7 @@ library_search (lib, mtime_ptr)
       mtime = name_mtime (libbuf);
       if (mtime != (FILE_TIMESTAMP) -1)
        {
-         *lib = strdup (libbuf);
+         *lib = xstrdup (libbuf);
          if (mtime_ptr != 0)
            *mtime_ptr = mtime;
          return 1;
@@ -1289,7 +1289,7 @@ library_search (lib, mtime_ptr)
          mtime = name_mtime (buf);
          if (mtime != (FILE_TIMESTAMP) -1)
            {
-             *lib = strdup (buf);
+             *lib = xstrdup (buf);
              if (mtime_ptr != 0)
                *mtime_ptr = mtime;
              return 1;
diff --git a/rule.c b/rule.c
index b2b14a1..2099e3c 100644 (file)
--- a/rule.c
+++ b/rule.c
@@ -669,7 +669,7 @@ print_rule_data_base ()
       /* This can happen if a fatal error was detected while reading the
          makefiles and thus count_implicit_rule_limits wasn't called yet.  */
       if (num_pattern_rules != 0)
-        fatal ("BUG: num_pattern_rules wrong!  %u != %u",
+        fatal (NILF, "BUG: num_pattern_rules wrong!  %u != %u",
                num_pattern_rules, rules);
     }