Back to index

glibc  2.9
dl-dst.h
Go to the documentation of this file.
00001 /* Handling of dynamic sring tokens.
00002    Copyright (C) 1999,2001,2002,2003,2004,2006,2007
00003    Free Software Foundation, Inc.
00004    This file is part of the GNU C Library.
00005 
00006    The GNU C Library is free software; you can redistribute it and/or
00007    modify it under the terms of the GNU Lesser General Public
00008    License as published by the Free Software Foundation; either
00009    version 2.1 of the License, or (at your option) any later version.
00010 
00011    The GNU C Library is distributed in the hope that it will be useful,
00012    but WITHOUT ANY WARRANTY; without even the implied warranty of
00013    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00014    Lesser General Public License for more details.
00015 
00016    You should have received a copy of the GNU Lesser General Public
00017    License along with the GNU C Library; if not, write to the Free
00018    Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
00019    02111-1307 USA.  */
00020 
00021 /* Determine the number of DST elements in the name.  Only if IS_PATH is
00022    nonzero paths are recognized (i.e., multiple, ':' separated filenames).  */
00023 #define DL_DST_COUNT(name, is_path) \
00024   ({                                                                 \
00025     size_t __cnt = 0;                                                       \
00026     const char *__sf = strchr (name, '$');                                  \
00027                                                                      \
00028     if (__builtin_expect (__sf != NULL, 0))                                 \
00029       __cnt = _dl_dst_count (__sf, is_path);                         \
00030                                                                      \
00031     __cnt; })
00032 
00033 
00034 /* Guess from the number of DSTs the length of the result string.  */
00035 #define DL_DST_REQUIRED(l, name, len, cnt) \
00036   ({                                                                 \
00037     size_t __len = (len);                                            \
00038     size_t __cnt = (cnt);                                            \
00039                                                                      \
00040     if (__cnt > 0)                                                   \
00041       {                                                                     \
00042        size_t origin_len;                                            \
00043        /* Now we make a guess how many extra characters on top of the       \
00044           length of S we need to represent the result.  We know that        \
00045           we have CNT replacements.  Each at most can use                   \
00046             MAX (strlen (ORIGIN), strlen (_dl_platform))                    \
00047           minus 7 (which is the length of "$ORIGIN").                       \
00048                                                                      \
00049           First get the origin string if it is not available yet.           \
00050           This can only happen for the map of the executable.  */           \
00051        DL_DST_REQ_STATIC (l)                                                \
00052        if ((l)->l_origin == NULL)                                    \
00053          {                                                           \
00054            assert ((l)->l_name[0] == '\0');                                 \
00055            (l)->l_origin = _dl_get_origin ();                               \
00056            origin_len = ((l)->l_origin && (l)->l_origin != (char *) -1             \
00057                        ? strlen ((l)->l_origin) : 0);                \
00058          }                                                           \
00059        else                                                          \
00060          origin_len = (l)->l_origin == (char *) -1                          \
00061            ? 0 : strlen ((l)->l_origin);                             \
00062                                                                      \
00063        __len += __cnt * (MAX (origin_len, GLRO(dl_platformlen)) - 7);       \
00064       }                                                                     \
00065                                                                      \
00066     __len; })
00067 
00068 #ifdef SHARED
00069 # define DL_DST_REQ_STATIC(l) /* nothing */
00070 #else
00071 # define DL_DST_REQ_STATIC(l) \
00072   if ((l) == NULL)                                                   \
00073     {                                                                \
00074       const char *origin = _dl_get_origin ();                               \
00075       origin_len = (origin && origin != (char *) -1 ? strlen (origin) : 0);   \
00076     }                                                                \
00077   else
00078 #endif