Updated to fedora-glibc-20070317T2130
[glibc.git] / elf / dl-dst.h
blob175b7cd195148a3e82e825d42ab56605667e70bd
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 /* Determine the number of DST elements in the name. Only if IS_PATH is
22 nonzero paths are recognized (i.e., multiple, ':' separated filenames). */
23 #define DL_DST_COUNT(name, is_path) \
24 ({ \
25 size_t __cnt = 0; \
26 const char *__sf = strchr (name, '$'); \
28 if (__builtin_expect (__sf != NULL, 0)) \
29 __cnt = _dl_dst_count (__sf, is_path); \
31 __cnt; })
32 #ifndef IS_IN_rtld
33 # define _dl_dst_count GLRO(dl_dst_count)
34 #endif
37 /* Guess from the number of DSTs the length of the result string. */
38 #define DL_DST_REQUIRED(l, name, len, cnt) \
39 ({ \
40 size_t __len = (len); \
41 size_t __cnt = (cnt); \
43 if (__cnt > 0) \
44 { \
45 size_t origin_len; \
46 /* Now we make a guess how many extra characters on top of the \
47 length of S we need to represent the result. We know that \
48 we have CNT replacements. Each at most can use \
49 MAX (strlen (ORIGIN), strlen (_dl_platform)) \
50 minus 7 (which is the length of "$ORIGIN"). \
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 origin_len = ((l)->l_origin && (l)->l_origin != (char *) -1 \
60 ? strlen ((l)->l_origin) : 0); \
61 } \
62 else \
63 origin_len = (l)->l_origin == (char *) -1 \
64 ? 0 : strlen ((l)->l_origin); \
66 __len += __cnt * (MAX (origin_len, GLRO(dl_platformlen)) - 7); \
67 } \
69 __len; })
71 #ifdef SHARED
72 # define DL_DST_REQ_STATIC(l) /* nothing */
73 #else
74 # define DL_DST_REQ_STATIC(l) \
75 if ((l) == NULL) \
76 { \
77 const char *origin = _dl_get_origin (); \
78 origin_len = (origin && origin != (char *) -1 ? strlen (origin) : 0); \
79 } \
80 else
81 #endif
83 #ifndef IS_IN_rtld
84 # define _dl_get_origin GLRO(dl_get_origin)
85 # define _dl_dst_substitute GLRO(dl_dst_substitute)
86 #endif