1 /* { dg-do compile } */
2 /* { dg-options "-O2" } */
4 extern __SIZE_TYPE__
strlen (__const
char *__s
)
5 __attribute__ ((__nothrow__
)) __attribute__ ((__pure__
)) __attribute__ ((__nonnull__ (1)));
6 extern char *strcpy (char *__restrict __dest
, __const
char *__restrict __src
)
7 __attribute__ ((__nothrow__
)) __attribute__ ((__nonnull__ (1, 2)));
8 extern char *getenv (__const
char *__name
) __attribute__ ((__nothrow__
)) __attribute__ ((__nonnull__ (1)));
9 extern int access (__const
char *__name
, int __type
) __attribute__ ((__nothrow__
)) __attribute__ ((__nonnull__ (1)));
10 extern void * xmalloc (__SIZE_TYPE__
) __attribute__ ((__malloc__
));
12 static __inline__
const char *
13 try (const char *dir
, const char *base
)
18 && access (dir
, 4 | 2 | 1) == 0)
23 static const char tmp
[] = { '/', 't', 'm', 'p', 0 };
24 static const char usrtmp
[] =
25 { '/', 'u', 's', 'r', '/', 't', 'm', 'p', 0 };
26 static const char vartmp
[] =
27 { '/', 'v', 'a', 'r', '/', 't', 'm', 'p', 0 };
29 static char *memoized_tmpdir
;
38 return memoized_tmpdir
;
40 base
= try (getenv ("TMPDIR"), base
);
41 base
= try (getenv ("TMP"), base
);
42 base
= try (getenv ("TEMP"), base
);
45 base
= try ("/tmp", base
);
49 base
= try (vartmp
, base
);
50 base
= try (usrtmp
, base
);
51 base
= try (tmp
, base
);
60 tmpdir
= xmalloc (len
+ 2);
61 strcpy (tmpdir
, base
);
62 /* Alias analysis was associating read-only memory tags to pointers
63 that are not read-only. We would then not issue any V_MAY_DEF in
68 memoized_tmpdir
= tmpdir
;