Update.
[platform/upstream/glibc.git] / elf / dl-dst.h
1 /* Handling of dynamic sring tokens.
2    Copyright (C) 1999, 2001, 2002 Free Software Foundation, Inc.
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
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.
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
13    Lesser General Public License for more details.
14
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.  */
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                                                                               \
27     if (__builtin_expect (__sf != NULL, 0))                                   \
28       __cnt = INTUSE(_dl_dst_count) (__sf, is_path);                          \
29                                                                               \
30     __cnt; })
31
32 /* Prototype for used function.  */
33 extern size_t _dl_dst_count (const char *name, int is_path);
34 extern size_t _dl_dst_count_internal (const char *name, int is_path);
35
36
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 origin_len;                                                        \
41     size_t __len = (len);                                                     \
42                                                                               \
43     /* Now we make a guess how many extra characters on top of the length     \
44        of S we need to represent the result.  We know that we have CNT        \
45        replacements.  Each at most can use                                    \
46          MAX (strlen (ORIGIN), strlen (_dl_platform))                         \
47        minus 7 (which is the length of "$ORIGIN").                            \
48                                                                               \
49        First get the origin string if it is not available yet.  This can      \
50        only happen for the map of the executable.  */                         \
51     if ((l)->l_origin == NULL)                                                \
52       {                                                                       \
53         assert ((l)->l_name[0] == '\0');                                      \
54         (l)->l_origin = _dl_get_origin ();                                    \
55         origin_len = ((l)->l_origin && (l)->l_origin != (char *) -1           \
56                       ? strlen ((l)->l_origin) : 0);                          \
57       }                                                                       \
58     else                                                                      \
59       origin_len = (l)->l_origin == (char *) -1 ? 0 : strlen ((l)->l_origin); \
60                                                                               \
61     __len + cnt * (MAX (origin_len, GL(dl_platformlen)) - 7); })
62
63 /* Find origin of the executable.  */
64 extern const char *_dl_get_origin (void);
65 extern const char *_dl_get_origin_internal (void);
66
67 #ifdef IS_IN_rtld
68 # define _dl_get_origin INTUSE(_dl_get_origin)
69 #endif
70
71 /* Prototype for used function.  */
72 extern char *_dl_dst_substitute (struct link_map *l, const char *name,
73                                  char *result, int is_path);
74 extern char *_dl_dst_substitute_internal (struct link_map *l, const char *name,
75                                           char *result, int is_path);