Update aarch64 bits/hwcap.h, dl-procinfo.c for Linux 4.16 HWCAP_ASIMDFHM.
[glibc.git] / sysdeps / unix / sysv / linux / i386 / scandir64.c
blob50590c3f741cabf05f47da725d3e47de93c5a8ff
1 /* Copyright (C) 2000-2018 Free Software Foundation, Inc.
2 This file is part of the GNU C Library.
4 The GNU C Library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Lesser General Public
6 License as published by the Free Software Foundation; either
7 version 2.1 of the License, or (at your option) any later version.
9 The GNU C Library is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 Lesser General Public License for more details.
14 You should have received a copy of the GNU Lesser General Public
15 License along with the GNU C Library; if not, see
16 <http://www.gnu.org/licenses/>. */
18 #include <dirent.h>
20 #define SCANDIR __scandir64
21 #define SCANDIR_TAIL __scandir64_tail
22 #define DIRENT_TYPE struct dirent64
24 #include <dirent/scandir.c>
26 #undef SCANDIR
27 #undef SCANDIR_TAIL
28 #undef DIRENT_TYPE
30 #include <shlib-compat.h>
32 versioned_symbol (libc, __scandir64, scandir64, GLIBC_2_2);
34 #if SHLIB_COMPAT (libc, GLIBC_2_1, GLIBC_2_2)
35 # include <string.h>
36 # include <errno.h>
37 # include "olddirent.h"
39 int
40 __old_scandir64 (const char *dir, struct __old_dirent64 ***namelist,
41 int (*select) (const struct __old_dirent64 *),
42 int (*cmp) (const struct __old_dirent64 **,
43 const struct __old_dirent64 **))
45 DIR *dp = __opendir (dir);
46 struct __old_dirent64 **v = NULL;
47 size_t vsize = 0;
48 struct scandir_cancel_struct c;
49 struct __old_dirent64 *d;
50 int save;
52 if (dp == NULL)
53 return -1;
55 save = errno;
56 __set_errno (0);
58 c.dp = dp;
59 c.v = NULL;
60 c.cnt = 0;
61 __libc_cleanup_push (__scandir_cancel_handler, &c);
63 while ((d = __old_readdir64 (dp)) != NULL)
65 int use_it = select == NULL;
67 if (! use_it)
69 use_it = select (d);
70 /* The select function might have changed errno. It was
71 zero before and it need to be again to make the latter
72 tests work. */
73 __set_errno (0);
76 if (use_it)
78 struct __old_dirent64 *vnew;
79 size_t dsize;
81 /* Ignore errors from select or readdir */
82 __set_errno (0);
84 if (__glibc_unlikely (c.cnt == vsize))
86 struct __old_dirent64 **new;
87 if (vsize == 0)
88 vsize = 10;
89 else
90 vsize *= 2;
91 new = (struct __old_dirent64 **) realloc (v,
92 vsize * sizeof (*v));
93 if (new == NULL)
94 break;
95 v = new;
96 c.v = (void *) v;
99 dsize = &d->d_name[_D_ALLOC_NAMLEN (d)] - (char *) d;
100 vnew = (struct __old_dirent64 *) malloc (dsize);
101 if (vnew == NULL)
102 break;
104 v[c.cnt++] = (struct __old_dirent64 *) memcpy (vnew, d, dsize);
108 if (__builtin_expect (errno, 0) != 0)
110 save = errno;
112 while (c.cnt > 0)
113 free (v[--c.cnt]);
114 free (v);
115 c.cnt = -1;
117 else
119 /* Sort the list if we have a comparison function to sort with. */
120 if (cmp != NULL)
121 qsort (v, c.cnt, sizeof (*v),
122 (int (*) (const void *, const void *)) cmp);
124 *namelist = v;
127 __libc_cleanup_pop (0);
129 (void) __closedir (dp);
130 __set_errno (save);
132 return c.cnt;
134 compat_symbol (libc, __old_scandir64, scandir64, GLIBC_2_1);
136 #endif