summaryrefslogtreecommitdiffstats
path: root/common
diff options
context:
space:
mode:
Diffstat (limited to 'common')
-rw-r--r--common/userpref.c76
-rw-r--r--common/userpref.h1
2 files changed, 4 insertions, 73 deletions
diff --git a/common/userpref.c b/common/userpref.c
index ec1b182..3fc4adc 100644
--- a/common/userpref.c
+++ b/common/userpref.c
@@ -117,57 +117,9 @@ static char *userpref_utf16_to_utf8(wchar_t *unistr, long len, long *items_read,
117} 117}
118#endif 118#endif
119 119
120#ifndef WIN32 120const char *userpref_get_config_dir()
121static char *get_home_dir_from_system(void)
122{
123 long bufsize;
124 char *buf;
125 int error;
126 struct passwd pwd;
127 struct passwd *ppwd;
128 char *result = NULL;
129
130 bufsize = sysconf (_SC_GETPW_R_SIZE_MAX);
131
132 if (bufsize < 0)
133 bufsize = 1024;
134
135 buf = NULL;
136
137 do {
138 free (buf);
139 buf = malloc (bufsize);
140 if (!buf)
141 return NULL;
142
143 errno = 0;
144 error = getpwuid_r (getuid (), &pwd, buf, bufsize, &ppwd);
145
146 error = (error < 0) ? errno : error;
147
148 if (!ppwd) {
149 if (error == 0 || error == ENOENT)
150 break;
151 else if (bufsize > 32 * 1024)
152 break; /* Unreasonable size; let's bail out */
153
154 bufsize *= 2;
155 }
156 } while (!ppwd);
157
158 if (ppwd && ppwd->pw_dir)
159 result = strdup (ppwd->pw_dir);
160
161 free (buf);
162
163 return result;
164}
165#endif
166
167static const char *userpref_get_config_dir()
168{ 121{
169 char *base_config_dir = NULL; 122 char *base_config_dir = NULL;
170 int use_dot_config;
171 123
172 if (__config_dir) 124 if (__config_dir)
173 return __config_dir; 125 return __config_dir;
@@ -186,36 +138,14 @@ static const char *userpref_get_config_dir()
186 CoTaskMemFree (pidl); 138 CoTaskMemFree (pidl);
187 } 139 }
188 } 140 }
189
190 use_dot_config = 0;
191#else 141#else
192#ifdef __APPLE__ 142#ifdef __APPLE__
193 base_config_dir = strdup("/var/db"); 143 base_config_dir = strdup("/var/db");
194 use_dot_config = 0;
195#else 144#else
196 const char *cdir = getenv("XDG_CONFIG_HOME"); 145 base_config_dir = strdup("/var/lib");
197 if (!cdir) {
198 cdir = getenv("HOME");
199 if (!cdir || !cdir[0]) {
200 base_config_dir = get_home_dir_from_system();
201 if (!base_config_dir)
202 return NULL;
203 } else {
204 base_config_dir = strdup(cdir);
205 }
206
207 use_dot_config = 1;
208 } else {
209 base_config_dir = strdup(cdir);
210 use_dot_config = 0;
211 }
212#endif 146#endif
213#endif 147#endif
214 148 __config_dir = string_concat(base_config_dir, DIR_SEP_S, USERPREF_CONFIG_DIR, NULL);
215 if (use_dot_config)
216 __config_dir = string_concat(base_config_dir, DIR_SEP_S, ".config", DIR_SEP_S, USERPREF_CONFIG_DIR, NULL);
217 else
218 __config_dir = string_concat(base_config_dir, DIR_SEP_S, USERPREF_CONFIG_DIR, NULL);
219 149
220 if (__config_dir) { 150 if (__config_dir) {
221 int i = strlen(__config_dir)-1; 151 int i = strlen(__config_dir)-1;
diff --git a/common/userpref.h b/common/userpref.h
index da9d454..07fed8d 100644
--- a/common/userpref.h
+++ b/common/userpref.h
@@ -84,6 +84,7 @@ LIBIMOBILEDEVICE_INTERNAL int userpref_has_device_record(const char *udid);
84userpref_error_t userpref_get_paired_udids(char ***list, unsigned int *count); 84userpref_error_t userpref_get_paired_udids(char ***list, unsigned int *count);
85void userpref_device_record_get_host_id(const char *udid, char **host_id); 85void userpref_device_record_get_host_id(const char *udid, char **host_id);
86void userpref_get_system_buid(char **system_buid); 86void userpref_get_system_buid(char **system_buid);
87const char *userpref_get_config_dir();
87 88
88userpref_error_t userpref_get_device_record(const char *udid, plist_t *device_record); 89userpref_error_t userpref_get_device_record(const char *udid, plist_t *device_record);
89int userpref_get_value(const char *key, plist_t *value); 90int userpref_get_value(const char *key, plist_t *value);