* Define and use xstrdup() instead of strdup().

This commit is contained in:
Paul Smith 1999-03-05 07:13:12 +00:00
parent 9e6ba6a148
commit a6a9ebb54f
9 changed files with 50 additions and 12 deletions

View File

@ -1,5 +1,15 @@
1999-03-05 Paul D. Smith <psmith@gnu.org> 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 * Makefile.am, configure.in: Use AC_SUBST_FILE to insert the
maintMakefile instead of "include", to avoid automake 1.4 maintMakefile instead of "include", to avoid automake 1.4
incompatibility. incompatibility.
@ -83,6 +93,10 @@
* read.c (record_files): Clean up some indentation. * 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> 1998-10-13 Paul D. Smith <psmith@gnu.org>
* job.c (new_job): If the command list resolves to empty (through * job.c (new_job): If the command list resolves to empty (through

View File

@ -55,7 +55,7 @@ AC_MSG_RESULT($ac_cv_check_symbol_$1)])dnl
# clock_gettime is in -lposix4 in Solaris 2.6. # clock_gettime is in -lposix4 in Solaris 2.6.
AC_CHECK_LIB(posix4, clock_gettime) 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 \ clock_gettime dup2 getcwd sigsetmask getgroups setlinebuf \
seteuid setegid setreuid setregid strerror strsignal) seteuid setegid setreuid setregid strerror strsignal)
AC_CHECK_SYMBOL(sys_siglist) AC_CHECK_SYMBOL(sys_siglist)

2
dir.c
View File

@ -385,7 +385,7 @@ find_directory (name)
/* Enter it in the contents hash table. */ /* Enter it in the contents hash table. */
dc->dev = st.st_dev; dc->dev = st.st_dev;
#ifdef WINDOWS32 #ifdef WINDOWS32
dc->path_key = strdup(w32_path); dc->path_key = xstrdup(w32_path);
dc->mtime = st.st_mtime; dc->mtime = st.st_mtime;
/* /*

4
job.c
View File

@ -2291,10 +2291,10 @@ construct_command_argv_internal (line, restp, shell, ifs, batch_filename_ptr)
/* create argv */ /* create argv */
new_argv = (char **) xmalloc(3 * sizeof(char *)); new_argv = (char **) xmalloc(3 * sizeof(char *));
if (unixy_shell) { 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 */ new_argv[1] = *batch_filename_ptr; /* only argv[0] gets freed later */
} else { } else {
new_argv[0] = strdup (*batch_filename_ptr); new_argv[0] = xstrdup (*batch_filename_ptr);
new_argv[1] = NULL; new_argv[1] = NULL;
} }
new_argv[2] = NULL; new_argv[2] = NULL;

8
main.c
View File

@ -568,7 +568,7 @@ find_and_set_default_shell(char *token)
} else if (file_exists_p(search_token)) { } else if (file_exists_p(search_token)) {
/* search token path was found */ /* search token path was found */
sprintf(sh_path, "%s", search_token); sprintf(sh_path, "%s", search_token);
default_shell = strdup(w32ify(sh_path,0)); default_shell = xstrdup(w32ify(sh_path,0));
if (debug_flag) if (debug_flag)
printf("find_and_set_shell setting default_shell = %s\n", default_shell); printf("find_and_set_shell setting default_shell = %s\n", default_shell);
sh_found = 1; sh_found = 1;
@ -590,7 +590,7 @@ find_and_set_default_shell(char *token)
if (dir_file_exists_p(p, search_token)) { if (dir_file_exists_p(p, search_token)) {
sprintf(sh_path, "%s/%s", 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; sh_found = 1;
*ep = PATH_SEPARATOR_CHAR; *ep = PATH_SEPARATOR_CHAR;
@ -607,7 +607,7 @@ find_and_set_default_shell(char *token)
/* be sure to check last element of Path */ /* be sure to check last element of Path */
if (p && *p && dir_file_exists_p(p, search_token)) { if (p && *p && dir_file_exists_p(p, search_token)) {
sprintf(sh_path, "%s/%s", 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; sh_found = 1;
} }
@ -941,7 +941,7 @@ int main (int argc, char ** argv)
if (strpbrk(argv[0], "/:\\") || if (strpbrk(argv[0], "/:\\") ||
strstr(argv[0], "..") || strstr(argv[0], "..") ||
!strncmp(argv[0], "//", 2)) !strncmp(argv[0], "//", 2))
argv[0] = strdup(w32ify(argv[0],1)); argv[0] = xstrdup(w32ify(argv[0],1));
#else /* WINDOWS32 */ #else /* WINDOWS32 */
if (current_directory[0] != '\0' if (current_directory[0] != '\0'
&& argv[0] != 0 && argv[0][0] != '/' && index (argv[0], '/') != 0) && argv[0] != 0 && argv[0][0] != '/' && index (argv[0], '/') != 0)

1
make.h
View File

@ -374,6 +374,7 @@ extern char *savestring PARAMS ((char *, unsigned int));
extern char *concat PARAMS ((char *, char *, char *)); extern char *concat PARAMS ((char *, char *, char *));
extern char *xmalloc PARAMS ((unsigned int)); extern char *xmalloc PARAMS ((unsigned int));
extern char *xrealloc PARAMS ((char *, 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 *find_next_token PARAMS ((char **, unsigned int *));
extern char *next_token PARAMS ((char *)); extern char *next_token PARAMS ((char *));
extern char *end_of_token PARAMS ((char *)); extern char *end_of_token PARAMS ((char *));

23
misc.c
View File

@ -378,6 +378,29 @@ xrealloc (ptr, size)
return result; 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 * char *
savestring (str, length) savestring (str, length)
char *str; char *str;

View File

@ -1208,7 +1208,7 @@ library_search (lib, mtime_ptr)
int save = warn_undefined_variables_flag; int save = warn_undefined_variables_flag;
warn_undefined_variables_flag = 0; warn_undefined_variables_flag = 0;
libpatterns = strdup (variable_expand ("$(strip $(.LIBPATTERNS))")); libpatterns = xstrdup (variable_expand ("$(strip $(.LIBPATTERNS))"));
warn_undefined_variables_flag = save; warn_undefined_variables_flag = save;
} }
@ -1249,7 +1249,7 @@ library_search (lib, mtime_ptr)
mtime = name_mtime (libbuf); mtime = name_mtime (libbuf);
if (mtime != (FILE_TIMESTAMP) -1) if (mtime != (FILE_TIMESTAMP) -1)
{ {
*lib = strdup (libbuf); *lib = xstrdup (libbuf);
if (mtime_ptr != 0) if (mtime_ptr != 0)
*mtime_ptr = mtime; *mtime_ptr = mtime;
return 1; return 1;
@ -1289,7 +1289,7 @@ library_search (lib, mtime_ptr)
mtime = name_mtime (buf); mtime = name_mtime (buf);
if (mtime != (FILE_TIMESTAMP) -1) if (mtime != (FILE_TIMESTAMP) -1)
{ {
*lib = strdup (buf); *lib = xstrdup (buf);
if (mtime_ptr != 0) if (mtime_ptr != 0)
*mtime_ptr = mtime; *mtime_ptr = mtime;
return 1; return 1;

2
rule.c
View File

@ -669,7 +669,7 @@ print_rule_data_base ()
/* This can happen if a fatal error was detected while reading the /* This can happen if a fatal error was detected while reading the
makefiles and thus count_implicit_rule_limits wasn't called yet. */ makefiles and thus count_implicit_rule_limits wasn't called yet. */
if (num_pattern_rules != 0) 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); num_pattern_rules, rules);
} }