]> git.ipfire.org Git - thirdparty/glibc.git/blame - elf/dl-dst.h
Update.
[thirdparty/glibc.git] / elf / dl-dst.h
CommitLineData
dc5efe83 1/* Handling of dynamic sring tokens.
d6b5d570 2 Copyright (C) 1999, 2001, 2002 Free Software Foundation, Inc.
dc5efe83
UD
3 This file is part of the GNU C Library.
4
5 The GNU C Library is free software; you can redistribute it and/or
41bdb6e2
AJ
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 2.1 of the License, or (at your option) any later version.
dc5efe83
UD
9
10 The GNU C Library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
41bdb6e2 13 Lesser General Public License for more details.
dc5efe83 14
41bdb6e2
AJ
15 You should have received a copy of the GNU Lesser General Public
16 License along with the GNU C Library; if not, write to the Free
17 Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
18 02111-1307 USA. */
dc5efe83
UD
19
20/* Determine the number of DST elements in the name. Only if IS_PATH is
21 nonzero paths are recognized (i.e., multiple, ':' separated filenames). */
22#define DL_DST_COUNT(name, is_path) \
23 ({ \
24 size_t __cnt = 0; \
25 const char *__sf = strchr (name, '$'); \
26 \
2541eda0 27 if (__builtin_expect (__sf != NULL, 0)) \
dc5efe83
UD
28 __cnt = _dl_dst_count (__sf, is_path); \
29 \
30 __cnt; })
31
32/* Prototype for used function. */
33extern size_t _dl_dst_count (const char *name, int is_path);
34
35
b3fc5f84 36/* Guess from the number of DSTs the length of the result string. */
dc5efe83
UD
37#define DL_DST_REQUIRED(l, name, len, cnt) \
38 ({ \
39 size_t origin_len; \
40 size_t __len = (len); \
41 \
42 /* Now we make a guess how many extra characters on top of the length \
43 of S we need to represent the result. We know that we have CNT \
44 replacements. Each at most can use \
45 MAX (strlen (ORIGIN), strlen (_dl_platform)) \
46 minus 7 (which is the length of "$ORIGIN"). \
47 \
48 First get the origin string if it is not available yet. This can \
49 only happen for the map of the executable. */ \
50 if ((l)->l_origin == NULL) \
51 { \
52 assert ((l)->l_name[0] == '\0'); \
53 (l)->l_origin = _dl_get_origin (); \
54 origin_len = ((l)->l_origin && (l)->l_origin != (char *) -1 \
55 ? strlen ((l)->l_origin) : 0); \
56 } \
57 else \
58 origin_len = (l)->l_origin == (char *) -1 ? 0 : strlen ((l)->l_origin); \
59 \
d6b5d570 60 __len + cnt * (MAX (origin_len, GL(dl_platformlen)) - 7); })
dc5efe83
UD
61
62/* Find origin of the executable. */
63extern const char *_dl_get_origin (void);
64
65
66/* Perform the DST substitution. */
67#define DL_DST_SUBSTITUTE(l, name, res, is_path) \
68 _dl_dst_substitute (l, name, res, is_path)
69
70/* Prototype for used function. */
71extern char *_dl_dst_substitute (struct link_map *l, const char *name,
72 char *result, int is_path);