From 3c93c602643bebb0e65975ab4946b114c44031ce Mon Sep 17 00:00:00 2001 From: psmith Date: Thu, 1 Jul 2010 05:59:08 +0000 Subject: [PATCH] - Rename strieq() to patheq() for clarity. - Convert xmalloc/memset pairs to xcalloc. --- ChangeLog | 9 +++++++++ dir.c | 11 ++++------- file.c | 3 +-- job.c | 3 +-- make.h | 20 ++++++++++---------- 5 files changed, 25 insertions(+), 21 deletions(-) diff --git a/ChangeLog b/ChangeLog index 5391e16..58eb673 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,12 @@ +2010-01-10 Paul Smith + + * make.h (patheq): Rename strieq() to patheq() for clarity. + * dir.c (dir_contents_file_exists_p): Use it. + + * dir.c (file_impossible): Convert xmalloc/memset to xcalloc. + * file.c (enter_file): Ditto. + * job.c (new_job): Ditto. + 2009-12-11 Eli Zaretskii * job.c (construct_command_argv_internal) diff --git a/dir.c b/dir.c index e127fc1..4224abb 100644 --- a/dir.c +++ b/dir.c @@ -721,7 +721,7 @@ dir_contents_file_exists_p (struct directory_contents *dir, hash_insert_at (&dir->dirfiles, df, dirfile_slot); } /* Check if the name matches the one we're searching for. */ - if (filename != 0 && strieq (d->d_name, filename)) + if (filename != 0 && patheq (d->d_name, filename)) return 1; } @@ -872,12 +872,9 @@ file_impossible (const char *filename) } if (dir->contents == 0) - { - /* The directory could not be stat'd. We allocate a contents - structure for it, but leave it out of the contents hash table. */ - dir->contents = xmalloc (sizeof (struct directory_contents)); - memset (dir->contents, '\0', sizeof (struct directory_contents)); - } + /* The directory could not be stat'd. We allocate a contents + structure for it, but leave it out of the contents hash table. */ + dir->contents = xcalloc (sizeof (struct directory_contents)); if (dir->contents->dirfiles.ht_vec == 0) { diff --git a/file.c b/file.c index d068b34..c3f7678 100644 --- a/file.c +++ b/file.c @@ -181,8 +181,7 @@ enter_file (const char *name) if (! HASH_VACANT (f) && !f->double_colon) return f; - new = xmalloc (sizeof (struct file)); - memset (new, '\0', sizeof (struct file)); + new = xcalloc (sizeof (struct file)); new->name = new->hname = name; new->update_status = -1; diff --git a/job.c b/job.c index 1db7217..edbf569 100644 --- a/job.c +++ b/job.c @@ -1611,8 +1611,7 @@ new_job (struct file *file) /* Start the command sequence, record it in a new `struct child', and add that to the chain. */ - c = xmalloc (sizeof (struct child)); - memset (c, '\0', sizeof (struct child)); + c = xcalloc (sizeof (struct child)); c->file = file; c->command_lines = lines; c->sh_batch_file = NULL; diff --git a/make.h b/make.h index 2841c7f..65faadc 100644 --- a/make.h +++ b/make.h @@ -264,23 +264,23 @@ char *strsignal (int signum); host does not conform to POSIX. */ #define ISDIGIT(c) ((unsigned) (c) - '0' <= 9) -#ifndef iAPX286 -# define streq(a, b) \ +/* Test if two strings are equal. Is this worthwhile? Should be profiled. */ +#define streq(a, b) \ ((a) == (b) || \ (*(a) == *(b) && (*(a) == '\0' || !strcmp ((a) + 1, (b) + 1)))) -# ifdef HAVE_CASE_INSENSITIVE_FS -# define strieq(a, b) \ + +/* Test if two strings are equal, but match case-insensitively on systems + which have case-insensitive filesystems. Should only be used for + filenames! */ +#ifdef HAVE_CASE_INSENSITIVE_FS +# define patheq(a, b) \ ((a) == (b) \ || (tolower((unsigned char)*(a)) == tolower((unsigned char)*(b)) \ && (*(a) == '\0' || !strcasecmp ((a) + 1, (b) + 1)))) -# else -# define strieq(a, b) streq(a, b) -# endif #else -/* Buggy compiler can't handle this. */ -# define streq(a, b) (strcmp ((a), (b)) == 0) -# define strieq(a, b) (strcmp ((a), (b)) == 0) +# define patheq(a, b) streq(a, b) #endif + #define strneq(a, b, l) (strncmp ((a), (b), (l)) == 0) #if defined(__GNUC__) || defined(ENUM_BITFIELDS) -- 2.11.4.GIT