diff options
Diffstat (limited to 'common/userpref.c')
| -rw-r--r-- | common/userpref.c | 53 |
1 files changed, 24 insertions, 29 deletions
diff --git a/common/userpref.c b/common/userpref.c index 0fa5b96..b985285 100644 --- a/common/userpref.c +++ b/common/userpref.c | |||
| @@ -208,14 +208,8 @@ int userpref_read_system_buid(char **system_buid) | |||
| 208 | */ | 208 | */ |
| 209 | userpref_error_t userpref_get_paired_udids(char ***list, unsigned int *count) | 209 | userpref_error_t userpref_get_paired_udids(char ***list, unsigned int *count) |
| 210 | { | 210 | { |
| 211 | struct slist_t { | ||
| 212 | char *name; | ||
| 213 | void *next; | ||
| 214 | }; | ||
| 215 | DIR *config_dir; | 211 | DIR *config_dir; |
| 216 | const char *config_path = NULL; | 212 | const char *config_path = NULL; |
| 217 | struct slist_t *udids = NULL; | ||
| 218 | unsigned int i; | ||
| 219 | unsigned int found = 0; | 213 | unsigned int found = 0; |
| 220 | 214 | ||
| 221 | if (!list || (list && *list)) { | 215 | if (!list || (list && *list)) { |
| @@ -226,41 +220,42 @@ userpref_error_t userpref_get_paired_udids(char ***list, unsigned int *count) | |||
| 226 | if (count) { | 220 | if (count) { |
| 227 | *count = 0; | 221 | *count = 0; |
| 228 | } | 222 | } |
| 223 | *list = (char**)malloc(sizeof(char*)); | ||
| 229 | 224 | ||
| 230 | config_path = userpref_get_config_dir(); | 225 | config_path = userpref_get_config_dir(); |
| 231 | config_dir = opendir(config_path); | 226 | config_dir = opendir(config_path); |
| 232 | if (config_dir) { | 227 | if (config_dir) { |
| 233 | struct dirent *entry; | 228 | struct dirent *entry; |
| 234 | struct slist_t *listp = udids; | ||
| 235 | while ((entry = readdir(config_dir))) { | 229 | while ((entry = readdir(config_dir))) { |
| 236 | char *ext = strstr(entry->d_name, USERPREF_CONFIG_EXTENSION); | 230 | if (strcmp(entry->d_name, USERPREF_CONFIG_FILE) == 0) { |
| 237 | if (ext && ((ext - entry->d_name) == 40) && (strlen(entry->d_name) == (40 + strlen(ext)))) { | 231 | /* ignore SystemConfiguration.plist */ |
| 238 | struct slist_t *ne = (struct slist_t*)malloc(sizeof(struct slist_t)); | 232 | continue; |
| 239 | ne->name = (char*)malloc(41); | 233 | } |
| 240 | strncpy(ne->name, entry->d_name, 40); | 234 | char *ext = strrchr(entry->d_name, '.'); |
| 241 | ne->name[40] = 0; | 235 | if (ext && (strcmp(ext, USERPREF_CONFIG_EXTENSION) == 0)) { |
| 242 | ne->next = NULL; | 236 | size_t len = strlen(entry->d_name) - strlen(USERPREF_CONFIG_EXTENSION); |
| 243 | if (!listp) { | 237 | char **newlist = (char**)realloc(*list, sizeof(char*) * (found+2)); |
| 244 | listp = ne; | 238 | if (!newlist) { |
| 245 | udids = listp; | 239 | fprintf(stderr, "ERROR: Out of memory\n"); |
| 246 | } else { | 240 | break; |
| 247 | listp->next = ne; | 241 | } |
| 248 | listp = listp->next; | 242 | *list = newlist; |
| 243 | char *tmp = (char*)malloc(len+1); | ||
| 244 | if (tmp) { | ||
| 245 | strncpy(tmp, entry->d_name, len); | ||
| 246 | tmp[len] = '\0'; | ||
| 247 | } | ||
| 248 | (*list)[found] = tmp; | ||
| 249 | if (!tmp) { | ||
| 250 | fprintf(stderr, "ERROR: Out of memory\n"); | ||
| 251 | break; | ||
| 249 | } | 252 | } |
| 250 | found++; | 253 | found++; |
| 251 | } | 254 | } |
| 252 | } | 255 | } |
| 253 | closedir(config_dir); | 256 | closedir(config_dir); |
| 254 | } | 257 | } |
| 255 | *list = (char**)malloc(sizeof(char*) * (found+1)); | 258 | (*list)[found] = NULL; |
| 256 | i = 0; | ||
| 257 | while (udids) { | ||
| 258 | (*list)[i++] = udids->name; | ||
| 259 | struct slist_t *old = udids; | ||
| 260 | udids = udids->next; | ||
| 261 | free(old); | ||
| 262 | } | ||
| 263 | (*list)[i] = NULL; | ||
| 264 | 259 | ||
| 265 | if (count) { | 260 | if (count) { |
| 266 | *count = found; | 261 | *count = found; |
