Add missing file
[glibc.git] / elf / dl-dst.h
blobae8d119c0d05f810abb0e0f62d2584dbae348ec8
1 /* Handling of dynamic sring tokens.
2 Copyright (C) 1999,2001,2002,2003,2004,2006,2007
3 Free Software Foundation, Inc.
4 This file is part of the GNU C Library.
6 The GNU C Library is free software; you can redistribute it and/or
7 modify it under the terms of the GNU Lesser General Public
8 License as published by the Free Software Foundation; either
9 version 2.1 of the License, or (at your option) any later version.
11 The GNU C Library is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 Lesser General Public License for more details.
16 You should have received a copy of the GNU Lesser General Public
17 License along with the GNU C Library; if not, write to the Free
18 Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
19 02111-1307 USA. */
21 #include "trusted-dirs.h"
23 /* Determine the number of DST elements in the name. Only if IS_PATH is
24 nonzero paths are recognized (i.e., multiple, ':' separated filenames). */
25 #define DL_DST_COUNT(name, is_path) \
26 ({ \
27 size_t __cnt = 0; \
28 const char *__sf = strchr (name, '$'); \
30 if (__builtin_expect (__sf != NULL, 0)) \
31 __cnt = _dl_dst_count (__sf, is_path); \
33 __cnt; })
36 /* Guess from the number of DSTs the length of the result string. */
37 #define DL_DST_REQUIRED(l, name, len, cnt) \
38 ({ \
39 size_t __len = (len); \
40 size_t __cnt = (cnt); \
42 if (__cnt > 0) \
43 { \
44 size_t dst_len; \
45 /* Now we make a guess how many extra characters on top of the \
46 length of S we need to represent the result. We know that \
47 we have CNT replacements. Each at most can use \
48 MAX (MAX (strlen (ORIGIN), strlen (_dl_platform)), \
49 strlen (DL_DST_LIB)) \
50 minus 4 (which is the length of "$LIB"). \
52 First get the origin string if it is not available yet. \
53 This can only happen for the map of the executable. */ \
54 DL_DST_REQ_STATIC (l) \
55 if ((l)->l_origin == NULL) \
56 { \
57 assert ((l)->l_name[0] == '\0'); \
58 (l)->l_origin = _dl_get_origin (); \
59 dst_len = ((l)->l_origin && (l)->l_origin != (char *) -1 \
60 ? strlen ((l)->l_origin) : 0); \
61 } \
62 else \
63 dst_len = (l)->l_origin == (char *) -1 \
64 ? 0 : strlen ((l)->l_origin); \
65 dst_len = MAX (MAX (dst_len, GLRO(dl_platformlen)), \
66 strlen (DL_DST_LIB)); \
67 if (dst_len > 4) \
68 __len += __cnt * (dst_len - 4); \
69 } \
71 __len; })
73 #ifdef SHARED
74 # define DL_DST_REQ_STATIC(l) /* nothing */
75 #else
76 # define DL_DST_REQ_STATIC(l) \
77 if ((l) == NULL) \
78 { \
79 const char *origin = _dl_get_origin (); \
80 dst_len = (origin && origin != (char *) -1 ? strlen (origin) : 0); \
81 } \
82 else
83 #endif