libmap.c (115396) | libmap.c (115400) |
---|---|
1/* | 1/* |
2 * $FreeBSD: head/libexec/rtld-elf/libmap.c 115396 2003-05-29 22:58:26Z kan $ | 2 * $FreeBSD: head/libexec/rtld-elf/libmap.c 115400 2003-05-30 00:49:16Z mdodd $ |
3 */ 4 5#include <stdio.h> 6#include <ctype.h> 7#include <string.h> 8#include <stdlib.h> 9#include <sys/queue.h> 10#include <sys/param.h> --- 15 unchanged lines hidden (view full) --- 26 27TAILQ_HEAD(lmp_list, lmp) lmp_head = TAILQ_HEAD_INITIALIZER(lmp_head); 28struct lmp { 29 char *p; 30 struct lm_list lml; 31 TAILQ_ENTRY(lmp) lmp_link; 32}; 33 | 3 */ 4 5#include <stdio.h> 6#include <ctype.h> 7#include <string.h> 8#include <stdlib.h> 9#include <sys/queue.h> 10#include <sys/param.h> --- 15 unchanged lines hidden (view full) --- 26 27TAILQ_HEAD(lmp_list, lmp) lmp_head = TAILQ_HEAD_INITIALIZER(lmp_head); 28struct lmp { 29 char *p; 30 struct lm_list lml; 31 TAILQ_ENTRY(lmp) lmp_link; 32}; 33 |
34static void lm_add (char *, char *, char *); | 34static void lm_add (const char *, const char *, const char *); |
35static void lm_free (struct lm_list *); 36static char * lml_find (struct lm_list *, const char *); 37static struct lm_list * lmp_find (const char *); 38static struct lm_list * lmp_init (char *); 39 40#define iseol(c) (((c) == '#') || ((c) == '\0') || \ 41 ((c) == '\n') || ((c) == '\r')) 42 43void 44lm_init (void) 45{ 46 FILE *fp; 47 char *cp; | 35static void lm_free (struct lm_list *); 36static char * lml_find (struct lm_list *, const char *); 37static struct lm_list * lmp_find (const char *); 38static struct lm_list * lmp_init (char *); 39 40#define iseol(c) (((c) == '#') || ((c) == '\0') || \ 41 ((c) == '\n') || ((c) == '\r')) 42 43void 44lm_init (void) 45{ 46 FILE *fp; 47 char *cp; |
48 char *f, *t, *p; | 48 char *f, *t, *p, *c; |
49 char prog[MAXPATHLEN]; 50 char line[MAXPATHLEN + 2]; 51 52 TAILQ_INIT(&lmp_head); 53 54 if ((fp = fopen(_PATH_LIBMAP_CONF, "r")) == NULL) 55 return; 56 57 p = NULL; 58 while ((cp = fgets(line, MAXPATHLEN + 1, fp)) != NULL) { | 49 char prog[MAXPATHLEN]; 50 char line[MAXPATHLEN + 2]; 51 52 TAILQ_INIT(&lmp_head); 53 54 if ((fp = fopen(_PATH_LIBMAP_CONF, "r")) == NULL) 55 return; 56 57 p = NULL; 58 while ((cp = fgets(line, MAXPATHLEN + 1, fp)) != NULL) { |
59 t = f = NULL; | 59 t = f = c = NULL; |
60 61 /* Skip over leading space */ 62 while (isspace(*cp)) cp++; 63 64 /* Found a comment or EOL */ 65 if (iseol(*cp)) continue; 66 67 /* Found a constraint selector */ 68 if (*cp == '[') { 69 cp++; 70 71 /* Skip leading space */ 72 while (isspace(*cp)) cp++; 73 74 /* Found comment, EOL or end of selector */ 75 if (iseol(*cp) || *cp == ']') 76 continue; 77 | 60 61 /* Skip over leading space */ 62 while (isspace(*cp)) cp++; 63 64 /* Found a comment or EOL */ 65 if (iseol(*cp)) continue; 66 67 /* Found a constraint selector */ 68 if (*cp == '[') { 69 cp++; 70 71 /* Skip leading space */ 72 while (isspace(*cp)) cp++; 73 74 /* Found comment, EOL or end of selector */ 75 if (iseol(*cp) || *cp == ']') 76 continue; 77 |
78 p = cp++; | 78 c = cp++; |
79 /* Skip to end of word */ 80 while (!isspace(*cp) && !iseol(*cp) && *cp != ']') 81 cp++; 82 83 /* Skip and zero out trailing space */ 84 while (isspace(*cp)) *cp++ = '\0'; 85 86 /* Check if there is a closing brace */ 87 if (*cp != ']') continue; 88 89 /* Terminate string if there was no trailing space */ 90 *cp++ = '\0'; 91 92 /* 93 * There should be nothing except whitespace or comment 94 from this point to the end of the line. 95 */ | 79 /* Skip to end of word */ 80 while (!isspace(*cp) && !iseol(*cp) && *cp != ']') 81 cp++; 82 83 /* Skip and zero out trailing space */ 84 while (isspace(*cp)) *cp++ = '\0'; 85 86 /* Check if there is a closing brace */ 87 if (*cp != ']') continue; 88 89 /* Terminate string if there was no trailing space */ 90 *cp++ = '\0'; 91 92 /* 93 * There should be nothing except whitespace or comment 94 from this point to the end of the line. 95 */ |
96 while(isspace(*cp++)); | 96 while(isspace(*cp)) *cp++; |
97 if (!iseol(*cp)) continue; 98 | 97 if (!iseol(*cp)) continue; 98 |
99 strcpy(prog, p); | 99 strcpy(prog, c); |
100 p = prog; 101 continue; 102 } 103 104 /* Parse the 'from' candidate. */ 105 f = cp++; 106 while (!isspace(*cp) && !iseol(*cp)) cp++; 107 --- 9 unchanged lines hidden (view full) --- 117 118 /* Skip and zero out the trailing whitespace */ 119 while (isspace(*cp)) *cp++ = '\0'; 120 121 /* Should be no extra tokens at this point */ 122 if (!iseol(*cp)) continue; 123 124 *cp = '\0'; | 100 p = prog; 101 continue; 102 } 103 104 /* Parse the 'from' candidate. */ 105 f = cp++; 106 while (!isspace(*cp) && !iseol(*cp)) cp++; 107 --- 9 unchanged lines hidden (view full) --- 117 118 /* Skip and zero out the trailing whitespace */ 119 while (isspace(*cp)) *cp++ = '\0'; 120 121 /* Should be no extra tokens at this point */ 122 if (!iseol(*cp)) continue; 123 124 *cp = '\0'; |
125 lm_add(p, xstrdup(f), xstrdup(t)); | 125 lm_add(p, f, t); |
126 } 127 fclose(fp); 128 return; 129} 130 131static void 132lm_free (struct lm_list *lml) 133{ --- 20 unchanged lines hidden (view full) --- 154 free(lmp->p); 155 lm_free(&lmp->lml); 156 free(lmp); 157 } 158 return; 159} 160 161static void | 126 } 127 fclose(fp); 128 return; 129} 130 131static void 132lm_free (struct lm_list *lml) 133{ --- 20 unchanged lines hidden (view full) --- 154 free(lmp->p); 155 lm_free(&lmp->lml); 156 free(lmp); 157 } 158 return; 159} 160 161static void |
162lm_add (char *p, char *f, char *t) | 162lm_add (const char *p, const char *f, const char *t) |
163{ 164 struct lm_list *lml; 165 struct lm *lm; 166 167 if (p == NULL) 168 p = "$DEFAULT$"; 169 170 if ((lml = lmp_find(p)) == NULL) 171 lml = lmp_init(xstrdup(p)); 172 173 lm = xmalloc(sizeof(struct lm)); | 163{ 164 struct lm_list *lml; 165 struct lm *lm; 166 167 if (p == NULL) 168 p = "$DEFAULT$"; 169 170 if ((lml = lmp_find(p)) == NULL) 171 lml = lmp_init(xstrdup(p)); 172 173 lm = xmalloc(sizeof(struct lm)); |
174 lm->f = f; 175 lm->t = t; | 174 lm->f = xstrdup(f); 175 lm->t = xstrdup(t); |
176 TAILQ_INSERT_HEAD(lml, lm, lm_link); 177} 178 179char * 180lm_find (const char *p, const char *f) 181{ 182 struct lm_list *lml; 183 char *t; 184 185 if (p != NULL && (lml = lmp_find(p)) != NULL) { 186 t = lml_find(lml, f); 187 if (t != NULL) { 188 /* 189 * Add a global mapping if we have 190 * a successful constrained match. 191 */ | 176 TAILQ_INSERT_HEAD(lml, lm, lm_link); 177} 178 179char * 180lm_find (const char *p, const char *f) 181{ 182 struct lm_list *lml; 183 char *t; 184 185 if (p != NULL && (lml = lmp_find(p)) != NULL) { 186 t = lml_find(lml, f); 187 if (t != NULL) { 188 /* 189 * Add a global mapping if we have 190 * a successful constrained match. 191 */ |
192 lm_add(NULL, xstrdup(f), xstrdup(t)); | 192 lm_add(NULL, f, t); |
193 return (t); 194 } 195 } 196 lml = lmp_find("$DEFAULT$"); 197 if (lml != NULL) 198 return (lml_find(lml, f)); 199 else 200 return (NULL); --- 39 unchanged lines hidden --- | 193 return (t); 194 } 195 } 196 lml = lmp_find("$DEFAULT$"); 197 if (lml != NULL) 198 return (lml_find(lml, f)); 199 else 200 return (NULL); --- 39 unchanged lines hidden --- |