Changeset 1591
- Timestamp:
- 03/10/10 23:34:43 (6 months ago)
- Files:
-
- 1 modified
-
branches/batctl-0.2.x/bat-hosts.c (modified) (4 diffs)
Legend:
- Unmodified
- Added
- Removed
-
branches/batctl-0.2.x/bat-hosts.c
r1590 r1591 151 151 char *homedir; 152 152 size_t locations = sizeof(bat_hosts_path) / sizeof(char *); 153 char *normalized[locations]; 154 153 char *normalized; 154 155 /*** 156 * realpath could allocate the memory for us but some embedded libc 157 * implementations seem to expect a buffer as second argument 158 */ 159 normalized = malloc(locations * PATH_MAX); 160 if (!normalized) { 161 printf("Warning - couldn't not get memory for bat-hosts file parsing\n"); 162 return; 163 } 164 165 memset(normalized, 0, locations * PATH_MAX); 155 166 host_hash = hash_new(64, compare_mac, choose_mac); 156 167 … … 175 186 } 176 187 177 normalized[i] = realpath(confdir, NULL); 178 if (normalized[i] == NULL) 188 if (!realpath(confdir, normalized + (i * PATH_MAX))) 179 189 continue; 180 190 … … 182 192 parse = 1; 183 193 for (j = 0; j < i; j++) { 184 if (normalized[j] == NULL) 185 continue; 186 187 if (strncmp(normalized[i], normalized[j], CONF_DIR_LEN) == 0) { 194 if (strncmp(normalized + (i * PATH_MAX), normalized + (j * PATH_MAX), CONF_DIR_LEN) == 0) { 188 195 parse = 0; 189 196 break; … … 191 198 } 192 199 193 if (parse && (normalized[i] != NULL)) 194 parse_hosts_file(&host_hash, normalized[i]); 195 } 196 197 for (i = 0; i < locations; i++) { 198 if (normalized[i]) 199 free(normalized[i]); 200 } 200 if (parse) 201 parse_hosts_file(&host_hash, normalized + (i * PATH_MAX)); 202 } 203 204 free(normalized); 201 205 } 202 206
