Browse code

bb12238 - Removing support for deprecated readdir_r() function. The readdir() function is thread safe so long as you don't share a dir object between threads. If you do, it requires a mutex.

Micah Snyder (micasnyd) authored on 2019/07/10 01:21:34
Showing 9 changed files
... ...
@@ -45,11 +45,6 @@
45 45
 #endif
46 46
 #include <pthread.h>
47 47
 
48
-#if defined(HAVE_READDIR_R_3) || defined(HAVE_READDIR_R_2)
49
-#include <limits.h>
50
-#include <stddef.h>
51
-#endif
52
-
53 48
 #include "libclamav/clamav.h"
54 49
 #include "libclamav/others.h"
55 50
 #include "libclamav/scanners.h"
... ...
@@ -144,7 +139,7 @@ int scan_callback(STATBUF *sb, char *filename, const char *msg, enum cli_ftw_rea
144 144
     int type = scandata->type;
145 145
     struct cb_context context;
146 146
 
147
-    /* detect disconnected socket, 
147
+    /* detect disconnected socket,
148 148
      * this should NOT detect half-shutdown sockets (SHUT_WR) */
149 149
     if (send(scandata->conn->sd, &ret, 0, 0) == -1 && errno != EINTR) {
150 150
         logg("$Client disconnected while command was active!\n");
... ...
@@ -1,7 +1,6 @@
1 1
 dnl   Copyright (C) 2013-2019 Cisco Systems, Inc. and/or its affiliates. All rights reserved.
2 2
 dnl   Copyright (C) 2007-2013 Sourcefire, Inc.
3 3
 dnl   Copyright (C) 2002-2007 Tomasz Kojm <tkojm@clamav.net>
4
-dnl   readdir_r checks (c) COPYRIGHT MIT 1995
5 4
 dnl   socklen_t check (c) Alexander V. Lukyanov <lav@yars.free.net>
6 5
 dnl
7 6
 dnl   This program is free software; you can redistribute it and/or modify
... ...
@@ -127,7 +126,6 @@ m4_include([m4/reorganization/code_checks/in_addr_t.m4])
127 127
 m4_include([m4/reorganization/os_checks.m4])
128 128
 m4_include([m4/reorganization/milter/check.m4])
129 129
 m4_include([m4/reorganization/code_checks/pthread_02.m4])
130
-m4_include([m4/reorganization/code_checks/readdir.m4])
131 130
 m4_include([m4/reorganization/code_checks/ctime.m4])
132 131
 m4_include([m4/reorganization/code_checks/socklen_t.m4])
133 132
 m4_include([m4/reorganization/clamav_user.m4])
... ...
@@ -842,24 +842,12 @@ int cl_validate_certificate_chain_ts_dir(char *tsdir, char *certpath)
842 842
     int res;
843 843
     DIR *dp;
844 844
     struct dirent *dirent;
845
-#if defined(HAVE_READDIR_R_3) || defined(HAVE_READDIR_R_2)
846
-    union {
847
-        struct dirent d;
848
-        char b[offsetof(struct dirent, d_name) + NAME_MAX + 1];
849
-    } result;
850
-#endif
851 845
 
852 846
     dp = opendir(tsdir);
853 847
     if (!(dp))
854 848
         return CL_EOPEN;
855 849
 
856
-#if defined(HAVE_READDIR_R_3)
857
-    while (!readdir_r(dp, &result.d, &dirent) && dirent) {
858
-#elif defined(HAVE_READDIR_R_2)
859
-    while ((dirent = (struct dirent *)readdir_r(dp, &result.d))) {
860
-#else
861 850
     while ((dirent = readdir(dp))) {
862
-#endif
863 851
         if (dirent->d_name[0] == '.')
864 852
             continue;
865 853
 
... ...
@@ -59,10 +59,6 @@
59 59
 #include <unistd.h>
60 60
 #endif
61 61
 
62
-#if defined(HAVE_READDIR_R_3) || defined(HAVE_READDIR_R_2)
63
-#include <stddef.h>
64
-#endif
65
-
66 62
 #ifdef CL_THREAD_SAFE
67 63
 #include <pthread.h>
68 64
 #endif
... ...
@@ -3269,22 +3265,10 @@ rfc1341(message *m, const char *dir)
3269 3269
             for (n = 1; n <= t; n++) {
3270 3270
                 char filename[NAME_MAX + 1];
3271 3271
                 struct dirent *dent;
3272
-#if defined(HAVE_READDIR_R_3) || defined(HAVE_READDIR_R_2)
3273
-                union {
3274
-                    struct dirent d;
3275
-                    char b[offsetof(struct dirent, d_name) + NAME_MAX + 1];
3276
-                } result;
3277
-#endif
3278 3272
 
3279 3273
                 snprintf(filename, sizeof(filename), "_%s-%u", md5_hex, n);
3280 3274
 
3281
-#ifdef HAVE_READDIR_R_3
3282
-                while ((readdir_r(dd, &result.d, &dent) == 0) && dent) {
3283
-#elif defined(HAVE_READDIR_R_2)
3284
-                while ((dent = (struct dirent *)readdir_r(dd, &result.d))) {
3285
-#else /*!HAVE_READDIR_R*/
3286 3275
                 while ((dent = readdir(dd))) {
3287
-#endif
3288 3276
                     FILE *fin;
3289 3277
                     char buffer[BUFSIZ], fullname[NAME_MAX + 1];
3290 3278
                     int nblanks;
... ...
@@ -57,11 +57,6 @@
57 57
 #include <pthread.h>
58 58
 #endif
59 59
 
60
-#if defined(HAVE_READDIR_R_3) || defined(HAVE_READDIR_R_2)
61
-#include <limits.h>
62
-#include <stddef.h>
63
-#endif
64
-
65 60
 #ifdef HAVE_LIBXML2
66 61
 #include <libxml/parser.h>
67 62
 #endif
... ...
@@ -1081,7 +1076,7 @@ int cli_unlink(const char *pathname)
1081 1081
 {
1082 1082
     if (unlink(pathname) == -1) {
1083 1083
 #ifdef _WIN32
1084
-        /* Windows may fail to unlink a file if it is marked read-only, 
1084
+        /* Windows may fail to unlink a file if it is marked read-only,
1085 1085
 		 * even if the user has permissions to delete the file. */
1086 1086
         if (-1 == _chmod(pathname, _S_IWRITE)) {
1087 1087
             char err[128];
... ...
@@ -1226,12 +1221,6 @@ int cli_rmdirs(const char *name)
1226 1226
     STATBUF statb;
1227 1227
     DIR *dd;
1228 1228
     struct dirent *dent;
1229
-#if defined(HAVE_READDIR_R_3) || defined(HAVE_READDIR_R_2)
1230
-    union {
1231
-        struct dirent d;
1232
-        char b[offsetof(struct dirent, d_name) + NAME_MAX + 1];
1233
-    } result;
1234
-#endif
1235 1229
     char err[128];
1236 1230
 
1237 1231
     if (CLAMSTAT(name, &statb) < 0) {
... ...
@@ -1249,13 +1238,7 @@ int cli_rmdirs(const char *name)
1249 1249
 
1250 1250
     rc = 0;
1251 1251
 
1252
-#ifdef HAVE_READDIR_R_3
1253
-    while ((readdir_r(dd, &result.d, &dent) == 0) && dent) {
1254
-#elif defined(HAVE_READDIR_R_2)
1255
-    while ((dent = (struct dirent *)readdir_r(dd, &result.d)) != NULL) {
1256
-#else
1257 1252
     while ((dent = readdir(dd)) != NULL) {
1258
-#endif
1259 1253
         char *path;
1260 1254
 
1261 1255
         if (strcmp(dent->d_name, ".") == 0)
... ...
@@ -1292,12 +1275,6 @@ int cli_rmdirs(const char *dirname)
1292 1292
 {
1293 1293
     DIR *dd;
1294 1294
     struct dirent *dent;
1295
-#if defined(HAVE_READDIR_R_3) || defined(HAVE_READDIR_R_2)
1296
-    union {
1297
-        struct dirent d;
1298
-        char b[offsetof(struct dirent, d_name) + NAME_MAX + 1];
1299
-    } result;
1300
-#endif
1301 1295
     STATBUF maind, statbuf;
1302 1296
     char *path;
1303 1297
     char err[128];
... ...
@@ -1312,13 +1289,7 @@ int cli_rmdirs(const char *dirname)
1312 1312
                 return -1;
1313 1313
             }
1314 1314
 
1315
-#ifdef HAVE_READDIR_R_3
1316
-            while (!readdir_r(dd, &result.d, &dent) && dent) {
1317
-#elif defined(HAVE_READDIR_R_2)
1318
-            while ((dent = (struct dirent *)readdir_r(dd, &result.d))) {
1319
-#else
1320 1315
             while ((dent = readdir(dd))) {
1321
-#endif
1322 1316
                 if (dent->d_ino) {
1323 1317
                     if (strcmp(dent->d_name, ".") && strcmp(dent->d_name, "..")) {
1324 1318
                         path = cli_malloc(strlen(dirname) + strlen(dent->d_name) + 2);
... ...
@@ -621,12 +621,6 @@ int cli_ftw(char *path, int flags, int maxdepth, cli_ftw_cb callback, struct cli
621 621
 static int cli_ftw_dir(const char *dirname, int flags, int maxdepth, cli_ftw_cb callback, struct cli_ftw_cbdata *data, cli_ftw_pathchk pathchk)
622 622
 {
623 623
     DIR *dd;
624
-#if defined(HAVE_READDIR_R_3) || defined(HAVE_READDIR_R_2)
625
-    union {
626
-        struct dirent d;
627
-        char b[offsetof(struct dirent, d_name) + NAME_MAX + 1];
628
-    } result;
629
-#endif
630 624
     struct dirent_data *entries = NULL;
631 625
     size_t i, entries_cnt = 0;
632 626
     int ret;
... ...
@@ -639,16 +633,9 @@ static int cli_ftw_dir(const char *dirname, int flags, int maxdepth, cli_ftw_cb
639 639
 
640 640
     if ((dd = opendir(dirname)) != NULL) {
641 641
         struct dirent *dent;
642
-        int err;
643 642
         errno = 0;
644 643
         ret   = CL_SUCCESS;
645
-#ifdef HAVE_READDIR_R_3
646
-        while (!(err = readdir_r(dd, &result.d, &dent)) && dent) {
647
-#elif defined(HAVE_READDIR_R_2)
648
-        while ((dent = (struct dirent *)readdir_r(dd, &result.d))) {
649
-#else
650 644
         while ((dent = readdir(dd))) {
651
-#endif
652 645
             int stated = 0;
653 646
             enum filetype ft;
654 647
             char *fname;
... ...
@@ -752,29 +739,8 @@ static int cli_ftw_dir(const char *dirname, int flags, int maxdepth, cli_ftw_cb
752 752
             }
753 753
             errno = 0;
754 754
         }
755
-#ifndef HAVE_READDIR_R_3
756
-        err = errno;
757
-#endif
758 755
         closedir(dd);
759 756
         ret = CL_SUCCESS;
760
-        if (err) {
761
-            char errs[128];
762
-            cli_errmsg("Unable to readdir() directory %s: %s\n", dirname,
763
-                       cli_strerror(errno, errs, sizeof(errs)));
764
-            /* report error to callback using error_stat */
765
-            ret = callback(NULL, NULL, dirname, error_stat, data);
766
-            if (ret != CL_SUCCESS) {
767
-                if (entries) {
768
-                    for (i = 0; i < entries_cnt; i++) {
769
-                        struct dirent_data *entry = &entries[i];
770
-                        free(entry->filename);
771
-                        free(entry->statbuf);
772
-                    }
773
-                    free(entries);
774
-                }
775
-                return ret;
776
-            }
777
-        }
778 757
 
779 758
         if (entries) {
780 759
             cli_qsort(entries, entries_cnt, sizeof(*entries), ftw_compare);
... ...
@@ -903,7 +869,7 @@ char *cli_sanitize_filepath(const char *filepath, size_t filepath_len)
903 903
                 depth--;
904 904
             }
905 905
 #ifdef _WIN32
906
-        /*
906
+            /*
907 907
          * Windows' POSIX style API's accept both "/" and "\\" style path separators.
908 908
          * The following checks using POSIX style path separators on Windows.
909 909
          */
... ...
@@ -957,7 +923,7 @@ char *cli_sanitize_filepath(const char *filepath, size_t filepath_len)
957 957
             depth++;
958 958
         }
959 959
     }
960
-    
960
+
961 961
 done:
962 962
     if ((NULL != sanitized_filepath) && (0 == strlen(sanitized_filepath))) {
963 963
         free(sanitized_filepath);
... ...
@@ -1162,7 +1128,7 @@ cl_error_t cli_get_filepath_from_filedesc(int desc, char **filepath)
1162 1162
     }
1163 1163
 
1164 1164
 #elif _WIN32
1165
-    DWORD dwRet = 0;
1165
+    DWORD dwRet    = 0;
1166 1166
     intptr_t hFile = _get_osfhandle(desc);
1167 1167
 
1168 1168
     dwRet = GetFinalPathNameByHandleA((HANDLE)hFile, NULL, 0, VOLUME_NAME_NT);
... ...
@@ -1184,7 +1150,7 @@ cl_error_t cli_get_filepath_from_filedesc(int desc, char **filepath)
1184 1184
         cli_errmsg("cli_get_filepath_from_filedesc: Failed to resolve filename for descriptor %d\n", desc);
1185 1185
         free(*filepath);
1186 1186
         *filepath = NULL;
1187
-        status = CL_EOPEN;
1187
+        status    = CL_EOPEN;
1188 1188
         goto done;
1189 1189
     }
1190 1190
 
... ...
@@ -69,11 +69,6 @@
69 69
 #include "regex_list.h"
70 70
 #include "hashtab.h"
71 71
 
72
-#if defined(HAVE_READDIR_R_3) || defined(HAVE_READDIR_R_2)
73
-#include <limits.h>
74
-#include <stddef.h>
75
-#endif
76
-
77 72
 #include "mpool.h"
78 73
 #include "bytecode.h"
79 74
 #include "bytecode_api.h"
... ...
@@ -129,7 +124,7 @@ int cli_sigopts_handler(struct cli_matcher *root, const char *virname, const cha
129 129
     int ret = CL_SUCCESS;
130 130
 
131 131
     /*
132
-     * cyclic loops with cli_parse_add are impossible now as cli_parse_add 
132
+     * cyclic loops with cli_parse_add are impossible now as cli_parse_add
133 133
      * no longer calls cli_sigopts_handler; leaving here for safety
134 134
      */
135 135
     if (sigopts & ACPATT_OPTION_ONCE) {
... ...
@@ -2923,7 +2918,7 @@ static int cli_loadcdb(FILE *fs, struct cl_engine *engine, unsigned int *signo,
2923 2923
     return CL_SUCCESS;
2924 2924
 }
2925 2925
 
2926
-/* 
2926
+/*
2927 2927
  * name;trusted;subject;serial;pubkey;exp;codesign;timesign;certsign;notbefore;comment[;minFL[;maxFL]]
2928 2928
  * Name and comment are ignored. They're just for the end user.
2929 2929
  * Exponent is ignored for now and hardcoded to \x01\x00\x01.
... ...
@@ -3231,7 +3226,7 @@ static char *parse_yara_hex_string(YR_STRING *string, int *ret)
3231 3231
         }
3232 3232
     }
3233 3233
 
3234
-/* FIXME: removing this code because anchored bytes are not sufficiently 
3234
+/* FIXME: removing this code because anchored bytes are not sufficiently
3235 3235
    general for the purposes of yara rule to ClamAV sig conversions.
3236 3236
    1. ClamAV imposes a maximum value for the upper range limit of 32:
3237 3237
       #define AC_CH_MAXDIST 32
... ...
@@ -3811,7 +3806,7 @@ static int load_oneyara(YR_RULE *rule, int chkpua, struct cl_engine *engine, uns
3811 3811
             ytable_delete(&ytable);
3812 3812
             return CL_EMEM;
3813 3813
         }
3814
-        
3814
+
3815 3815
         if (rule->cl_flags & RULE_ALL && rule->cl_flags & RULE_THEM)
3816 3816
             exp_op = "&";
3817 3817
         else {
... ...
@@ -3820,12 +3815,12 @@ static int load_oneyara(YR_RULE *rule, int chkpua, struct cl_engine *engine, uns
3820 3820
                 !(rule->cl_flags & RULE_EP && ytable.tbl_cnt == 1))
3821 3821
                 yara_complex++;
3822 3822
         }
3823
-        
3823
+
3824 3824
         for (i=0; i<ytable.tbl_cnt; i++) {
3825 3825
             size_t len=strlen(logic);
3826 3826
             snprintf(logic+len, lsize-len, "%u%s", i, (i+1 == ytable.tbl_cnt) ? "" : exp_op);
3827
-        }    
3828
-        
3827
+        }
3828
+
3829 3829
         /*** END CONDITIONAL HANDLING ***/
3830 3830
     }
3831 3831
 
... ...
@@ -4509,12 +4504,6 @@ static int cli_loaddbdir(const char *dirname, struct cl_engine *engine, unsigned
4509 4509
 {
4510 4510
     DIR *dd = NULL;
4511 4511
     struct dirent *dent;
4512
-#if defined(HAVE_READDIR_R_3) || defined(HAVE_READDIR_R_2)
4513
-    union {
4514
-        struct dirent d;
4515
-        char b[offsetof(struct dirent, d_name) + NAME_MAX + 1];
4516
-    } result;
4517
-#endif
4518 4512
     char *dbfile = NULL;
4519 4513
     int ret = CL_EOPEN, have_daily_cld = 0, have_daily_cvd = 0, ends_with_sep = 0;
4520 4514
     size_t dirname_len;
... ...
@@ -4540,13 +4529,7 @@ static int cli_loaddbdir(const char *dirname, struct cl_engine *engine, unsigned
4540 4540
         }
4541 4541
     }
4542 4542
 
4543
-#ifdef HAVE_READDIR_R_3
4544
-    while (!readdir_r(dd, &result.d, &dent) && dent) {
4545
-#elif defined(HAVE_READDIR_R_2)
4546
-    while ((dent = (struct dirent *)readdir_r(dd, &result.d))) {
4547
-#else
4548 4543
     while ((dent = readdir(dd))) {
4549
-#endif
4550 4544
         struct db_ll_entry *entry;
4551 4545
         unsigned int load_priority;
4552 4546
 
... ...
@@ -4808,12 +4791,6 @@ int cl_statinidir(const char *dirname, struct cl_stat *dbstat)
4808 4808
 {
4809 4809
     DIR *dd;
4810 4810
     struct dirent *dent;
4811
-#if defined(HAVE_READDIR_R_3) || defined(HAVE_READDIR_R_2)
4812
-    union {
4813
-        struct dirent d;
4814
-        char b[offsetof(struct dirent, d_name) + NAME_MAX + 1];
4815
-    } result;
4816
-#endif
4817 4811
     char *fname;
4818 4812
 
4819 4813
     if (dbstat) {
... ...
@@ -4834,13 +4811,7 @@ int cl_statinidir(const char *dirname, struct cl_stat *dbstat)
4834 4834
 
4835 4835
     cli_dbgmsg("Stat()ing files in %s\n", dirname);
4836 4836
 
4837
-#ifdef HAVE_READDIR_R_3
4838
-    while (!readdir_r(dd, &result.d, &dent) && dent) {
4839
-#elif defined(HAVE_READDIR_R_2)
4840
-    while ((dent = (struct dirent *)readdir_r(dd, &result.d))) {
4841
-#else
4842 4837
     while ((dent = readdir(dd))) {
4843
-#endif
4844 4838
         if (dent->d_ino) {
4845 4839
             if (strcmp(dent->d_name, ".") && strcmp(dent->d_name, "..") && CLI_DBEXT(dent->d_name)) {
4846 4840
                 dbstat->entries++;
... ...
@@ -4894,12 +4865,6 @@ int cl_statchkdir(const struct cl_stat *dbstat)
4894 4894
 {
4895 4895
     DIR *dd;
4896 4896
     struct dirent *dent;
4897
-#if defined(HAVE_READDIR_R_3) || defined(HAVE_READDIR_R_2)
4898
-    union {
4899
-        struct dirent d;
4900
-        char b[offsetof(struct dirent, d_name) + NAME_MAX + 1];
4901
-    } result;
4902
-#endif
4903 4897
     STATBUF sb;
4904 4898
     unsigned int i, found;
4905 4899
     char *fname;
... ...
@@ -4916,13 +4881,7 @@ int cl_statchkdir(const struct cl_stat *dbstat)
4916 4916
 
4917 4917
     cli_dbgmsg("Stat()ing files in %s\n", dbstat->dir);
4918 4918
 
4919
-#ifdef HAVE_READDIR_R_3
4920
-    while (!readdir_r(dd, &result.d, &dent) && dent) {
4921
-#elif defined(HAVE_READDIR_R_2)
4922
-    while ((dent = (struct dirent *)readdir_r(dd, &result.d))) {
4923
-#else
4924 4919
     while ((dent = readdir(dd))) {
4925
-#endif
4926 4920
         if (dent->d_ino) {
4927 4921
             if (strcmp(dent->d_name, ".") && strcmp(dent->d_name, "..") && CLI_DBEXT(dent->d_name)) {
4928 4922
                 fname = cli_malloc(strlen(dbstat->dir) + strlen(dent->d_name) + 32);
... ...
@@ -5402,12 +5361,6 @@ int cl_countsigs(const char *path, unsigned int countoptions, unsigned int *sigs
5402 5402
     STATBUF sb;
5403 5403
     char fname[1024];
5404 5404
     struct dirent *dent;
5405
-#if defined(HAVE_READDIR_R_3) || defined(HAVE_READDIR_R_2)
5406
-    union {
5407
-        struct dirent d;
5408
-        char b[offsetof(struct dirent, d_name) + NAME_MAX + 1];
5409
-    } result;
5410
-#endif
5411 5405
     DIR *dd;
5412 5406
     int ret;
5413 5407
 
... ...
@@ -5427,13 +5380,7 @@ int cl_countsigs(const char *path, unsigned int countoptions, unsigned int *sigs
5427 5427
             cli_errmsg("cl_countsigs: Can't open directory %s\n", path);
5428 5428
             return CL_EOPEN;
5429 5429
         }
5430
-#ifdef HAVE_READDIR_R_3
5431
-        while (!readdir_r(dd, &result.d, &dent) && dent) {
5432
-#elif defined(HAVE_READDIR_R_2)
5433
-        while ((dent = (struct dirent *)readdir_r(dd, &result.d))) {
5434
-#else
5435 5430
         while ((dent = readdir(dd))) {
5436
-#endif
5437 5431
             if (dent->d_ino) {
5438 5432
                 if (strcmp(dent->d_name, ".") && strcmp(dent->d_name, "..") && CLI_DBEXT(dent->d_name)) {
5439 5433
                     snprintf(fname, sizeof(fname), "%s" PATHSEP "%s", path, dent->d_name);
... ...
@@ -115,11 +115,6 @@
115 115
 #include <bzlib.h>
116 116
 #endif
117 117
 
118
-#if defined(HAVE_READDIR_R_3) || defined(HAVE_READDIR_R_2)
119
-#include <limits.h>
120
-#include <stddef.h>
121
-#endif
122
-
123 118
 #include <fcntl.h>
124 119
 #include <string.h>
125 120
 
... ...
@@ -129,24 +124,12 @@ static int cli_scandir(const char *dirname, cli_ctx *ctx)
129 129
 {
130 130
     DIR *dd;
131 131
     struct dirent *dent;
132
-#if defined(HAVE_READDIR_R_3) || defined(HAVE_READDIR_R_2)
133
-    union {
134
-        struct dirent d;
135
-        char b[offsetof(struct dirent, d_name) + NAME_MAX + 1];
136
-    } result;
137
-#endif
138 132
     STATBUF statbuf;
139 133
     char *fname;
140 134
     unsigned int viruses_found = 0;
141 135
 
142 136
     if ((dd = opendir(dirname)) != NULL) {
143
-#ifdef HAVE_READDIR_R_3
144
-        while (!readdir_r(dd, &result.d, &dent) && dent) {
145
-#elif defined(HAVE_READDIR_R_2)
146
-        while ((dent = (struct dirent *)readdir_r(dd, &result.d))) {
147
-#else
148 137
         while ((dent = readdir(dd))) {
149
-#endif
150 138
             if (dent->d_ino) {
151 139
                 if (strcmp(dent->d_name, ".") && strcmp(dent->d_name, "..")) {
152 140
                     /* build the full name */
... ...
@@ -1149,12 +1132,6 @@ static int cli_vba_scandir(const char *dirname, cli_ctx *ctx, struct uniq *U)
1149 1149
     vba_project_t *vba_project;
1150 1150
     DIR *dd;
1151 1151
     struct dirent *dent;
1152
-#if defined(HAVE_READDIR_R_3) || defined(HAVE_READDIR_R_2)
1153
-    union {
1154
-        struct dirent d;
1155
-        char b[offsetof(struct dirent, d_name) + NAME_MAX + 1];
1156
-    } result;
1157
-#endif
1158 1152
     STATBUF statbuf;
1159 1153
     char *fullname, vbaname[1024];
1160 1154
     unsigned char *data;
... ...
@@ -1384,13 +1361,7 @@ static int cli_vba_scandir(const char *dirname, cli_ctx *ctx, struct uniq *U)
1384 1384
      * flattening the paths in ole2_walk_property_tree (case 1) */
1385 1385
 
1386 1386
     if ((dd = opendir(dirname)) != NULL) {
1387
-#ifdef HAVE_READDIR_R_3
1388
-        while (!readdir_r(dd, &result.d, &dent) && dent) {
1389
-#elif defined(HAVE_READDIR_R_2)
1390
-        while ((dent = (struct dirent *)readdir_r(dd, &result.d))) {
1391
-#else
1392 1387
         while ((dent = readdir(dd))) {
1393
-#endif
1394 1388
             if (dent->d_ino) {
1395 1389
                 if (strcmp(dent->d_name, ".") && strcmp(dent->d_name, "..")) {
1396 1390
                     /* build the full name */
... ...
@@ -3590,14 +3561,14 @@ static cl_error_t cli_base_scandesc(int desc, const char *filepath, cli_ctx *ctx
3590 3590
 
3591 3591
         status = CL_ESTAT;
3592 3592
         cli_dbgmsg("cli_magic_scandesc: returning %d %s (no post, no cache)\n", status, __AT__);
3593
-        goto done;  
3593
+        goto done;
3594 3594
     }
3595 3595
     if (sb.st_size <= 5) {
3596 3596
         cli_dbgmsg("Small data (%u bytes)\n", (unsigned int)sb.st_size);
3597 3597
 
3598 3598
         status = CL_CLEAN;
3599 3599
         cli_dbgmsg("cli_magic_scandesc: returning %d %s (no post, no cache)\n", status, __AT__);
3600
-        goto done;  
3600
+        goto done;
3601 3601
     }
3602 3602
 
3603 3603
     ctx->fmap++;
... ...
@@ -3609,7 +3580,7 @@ static cl_error_t cli_base_scandesc(int desc, const char *filepath, cli_ctx *ctx
3609 3609
 
3610 3610
         status = CL_EMEM;
3611 3611
         cli_dbgmsg("cli_magic_scandesc: returning %d %s (no post, no cache)\n", status, __AT__);
3612
-        goto done;  
3612
+        goto done;
3613 3613
     }
3614 3614
     perf_stop(ctx, PERFT_MAP);
3615 3615
 
3616 3616
deleted file mode 100644
... ...
@@ -1,46 +0,0 @@
1
-dnl Check for readdir_r and number of its arguments
2
-dnl Code from libwww/configure.in
3
-
4
-AC_MSG_CHECKING([for readdir_r])
5
-if test -z "$ac_cv_readdir_args"; then
6
-    AC_TRY_COMPILE(
7
-    [
8
-#include <sys/types.h>
9
-#include <dirent.h>
10
-    ],
11
-    [
12
-    struct dirent dir, *dirp;
13
-    DIR *mydir;
14
-    dirp = readdir_r(mydir, &dir);
15
-    ], ac_cv_readdir_args=2)
16
-fi
17
-if test -z "$ac_cv_readdir_args"; then
18
-    AC_TRY_COMPILE(
19
-        [
20
-#include <sys/types.h>
21
-#include <dirent.h>
22
-    ],
23
-    [
24
-        struct dirent dir, *dirp;
25
-        DIR *mydir;
26
-        int rc;
27
-        rc = readdir_r(mydir, &dir, &dirp);
28
-    ], ac_cv_readdir_args=3)
29
-fi
30
-
31
-AC_ARG_ENABLE([readdir_r],
32
-[AS_HELP_STRING([--enable-readdir_r], [enable support for readdir_r])],
33
-enable_readdir_r=$enableval, enable_readdir_r="no")
34
-
35
-if test "$enable_readdir_r" = "no"; then
36
-    AC_MSG_RESULT(support disabled)
37
-elif test -z "$ac_cv_readdir_args"; then
38
-    AC_MSG_RESULT(no)
39
-else
40
-    if test "$ac_cv_readdir_args" = 2; then
41
-	AC_DEFINE([HAVE_READDIR_R_2],1,[readdir_r takes 2 arguments])
42
-    elif test "$ac_cv_readdir_args" = 3; then
43
-	AC_DEFINE([HAVE_READDIR_R_3],1,[readdir_r takes 3 arguments])
44
-    fi
45
-    AC_MSG_RESULT([yes, and it takes $ac_cv_readdir_args arguments])
46
-fi