Skip to content

Commit

Permalink
fixup! main: introduce portable scandir implementation
Browse files Browse the repository at this point in the history
Suggested by @k-takata:

* use eMalloc/eRealloc/eFree, and
* refer _MSC_VER instead of _MSVC
  • Loading branch information
masatake committed Aug 3, 2017
1 parent 41460a9 commit dc52e6f
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 9 deletions.
4 changes: 2 additions & 2 deletions main/options.c
Original file line number Diff line number Diff line change
Expand Up @@ -507,7 +507,7 @@ static struct Feature {
#ifdef DEBUG
{"debug", "TO BE WRITTEN"},
#endif
#if defined(HAVE_SCANDIR) || defined (HAVE_DIRENT_H) || defined (_MSVC)
#if defined(HAVE_SCANDIR) || defined (HAVE_DIRENT_H) || defined (_MSC_VER)
{"option-directory", "TO BE WRITTEN"},
#endif
#ifdef HAVE_LIBXML
Expand Down Expand Up @@ -3337,7 +3337,7 @@ static void parseConfigurationFileOptionsInDirectory (const char* directory)
#endif
}

#if defined(HAVE_SCANDIR) || defined (HAVE_DIRENT_H) || defined (_MSVC)
#if defined(HAVE_SCANDIR) || defined (HAVE_DIRENT_H) || defined (_MSC_VER)
static int ignore_dot_file(const struct dirent* dent)
{
/* Ignore a file which name is started from dot. */
Expand Down
2 changes: 1 addition & 1 deletion main/portable-dirent.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

#include <dirent.h>

#elif defined (_MSVC)
#elif defined (_MSC_VER)
/*
* Taken from
* https://svn.apache.org/repos/asf/avro/trunk/lang/c/tests/msdirent.h
Expand Down
14 changes: 8 additions & 6 deletions main/portable-scandir.c
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,8 @@
#if HAVE_SCANDIR
#include <dirent.h>
#elif HAVE_DIRENT_H
#include "general.h"
#include "routiens.h"

#include <sys/types.h>
#include <dirent.h>
Expand Down Expand Up @@ -150,7 +152,7 @@ scandir(const char *directory_name,
if (directory = opendir(directory_name), directory == NULL)
return -1;

if (array = (struct dirent **)malloc(allocated * sizeof(struct dirent *)), array == NULL)
if (array = (struct dirent **)eMalloc(allocated * sizeof(struct dirent *)), array == NULL)
return -1;

/* Read entries in the directory. */
Expand Down Expand Up @@ -183,9 +185,9 @@ scandir(const char *directory_name,
extra += namelength - sizeof(entry->d_name);
}

if (copy = (struct dirent *)malloc(sizeof(struct dirent) + extra), copy == NULL) {
if (copy = (struct dirent *)eMalloc(sizeof(struct dirent) + extra), copy == NULL) {
closedir(directory);
free(array);
eFree(array);
return -1;
}
copy->d_ino = entry->d_ino;
Expand All @@ -197,11 +199,11 @@ scandir(const char *directory_name,
if (counter + 1 == allocated) {
allocated <<= 1;
array = (struct dirent **)
realloc_safe((char *)array, allocated * sizeof(struct dirent *));
eRealloc((char *)array, allocated * sizeof(struct dirent *));
if (array == NULL) {
closedir(directory);
free(array);
free(copy);
eFree(array);
eFree(copy);
return -1;
}
}
Expand Down

0 comments on commit dc52e6f

Please sign in to comment.