From: Vsevolod Stakhov Date: Sat, 24 Sep 2016 12:42:23 +0000 (+0100) Subject: [Minor] Kill POSIX with fire please X-Git-Tag: 1.4.0~379 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=8e7e9671d019d435880459cf859af6cf34c55104;p=rspamd.git [Minor] Kill POSIX with fire please --- diff --git a/src/client/rspamc.c b/src/client/rspamc.c index ec715abb5..400c4c59b 100644 --- a/src/client/rspamc.c +++ b/src/client/rspamc.c @@ -1431,10 +1431,10 @@ rspamc_process_dir (struct event_base *ev_base, struct rspamc_command *cmd, name_max = pathconf (name, _PC_NAME_MAX); if (name_max == -1) { - name_max = PATH_MAX + 1; + name_max = PATH_MAX; } - len = offsetof(struct dirent, d_name) + name_max + 1; + len = G_STRUCT_OFFSET (struct dirent, d_name) + name_max + 1; entry = g_malloc0 (len); while (readdir_r (d, entry, pentry) == 0) { @@ -1446,14 +1446,33 @@ rspamc_process_dir (struct event_base *ev_base, struct rspamc_command *cmd, continue; } - rspamd_snprintf (fpath, sizeof (fpath), "%s%c%*s", + rspamd_snprintf (fpath, sizeof (fpath), "%s%c%s", name, G_DIR_SEPARATOR, - (gint)entry->d_namlen, entry->d_name); + entry->d_name); is_reg = FALSE; is_dir = FALSE; -#ifdef _DIRENT_HAVE_D_TYPE +#if (defined(_DIRENT_HAVE_D_TYPE) || defined(__APPLE__)) && defined(DT_UNKNOWN) + if (entry->d_type == DT_UNKNOWN) { + /* Fallback to lstat */ + if (lstat (fpath, &st) == -1) { + rspamd_fprintf (stderr, "cannot stat file %s: %s\n", + fpath, strerror (errno)); + continue; + } + + is_dir = S_ISDIR (st.st_mode); + is_reg = S_ISREG (st.st_mode); + } + else { + if (entry->d_type == DT_REG) { + is_reg = TRUE; + } + else if (entry->d_type == DT_DIR) { + is_dir = TRUE; + } + } #else if (lstat (fpath, &st) == -1) { rspamd_fprintf (stderr, "cannot stat file %s: %s\n",