
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. 5: 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. 10: 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. 15: 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. */ 20: 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, '$'); \ 27: \ 28: if (__builtin_expect (__sf != NULL, 0)) \ 29: __cnt = _dl_dst_count (__sf, is_path); \ 30: \ 31: __cnt; }) 32: 33: 34: /* Guess from the number of DSTs the length of the result string. */ 35: #define DL_DST_REQUIRED(l, name, len, cnt) \ 36: ({ \ 37: size_t __len = (len); \ 38: size_t __cnt = (cnt); \ 39: \ 40: if (__cnt > 0) \ 41: { \ 42: size_t origin_len; \ 43: /* Now we make a guess how many extra characters on top of the \ 44: length of S we need to represent the result. We know that \ 45: we have CNT 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. \ 50: This can only happen for the map of the executable. */ \ 51: DL_DST_REQ_STATIC (l) \ 52: if ((l)->l_origin == NULL) \ 53: { \ 54: assert ((l)->l_name[0] == '\0'); \ 55: (l)->l_origin = _dl_get_origin (); \ 56: origin_len = ((l)->l_origin && (l)->l_origin != (char *) -1 \ 57: ? strlen ((l)->l_origin) : 0); \ 58: } \ 59: else \ 60: origin_len = (l)->l_origin == (char *) -1 \ 61: ? 0 : strlen ((l)->l_origin); \ 62: \ 63: __len += __cnt * (MAX (origin_len, GLRO(dl_platformlen)) - 7); \ 64: } \ 65: \ 66: __len; }) 67: 68: #ifdef SHARED 69: # define DL_DST_REQ_STATIC(l) /* nothing */ 70: #else 71: # define DL_DST_REQ_STATIC(l) \ 72: if ((l) == NULL) \ 73: { \ 74: const char *origin = _dl_get_origin (); \ 75: origin_len = (origin && origin != (char *) -1 ? strlen (origin) : 0); \ 76: } \ 77: else 78: #endif