Changeset 36 for trunk/pymigemo/pymigemo.c
- Timestamp:
- 11/07/10 01:36:30 (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/pymigemo/pymigemo.c
r35 r36 11 11 #include <stdbool.h> 12 12 #include <string.h> 13 #include <errno.h> 14 #include <sys/types.h> 15 #include <sys/stat.h> 16 #include <fcntl.h> 17 #include <unistd.h> 13 18 14 19 #define PYMIGEMO_VERSION "0.3" … … 60 65 } 61 66 67 static int 68 isloadable(const char *path) 69 { 70 struct stat st; 71 int ret = 0; 72 int fd = open(path, O_RDONLY); 73 74 if (fd < 0) { 75 return errno; 76 } 77 78 if (fstat(fd, &st) < 0) { 79 ret = errno; 80 goto isloadable_end; 81 } 82 if (S_ISDIR(st.st_mode)) { 83 ret = EISDIR; 84 goto isloadable_end; 85 } 86 87 isloadable_end: 88 if (close(fd) < 0) { 89 ret = errno; 90 } 91 return ret; 92 } 93 62 94 static void 63 95 Migemo_dealloc(Migemo *self) … … 97 129 98 130 if (dictionary) { 131 int ret = isloadable(dictionary); 132 133 if (ret != 0) { 134 PyErr_SetString(PyExc_ValueError, strerror(ret)); 135 return -1; 136 } 137 99 138 if (self->migemo_obj) { 100 139 migemo_close(self->migemo_obj); … … 241 280 242 281 if (dict_file) { 282 int ret = isloadable(dict_file); 283 284 if (ret != 0) { 285 PyErr_SetString(PyExc_ValueError, strerror(ret)); 286 return NULL; 287 } 288 243 289 result = PyInt_FromLong((long)migemo_load(self->migemo_obj, dict_id, dict_file)); 244 290 }
Note: See TracChangeset
for help on using the changeset viewer.