summaryrefslogtreecommitdiff
path: root/include/stdlib.h
blob: 9d3698a29624462576a44b1ab3d10f39bd3126ea (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#ifndef _FORTIFY_STDLIB_H
#define _FORTIFY_STDLIB_H

#if defined(_XOPEN_SOURCE) || defined(_GNU_SOURCE) || defined(_BSD_SOURCE)
#include_next <limits.h>
#endif

#include_next <stdlib.h>

#if defined(_FORTIFY_SOURCE) && _FORTIFY_SOURCE > 0 && defined(__OPTIMIZE__) && __OPTIMIZE__ > 0

#ifdef __cplusplus
extern "C" {
#endif

#if defined(_XOPEN_SOURCE) || defined(_GNU_SOURCE) || defined(_BSD_SOURCE)
#undef realpath
extern char *__realpath_orig(const char *, char *)
	__asm__(__USER_LABEL_PREFIX__ "realpath");
extern __inline __attribute__((__always_inline__,__gnu_inline__))
char *realpath(const char *path, char *resolved)
{
	size_t bos;

	if (resolved) {
#ifndef PATH_MAX
		__builtin_trap();
#else
		bos = __builtin_object_size(resolved, 0);
		if (PATH_MAX > bos)
			__builtin_trap();
#endif
	}
	return __realpath_orig(path, resolved);
}
#endif

#ifdef __cplusplus
}
#endif

#endif

#endif