Lines 141-161
home_directory(uim_lisp user_)
Link Here
|
141 |
return MAKE_STR(home); |
141 |
return MAKE_STR(home); |
142 |
} |
142 |
} |
143 |
|
143 |
|
144 |
uim_bool |
144 |
static uim_bool |
145 |
uim_check_dir(const char *dir) |
145 |
uim_check_dir_internal(const char *dir, int need_prepare) |
146 |
{ |
146 |
{ |
147 |
struct stat st; |
147 |
struct stat st; |
148 |
|
148 |
|
149 |
if (stat(dir, &st) < 0) |
149 |
if (stat(dir, &st) < 0) |
150 |
return (mkdir(dir, 0700) < 0) ? UIM_FALSE : UIM_TRUE; |
150 |
if (need_prepare) |
|
|
151 |
return (mkdir(dir, 0700) < 0) ? UIM_FALSE : UIM_TRUE; |
152 |
else |
153 |
return UIM_FALSE; |
151 |
else { |
154 |
else { |
152 |
mode_t mode = S_IFDIR | S_IRUSR | S_IWUSR | S_IXUSR; |
155 |
mode_t mode = S_IFDIR | S_IRUSR | S_IWUSR | S_IXUSR; |
153 |
return ((st.st_mode & mode) == mode) ? UIM_TRUE : UIM_FALSE; |
156 |
return ((st.st_mode & mode) == mode) ? UIM_TRUE : UIM_FALSE; |
154 |
} |
157 |
} |
155 |
} |
158 |
} |
156 |
|
159 |
|
|
|
160 |
/* FIXME: use appropriate name for this API */ |
161 |
uim_bool |
162 |
uim_check_dir(const char *dir) |
163 |
{ |
164 |
int need_prepare = UIM_TRUE; |
165 |
|
166 |
return uim_check_dir_internal(dir, need_prepare); |
167 |
} |
168 |
|
157 |
static uim_lisp |
169 |
static uim_lisp |
158 |
c_check_dir(uim_lisp dir_) |
170 |
c_prepare_dir(uim_lisp dir_) |
159 |
{ |
171 |
{ |
160 |
if (!uim_check_dir(REFER_C_STR(dir_))) { |
172 |
if (!uim_check_dir(REFER_C_STR(dir_))) { |
161 |
return uim_scm_f(); |
173 |
return uim_scm_f(); |
Lines 163-170
c_check_dir(uim_lisp dir_)
Link Here
|
163 |
return uim_scm_t(); |
175 |
return uim_scm_t(); |
164 |
} |
176 |
} |
165 |
|
177 |
|
166 |
uim_bool |
178 |
static uim_bool |
167 |
uim_get_config_path(char *path, int len, int is_getenv) |
179 |
uim_get_config_path_internal(char *path, int len, int is_getenv, int need_prepare) |
168 |
{ |
180 |
{ |
169 |
char home[MAXPATHLEN]; |
181 |
char home[MAXPATHLEN]; |
170 |
|
182 |
|
Lines 174-207
uim_get_config_path(char *path, int len, int is_getenv)
Link Here
|
174 |
if (!uim_get_home_directory(home, sizeof(home), getuid()) && is_getenv) { |
186 |
if (!uim_get_home_directory(home, sizeof(home), getuid()) && is_getenv) { |
175 |
char *home_env = getenv("HOME"); |
187 |
char *home_env = getenv("HOME"); |
176 |
|
188 |
|
177 |
if (!home_env) |
189 |
if (!home_env) { |
|
|
190 |
path[0] = '\0'; |
178 |
return UIM_FALSE; |
191 |
return UIM_FALSE; |
|
|
192 |
} |
179 |
|
193 |
|
180 |
if (strlcpy(home, home_env, sizeof(home)) >= sizeof(home)) |
194 |
if (strlcpy(home, home_env, sizeof(home)) >= sizeof(home)) { |
|
|
195 |
path[0] = '\0'; |
181 |
return UIM_FALSE; |
196 |
return UIM_FALSE; |
|
|
197 |
} |
182 |
} |
198 |
} |
183 |
|
199 |
|
184 |
if (snprintf(path, len, "%s/.uim.d", home) == -1) |
200 |
if (snprintf(path, len, "%s/.uim.d", home) < 0) { |
|
|
201 |
path[0] = '\0'; |
185 |
return UIM_FALSE; |
202 |
return UIM_FALSE; |
|
|
203 |
} |
186 |
|
204 |
|
187 |
if (!uim_check_dir(path)) { |
205 |
if (!uim_check_dir_internal(path, need_prepare)) { |
188 |
return UIM_FALSE; |
206 |
return UIM_FALSE; |
189 |
} |
207 |
} |
190 |
|
208 |
|
191 |
return UIM_TRUE; |
209 |
return UIM_TRUE; |
192 |
} |
210 |
} |
193 |
|
211 |
|
|
|
212 |
/* FIXME: use appropriate name for this API */ |
213 |
uim_bool |
214 |
uim_get_config_path(char *path, int len, int is_getenv) |
215 |
{ |
216 |
int need_prepare = UIM_TRUE; |
217 |
|
218 |
return uim_get_config_path_internal(path, len, is_getenv, need_prepare); |
219 |
} |
220 |
|
194 |
static uim_lisp |
221 |
static uim_lisp |
195 |
c_get_config_path(uim_lisp is_getenv_) |
222 |
c_prepare_config_path(uim_lisp is_getenv_) |
196 |
{ |
223 |
{ |
197 |
char path[MAXPATHLEN]; |
224 |
char path[MAXPATHLEN]; |
|
|
225 |
int need_prepare = UIM_TRUE; |
198 |
|
226 |
|
199 |
if (!uim_get_config_path(path, sizeof(path), C_BOOL(is_getenv_))) |
227 |
if (!uim_get_config_path_internal(path, sizeof(path), C_BOOL(is_getenv_), need_prepare)) |
200 |
return uim_scm_f(); |
228 |
return uim_scm_f(); |
201 |
return MAKE_STR(path); |
229 |
return MAKE_STR(path); |
202 |
} |
230 |
} |
203 |
|
231 |
|
204 |
static uim_lisp |
232 |
static uim_lisp |
|
|
233 |
c_get_config_path(uim_lisp is_getenv_) |
234 |
{ |
235 |
char path[MAXPATHLEN]; |
236 |
int need_prepare = UIM_FALSE; |
237 |
int exist; |
238 |
|
239 |
/* No need to check the existence of path in this function */ |
240 |
exist = uim_get_config_path_internal(path, sizeof(path), C_BOOL(is_getenv_), need_prepare); |
241 |
|
242 |
return MAKE_STR(path); |
243 |
} |
244 |
|
245 |
static uim_lisp |
205 |
file_stat_mode(uim_lisp filename, mode_t mode) |
246 |
file_stat_mode(uim_lisp filename, mode_t mode) |
206 |
{ |
247 |
{ |
207 |
struct stat st; |
248 |
struct stat st; |
Lines 391-398
uim_init_posix_subrs(void)
Link Here
|
391 |
uim_scm_init_proc0("user-name", user_name); |
432 |
uim_scm_init_proc0("user-name", user_name); |
392 |
uim_scm_init_proc1("home-directory", home_directory); |
433 |
uim_scm_init_proc1("home-directory", home_directory); |
393 |
|
434 |
|
394 |
uim_scm_init_proc1("create/check-directory!", c_check_dir); |
435 |
uim_scm_init_proc1("create/check-directory!", c_prepare_dir); |
395 |
uim_scm_init_proc1("get-config-path!", c_get_config_path); |
436 |
uim_scm_init_proc1("get-config-path!", c_prepare_config_path); |
|
|
437 |
uim_scm_init_proc1("get-config-path", c_get_config_path); |
396 |
|
438 |
|
397 |
uim_scm_init_proc1("file-readable?", file_readablep); |
439 |
uim_scm_init_proc1("file-readable?", file_readablep); |
398 |
uim_scm_init_proc1("file-writable?", file_writablep); |
440 |
uim_scm_init_proc1("file-writable?", file_writablep); |