Ticket #62994: TestDirDepth@Leopard.c

File TestDirDepth@Leopard.c, 12.0 KB (added by ballapete (Peter "Pete" Dyballa), 8 months ago)

TestDirDepth.c version from PPC Leopard, Mac OS X 10.5.8

Line 
1/* confdefs.h */
2#define PACKAGE_NAME "GNU M4"
3#define PACKAGE_TARNAME "m4"
4#define PACKAGE_VERSION "1.4.19"
5#define PACKAGE_STRING "GNU M4 1.4.19"
6#define PACKAGE_BUGREPORT "bug-m4@gnu.org"
7#define PACKAGE_URL "https://www.gnu.org/software/m4/"
8#define PACKAGE "m4"
9#define VERSION "1.4.19"
10#define HAVE_STDIO_H 1
11#define HAVE_STDLIB_H 1
12#define HAVE_STRING_H 1
13#define HAVE_INTTYPES_H 1
14#define HAVE_STDINT_H 1
15#define HAVE_STRINGS_H 1
16#define HAVE_SYS_STAT_H 1
17#define HAVE_SYS_TYPES_H 1
18#define HAVE_UNISTD_H 1
19#define HAVE_WCHAR_H 1
20#define HAVE_PTHREAD_H 1
21#define HAVE_SYS_PARAM_H 1
22#define HAVE_SYS_SOCKET_H 1
23#define HAVE_DIRENT_H 1
24#define HAVE_GETOPT_H 1
25#define HAVE_SYS_CDEFS_H 1
26#define HAVE_ICONV_H 1
27#define HAVE_LIMITS_H 1
28#define HAVE_WCTYPE_H 1
29#define HAVE_LANGINFO_H 1
30#define HAVE_XLOCALE_H 1
31#define HAVE_MATH_H 1
32#define HAVE_SYS_MMAN_H 1
33#define HAVE_SPAWN_H 1
34#define HAVE_SYS_TIME_H 1
35#define HAVE_SYS_RANDOM_H 1
36#define HAVE_SYS_WAIT_H 1
37#define HAVE_ARPA_INET_H 1
38#define HAVE_SEMAPHORE_H 1
39#define HAVE_NETDB_H 1
40#define HAVE_NETINET_IN_H 1
41#define HAVE_SYS_SELECT_H 1
42#define HAVE_SYS_IOCTL_H 1
43#define HAVE_SYS_UIO_H 1
44#define STDC_HEADERS 1
45#define _ALL_SOURCE 1
46#define _DARWIN_C_SOURCE 1
47#define _GNU_SOURCE 1
48#define _HPUX_ALT_XOPEN_SOCKET_API 1
49#define _NETBSD_SOURCE 1
50#define _OPENBSD_SOURCE 1
51#define _POSIX_PTHREAD_SEMANTICS 1
52#define __STDC_WANT_IEC_60559_ATTRIBS_EXT__ 1
53#define __STDC_WANT_IEC_60559_BFP_EXT__ 1
54#define __STDC_WANT_IEC_60559_DFP_EXT__ 1
55#define __STDC_WANT_IEC_60559_FUNCS_EXT__ 1
56#define __STDC_WANT_IEC_60559_TYPES_EXT__ 1
57#define __STDC_WANT_LIB_EXT2__ 1
58#define __STDC_WANT_MATH_SPEC_FUNCS__ 1
59#define _TANDEM_SOURCE 1
60#define __EXTENSIONS__ 1
61#define HAVE_FSEEKO 1
62#define GNULIB_REGEX_SINGLE_THREAD 1
63#define GNULIB_MBRTOWC_SINGLE_THREAD 1
64#define GNULIB_WCHAR_SINGLE_LOCALE 1
65#define HAVE_UNSIGNED_LONG_LONG_INT 1
66#define HAVE_LONG_LONG_INT 1
67#define HAVE_UNSIGNED_LONG_LONG_INT 1
68#define HAVE_ALLOCA_H 1
69#define HAVE_ALLOCA 1
70#define HAVE_BTOWC 1
71#define HAVE_REALPATH 1
72#define HAVE_LSTAT 1
73#define HAVE_FCHDIR 1
74#define HAVE_FCNTL 1
75#define HAVE_SYMLINK 1
76#define HAVE_FPURGE 1
77#define HAVE_GETDTABLESIZE 1
78#define HAVE_GETPROGNAME 1
79#define HAVE_ISWCNTRL 1
80#define HAVE_ISWBLANK 1
81#define HAVE_USELOCALE 1
82#define HAVE_NEWLOCALE 1
83#define HAVE_DUPLOCALE 1
84#define HAVE_FREELOCALE 1
85#define HAVE_MBSINIT 1
86#define HAVE_MBRTOWC 1
87#define HAVE_MPROTECT 1
88#define HAVE_MKSTEMP 1
89#define HAVE_NL_LANGINFO 1
90#define HAVE_PIPE 1
91#define HAVE_READLINK 1
92#define HAVE_ISBLANK 1
93#define HAVE_ISWCTYPE 1
94#define HAVE_LINK 1
95#define HAVE_GETUID 1
96#define HAVE_GETEUID 1
97#define HAVE_GETGID 1
98#define HAVE_GETEGID 1
99#define HAVE_SIGACTION 1
100#define HAVE_SIGALTSTACK 1
101#define HAVE_SIGINTERRUPT 1
102#define HAVE_SETRLIMIT 1
103#define HAVE_GETRLIMIT 1
104#define HAVE_SNPRINTF 1
105#define HAVE_STRERROR_R 1
106#define HAVE_WCRTOMB 1
107#define HAVE_WCWIDTH 1
108#define HAVE_FTRUNCATE 1
109#define HAVE_GETTIMEOFDAY 1
110#define HAVE_PTHREAD_SIGMASK 1
111#define HAVE_SETENV 1
112#define HAVE_SLEEP 1
113#define HAVE_CATGETS 1
114#define HAVE_SHUTDOWN 1
115#define HAVE_WCTOB 1
116#define HAVE_LANGINFO_CODESET 1
117#define HAVE_MALLOC_POSIX 1
118#define HAVE_GETCWD 1
119#define HAVE_DECL_STRERROR_R 1
120#define HAVE_STRERROR_R 1
121#define HAVE_SIG_ATOMIC_T 1
122#define HAVE_DECL_FCHDIR 1
123#define HAVE_WORKING_O_NOATIME 0
124#define HAVE_WORKING_O_NOFOLLOW 1
125#define eaccess access
126#define HAVE_DECL_ALARM 1
127#define _USE_STD_STAT 1
128#define HAVE_DECL_FSEEKO 1
129#define FUNC_FFLUSH_STDIN 0
130#define restrict /**/
131#define HAVE_DECL_FTELLO 1
132#define HAVE_DECL_GETCWD 1
133#define HAVE_DECL_GETDTABLESIZE 1
134#define HAVE_GETOPT_H 1
135#define HAVE_GETOPT_LONG_ONLY 1
136#define HAVE_PTHREAD_API 1
137#define SETLOCALE_NULL_ALL_MTSAFE 0
138#define SETLOCALE_NULL_ONE_MTSAFE 1
139#ifndef __powerpc__
140#define __powerpc__ 1
141#endif
142#ifndef __powerpc__
143#define __powerpc__ 1
144#endif
145#define HAVE_ICONV 1
146#define ICONV_CONST
147#define HAVE_WINT_T 1
148#define HAVE_LONG_LONG_INT 1
149#define HAVE_UNSIGNED_LONG_LONG_INT 1
150#define BITSIZEOF_PTRDIFF_T 32
151#define BITSIZEOF_SIZE_T 32
152#define BITSIZEOF_SIG_ATOMIC_T 32
153#define BITSIZEOF_WCHAR_T 32
154#define BITSIZEOF_WINT_T 32
155#define HAVE_SIGNED_SIG_ATOMIC_T 1
156#define HAVE_SIGNED_WCHAR_T 1
157#define HAVE_SIGNED_WINT_T 1
158#define PTRDIFF_T_SUFFIX
159#define SIZE_T_SUFFIX ul
160#define SIG_ATOMIC_T_SUFFIX
161#define WCHAR_T_SUFFIX
162#define WINT_T_SUFFIX
163#define DBL_EXPBIT0_WORD 0
164#define DBL_EXPBIT0_BIT 20
165#define FLT_EXPBIT0_WORD 0
166#define FLT_EXPBIT0_BIT 23
167#define WORDS_BIGENDIAN 1
168#define HAVE_TOWLOWER 1
169#define HAVE_WCHAR_T 1
170#define HAVE_LC_MESSAGES 1
171#define HAVE_WORKING_USELOCALE 1
172#define HAVE_GOOD_USELOCALE 1
173#define HAVE_CFPREFERENCESCOPYAPPVALUE 1
174#define HAVE_CFLOCALECOPYPREFERREDLANGUAGES 1
175#define MALLOC_0_IS_NONNULL 1
176#define HAVE_MBSTATE_T 1
177#define MAP_ANONYMOUS MAP_ANON
178#define HAVE_MAP_ANONYMOUS 1
179#define HAVE_DECL_MEMRCHR 0
180#define HAVE_MINMAX_IN_SYS_PARAM_H 1
181#define PROMOTED_MODE_T int
182#define HAVE_POSIX_SPAWN 1
183#define HAVE_DECL_POSIX_SPAWN 1
184#define REPLACE_POSIX_SPAWN 1
185#define HAVE_SIGSET_T 1
186#define HAVE_SCHED_H 1
187#define USER_LABEL_PREFIX _
188#define HAVE_DECL_SNPRINTF 1
189#define HAVE_POSIX_SPAWNATTR_T 1
190#define HAVE_POSIX_SPAWN_FILE_ACTIONS_T 1
191#define HAVE__BOOL 1
192#define HAVE_DECL_FCLOSEALL 0
193#define __USE_MINGW_ANSI_STDIO 1
194#define HAVE_DECL_ECVT 1
195#define HAVE_DECL_FCVT 1
196#define HAVE_DECL_GCVT 1
197#define HAVE_DECL_STRDUP 1
198#define REPLACE_STRERROR_0 1
199#define HAVE_DECL_STRNDUP 0
200#define HAVE_DECL_STRNLEN 0
201#define HAVE_DECL_STRSIGNAL 1
202#define HAVE_DECL_EXECVPE 0
203#define HAVE_DECL_CLEARERR_UNLOCKED 1
204#define HAVE_DECL_FEOF_UNLOCKED 1
205#define HAVE_DECL_FERROR_UNLOCKED 1
206#define HAVE_DECL_FFLUSH_UNLOCKED 0
207#define HAVE_DECL_FGETS_UNLOCKED 0
208#define HAVE_DECL_FPUTC_UNLOCKED 0
209#define HAVE_DECL_FPUTS_UNLOCKED 0
210#define HAVE_DECL_FREAD_UNLOCKED 0
211#define HAVE_DECL_FWRITE_UNLOCKED 0
212#define HAVE_DECL_GETC_UNLOCKED 1
213#define HAVE_DECL_GETCHAR_UNLOCKED 1
214#define HAVE_DECL_PUTC_UNLOCKED 1
215#define HAVE_DECL_PUTCHAR_UNLOCKED 1
216#define HAVE_INTTYPES_H_WITH_UINTMAX 1
217#define HAVE_STDINT_H_WITH_UINTMAX 1
218#define HAVE_INTMAX_T 1
219#define HAVE_SNPRINTF 1
220#define HAVE_WCSLEN 1
221#define HAVE_MBRTOWC 1
222#define HAVE_WCRTOMB 1
223#define HAVE_DECL__SNPRINTF 0
224#define HAVE_SNPRINTF_RETVAL_C99 1
225#define HAVE_SNPRINTF_TRUNCATION_C99 1
226#define CHECK_PRINTF_SAFE 1
227#define HAVE_DECL_WCSDUP 0
228#define HAVE_SHUTDOWN 1
229#define HAVE_STRUCT_SOCKADDR_STORAGE 1
230#define HAVE_SA_FAMILY_T 1
231#define HAVE_STRUCT_SOCKADDR_STORAGE_SS_FAMILY 1
232#define HAVE_IPV4 1
233#define HAVE_IPV6 1
234#define HAVE_PTHREAD_T 1
235#define HAVE_DECL_SETENV 1
236#define HAVE_SEARCH_H 1
237#define HAVE_TSEARCH 1
238#define HAVE_DECL_UNSETENV 1
239#define GNULIB_TEST_ACCESS 1
240#define HAVE_ALLOCA 1
241#define GNULIB_TEST_BTOWC 1
242#define HAVE___BUILTIN_EXPECT 1
243#define GNULIB_TEST_CALLOC_POSIX 1
244#define GNULIB_CANONICALIZE 1
245#define GNULIB_TEST_CANONICALIZE 1
246#define GNULIB_TEST_CANONICALIZE_FILE_NAME 1
247#define GNULIB_CANONICALIZE_LGPL 1
248#define GNULIB_TEST_CANONICALIZE_FILE_NAME 1
249#define GNULIB_TEST_REALPATH 1
250#define GNULIB_TEST_CHDIR 1
251#define SIGNAL_SAFE_LIST 1
252#define GNULIB_TEST_CLOEXEC 1
253#define GNULIB_TEST_CLOSE 1
254#define GNULIB_CLOSE_STREAM 1
255#define HAVE_CLOSEDIR 1
256#define GNULIB_TEST_CLOSEDIR 1
257#define D_INO_IN_DIRENT 1
258#define HAVE_DECL_DIRFD 1
259#define GNULIB_TEST_DIRFD 1
260#define GNULIB_DIRNAME 1
261#define GNULIB_TEST_DUP 1
262#define GNULIB_TEST_DUP2 1
263#define GNULIB_TEST_ENVIRON 1
264#define GNULIB_TEST_FCHDIR 1
265#define FUNC_FFLUSH_STDIN 0
266#define GNULIB_TEST_FCLOSE 1
267#define GNULIB_TEST_FCNTL 1
268#define GNULIB_FD_SAFER_FLAG 1
269#define HAVE_DECL_FDOPENDIR 0
270#define GNULIB_TEST_FDOPENDIR 1
271#define GNULIB_FDOPENDIR 1
272#define FUNC_FFLUSH_STDIN 0
273#define GNULIB_FFLUSH 1
274#define GNULIB_TEST_FFLUSH 1
275#define GNULIB_FILENAMECAT 1
276#define FLEXIBLE_ARRAY_MEMBER /**/
277#define GNULIB_TEST_FOPEN 1
278#define GNULIB_FOPEN_GNU 1
279#define GNULIB_FOPEN_SAFER 1
280#define HAVE_DECL_FPURGE 1
281#define GNULIB_TEST_FPURGE 1
282#define GNULIB_TEST_FREE_POSIX 1
283#define HAVE_FREXP_IN_LIBC 1
284#define GNULIB_TEST_FREXP 1
285#define GNULIB_TEST_FREXPL 1
286#define GNULIB_TEST_FSEEK 1
287#define FUNC_FFLUSH_STDIN 0
288#define GNULIB_TEST_FSEEKO 1
289#define GNULIB_TEST_FSTAT 1
290#define GNULIB_TEST_FSTATAT 1
291#define GNULIB_TEST_FTELL 1
292#define GNULIB_TEST_FTELLO 1
293#define HAVE_GETPAGESIZE 1
294/* end confdefs.h.  */
295
296#include <errno.h>
297#include <stdlib.h>
298#if HAVE_UNISTD_H
299# include <unistd.h>
300#else /* on Windows with MSVC */
301# include <direct.h>
302#endif
303#include <string.h>
304#include <sys/stat.h>
305
306
307/* Arrange to define PATH_MAX, like "pathmax.h" does. */
308#if HAVE_UNISTD_H
309# include <unistd.h>
310#endif
311#include <limits.h>
312#if defined HAVE_SYS_PARAM_H && !defined PATH_MAX && !defined MAXPATHLEN
313# include <sys/param.h>
314#endif
315#if !defined PATH_MAX && defined MAXPATHLEN
316# define PATH_MAX MAXPATHLEN
317#endif
318#ifdef __hpux
319# undef PATH_MAX
320# define PATH_MAX 1024
321#endif
322#if defined _WIN32 && ! defined __CYGWIN__
323# undef PATH_MAX
324# define PATH_MAX 260
325#endif
326
327
328
329
330#if defined _WIN32 && !defined __CYGWIN__
331#define access    _access
332#define chdir     _chdir
333#define chmod     _chmod
334#define close     _close
335#define creat     _creat
336#define dup       _dup
337#define dup2      _dup2
338#define ecvt      _ecvt
339#define execl     _execl
340#define execle    _execle
341#define execlp    _execlp
342#define execv     _execv
343#define execve    _execve
344#define execvp    _execvp
345#define execvpe   _execvpe
346#define fcloseall _fcloseall
347#define fcvt      _fcvt
348#define fdopen    _fdopen
349#define fileno    _fileno
350#define gcvt      _gcvt
351#define getcwd    _getcwd
352#define getpid    _getpid
353#define getw      _getw
354#define isatty    _isatty
355#define j0        _j0
356#define j1        _j1
357#define jn        _jn
358#define lfind     _lfind
359#define lsearch   _lsearch
360#define lseek     _lseek
361#define memccpy   _memccpy
362#define mkdir     _mkdir
363#define mktemp    _mktemp
364#define open      _open
365#define putenv    _putenv
366#define putw      _putw
367#define read      _read
368#define rmdir     _rmdir
369#define strdup    _strdup
370#define swab      _swab
371#define tempnam   _tempnam
372#define tzset     _tzset
373#define umask     _umask
374#define unlink    _unlink
375#define utime     _utime
376#define wcsdup    _wcsdup
377#define write     _write
378#define y0        _y0
379#define y1        _y1
380#define yn        _yn
381#endif
382
383
384
385#ifndef S_IRWXU
386# define S_IRWXU 0700
387#endif
388
389/* FIXME: skip the run-test altogether on systems without getpagesize.  */
390#if ! HAVE_GETPAGESIZE
391# define getpagesize() 0
392#endif
393
394/* This size is chosen to be larger than PATH_MAX (4k), yet smaller than
395   the 16kB pagesize on ia64 linux.  Those conditions make the code below
396   trigger a bug in glibc's getcwd implementation before 2.4.90-10.  */
397#define TARGET_LEN (5 * 1024)
398
399int
400main ()
401{
402  char *cwd;
403  size_t initial_cwd_len;
404  int fail = 0;
405
406  /* The bug is triggered when PATH_MAX < getpagesize (), so skip
407     this relatively expensive and invasive test if that's not true.  */
408#ifdef PATH_MAX
409  int bug_possible = PATH_MAX < getpagesize ();
410#else
411  int bug_possible = 0;
412#endif
413  if (! bug_possible)
414    return 0;
415
416  cwd = getcwd (NULL, 0);
417  if (cwd == NULL)
418    return 2;
419
420  initial_cwd_len = strlen (cwd);
421  free (cwd);
422
423  if (1)
424    {
425      static char const dir_name[] = "confdir-14B---";
426      size_t desired_depth = ((TARGET_LEN - 1 - initial_cwd_len)
427                              / sizeof dir_name);
428      size_t d;
429      for (d = 0; d < desired_depth; d++)
430        {
431          if (mkdir (dir_name, S_IRWXU) < 0 || chdir (dir_name) < 0)
432            {
433              if (! (errno == ERANGE || errno == ENAMETOOLONG
434                     || errno == ENOENT))
435                fail = 3; /* Unable to construct deep hierarchy.  */
436              break;
437            }
438        }
439
440      /* If libc has the bug in question, this invocation of getcwd
441         results in a failed assertion.  */
442      cwd = getcwd (NULL, 0);
443      if (cwd == NULL)
444        fail = 4; /* getcwd didn't assert, but it failed for a long name
445                     where the answer could have been learned.  */
446      free (cwd);
447
448      /* Call rmdir first, in case the above chdir failed.  */
449      rmdir (dir_name);
450      while (0 < d--)
451        {
452          if (chdir ("..") < 0)
453            {
454              fail = 5;
455              break;
456            }
457          rmdir (dir_name);
458        }
459    }
460
461  return fail;
462}
463