Implement _dbm_get_fd in Kyoto cabinet.
* libmu_dbm/kyoto.c: Implement _dbm_get_fd.
Showing
1 changed file
with
16 additions
and
1 deletions
... | @@ -19,6 +19,7 @@ | ... | @@ -19,6 +19,7 @@ |
19 | # include <config.h> | 19 | # include <config.h> |
20 | #endif | 20 | #endif |
21 | #include <fcntl.h> | 21 | #include <fcntl.h> |
22 | #include <unistd.h> | ||
22 | #include <stdlib.h> | 23 | #include <stdlib.h> |
23 | #include <string.h> | 24 | #include <string.h> |
24 | #include <sys/stat.h> | 25 | #include <sys/stat.h> |
... | @@ -38,6 +39,7 @@ struct kc_descr | ... | @@ -38,6 +39,7 @@ struct kc_descr |
38 | { | 39 | { |
39 | KCDB *db; /* db */ | 40 | KCDB *db; /* db */ |
40 | KCCUR *cur; /* cursor */ | 41 | KCCUR *cur; /* cursor */ |
42 | int fd; | ||
41 | }; | 43 | }; |
42 | 44 | ||
43 | static int | 45 | static int |
... | @@ -49,7 +51,17 @@ _kc_file_safety (mu_dbm_file_t db, int mode, uid_t owner) | ... | @@ -49,7 +51,17 @@ _kc_file_safety (mu_dbm_file_t db, int mode, uid_t owner) |
49 | int | 51 | int |
50 | _kc_get_fd (mu_dbm_file_t db, int *pag, int *dir) | 52 | _kc_get_fd (mu_dbm_file_t db, int *pag, int *dir) |
51 | { | 53 | { |
52 | return ENOSYS; | 54 | struct kc_descr *kcd = db->db_descr; |
55 | if (kcd->fd == -1) | ||
56 | { | ||
57 | kcd->fd = open (db->db_name, O_RDONLY); | ||
58 | if (kcd->fd == -1) | ||
59 | return errno; | ||
60 | } | ||
61 | *pag = kcd->fd; | ||
62 | if (dir) | ||
63 | *dir = kcd->fd; | ||
64 | return 0; | ||
53 | } | 65 | } |
54 | 66 | ||
55 | static int | 67 | static int |
... | @@ -93,6 +105,7 @@ _kc_open (mu_dbm_file_t db, int flags, int mode) | ... | @@ -93,6 +105,7 @@ _kc_open (mu_dbm_file_t db, int flags, int mode) |
93 | kcd->db = kdb; | 105 | kcd->db = kdb; |
94 | kcd->cur = NULL; | 106 | kcd->cur = NULL; |
95 | db->db_descr = kcd; | 107 | db->db_descr = kcd; |
108 | kcd->fd = -1; | ||
96 | return 0; | 109 | return 0; |
97 | } | 110 | } |
98 | 111 | ||
... | @@ -102,6 +115,8 @@ _kc_close (mu_dbm_file_t db) | ... | @@ -102,6 +115,8 @@ _kc_close (mu_dbm_file_t db) |
102 | if (db->db_descr) | 115 | if (db->db_descr) |
103 | { | 116 | { |
104 | struct kc_descr *kcd = db->db_descr; | 117 | struct kc_descr *kcd = db->db_descr; |
118 | if (kcd->fd != -1) | ||
119 | close (kcd->fd); | ||
105 | kcdbclose (kcd->db); | 120 | kcdbclose (kcd->db); |
106 | kcdbdel (kcd->db); | 121 | kcdbdel (kcd->db); |
107 | free (kcd); | 122 | free (kcd); | ... | ... |
-
Please register or sign in to post a comment