gdbm.vapi 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248
  1. /**
  2. * GDBM - GNU dbm bindings for Vala
  3. *
  4. * This VAPI provides bindings for the GDBM (GNU dbm) library,
  5. * a simple key-value database with persistent storage.
  6. */
  7. [CCode (cprefix = "", lower_case_cprefix = "", cheader_filename = "gdbm.h,Storage/Gdbm/gdbm_wrapper.h")]
  8. namespace Gdbm {
  9. /**
  10. * Flags for gdbm_open() - read/write mode
  11. */
  12. [CCode (cname = "int", has_type_id = false)]
  13. public enum OpenFlag {
  14. [CCode (cname = "GDBM_READER")]
  15. READER,
  16. [CCode (cname = "GDBM_WRITER")]
  17. WRITER,
  18. [CCode (cname = "GDBM_WRCREAT")]
  19. WRCREAT,
  20. [CCode (cname = "GDBM_NEWDB")]
  21. NEWDB
  22. }
  23. /**
  24. * Additional flags for gdbm_open() - bitwise modifiers
  25. */
  26. [CCode (cname = "int", has_type_id = false)]
  27. [Flags]
  28. public enum OpenModifier {
  29. [CCode (cname = "GDBM_SYNC")]
  30. SYNC,
  31. [CCode (cname = "GDBM_NOLOCK")]
  32. NOLOCK,
  33. [CCode (cname = "GDBM_BSEXACT")]
  34. BSEXACT,
  35. [CCode (cname = "GDBM_CLOEXEC")]
  36. CLOEXEC
  37. }
  38. /**
  39. * Flags for gdbm_store()
  40. */
  41. [CCode (cname = "int", has_type_id = false)]
  42. public enum StoreFlag {
  43. [CCode (cname = "GDBM_INSERT")]
  44. INSERT,
  45. [CCode (cname = "GDBM_REPLACE")]
  46. REPLACE
  47. }
  48. /**
  49. * Error codes from gdbm_last_error()
  50. */
  51. [CCode (cname = "gdbm_error", has_type_id = false)]
  52. public enum ErrorCode {
  53. [CCode (cname = "GDBM_NO_ERROR")]
  54. NO_ERROR,
  55. [CCode (cname = "GDBM_MALLOC_ERROR")]
  56. MALLOC_ERROR,
  57. [CCode (cname = "GDBM_BLOCK_SIZE_ERROR")]
  58. BLOCK_SIZE_ERROR,
  59. [CCode (cname = "GDBM_OPEN_ERROR")]
  60. OPEN_ERROR,
  61. [CCode (cname = "GDBM_READ_ERROR")]
  62. READ_ERROR,
  63. [CCode (cname = "GDBM_WRITE_ERROR")]
  64. WRITE_ERROR,
  65. [CCode (cname = "GDBM_SEEK_ERROR")]
  66. SEEK_ERROR,
  67. [CCode (cname = "GDBM_REORGANIZE_FAILED")]
  68. REORGANIZE_FAILED,
  69. [CCode (cname = "GDBM_ILLEGAL_DATA")]
  70. ILLEGAL_DATA,
  71. [CCode (cname = "GDBM_OPT_ALREADY_SET")]
  72. OPT_ALREADY_SET,
  73. [CCode (cname = "GDBM_OPT_ILLEGAL")]
  74. OPT_ILLEGAL,
  75. [CCode (cname = "GDBM_BYTE_SWAPPED")]
  76. BYTE_SWAPPED,
  77. [CCode (cname = "GDBM_BAD_FILE_OFFSET")]
  78. BAD_FILE_OFFSET,
  79. [CCode (cname = "GDBM_BAD_OPEN_FLAGS")]
  80. BAD_OPEN_FLAGS,
  81. [CCode (cname = "GDBM_FILE_STAT_ERROR")]
  82. FILE_STAT_ERROR,
  83. [CCode (cname = "GDBM_FILE_EOF")]
  84. FILE_EOF,
  85. [CCode (cname = "GDBM_NO_DBNAME")]
  86. NO_DBNAME,
  87. [CCode (cname = "GDBM_ERR_FILE_OWNER")]
  88. ERR_FILE_OWNER,
  89. [CCode (cname = "GDBM_ERR_FILE_MODE")]
  90. ERR_FILE_MODE,
  91. [CCode (cname = "GDBM_UNKNOWN_ERROR")]
  92. UNKNOWN_ERROR,
  93. [CCode (cname = "GDBM_ITEM_NOT_FOUND")]
  94. ITEM_NOT_FOUND,
  95. [CCode (cname = "GDBM_MALFORMED_DATA")]
  96. MALFORMED_DATA,
  97. [CCode (cname = "GDBM_OPT_BADVAL")]
  98. OPT_BADVAL,
  99. [CCode (cname = "GDBM_ERR_SNAPSHOT_CLONE")]
  100. ERR_SNAPSHOT_CLONE,
  101. [CCode (cname = "GDBM_ERR_REALPATH")]
  102. ERR_REALPATH,
  103. [CCode (cname = "GDBM_ERR_DIR")]
  104. ERR_DIR,
  105. [CCode (cname = "GDBM_ERR_DB_FILENAME")]
  106. ERR_DB_FILENAME,
  107. [CCode (cname = "GDBM_ERR_OPEN")]
  108. ERR_OPEN,
  109. [CCode (cname = "GDBM_ERR_CLOSE")]
  110. ERR_CLOSE,
  111. [CCode (cname = "GDBM_ERR_FSTAT")]
  112. ERR_FSTAT,
  113. [CCode (cname = "GDBM_ERR_FILE_COUNT")]
  114. ERR_FILE_COUNT
  115. }
  116. /**
  117. * Database handle - wraps GDBM_FILE pointer.
  118. * GDBM_FILE is already a pointer type (typedef struct gdbm_file_info *GDBM_FILE).
  119. */
  120. [Compact]
  121. [CCode (cname = "struct gdbm_file_info", free_function = "gdbm_close")]
  122. public class Database {
  123. /**
  124. * Opens a GDBM database file.
  125. *
  126. * @param name Path to the database file
  127. * @param block_size Size of a block in the database (0 for default)
  128. * @param flags Open flags (READER, WRITER, WRCREAT, NEWDB) plus optional modifiers
  129. * @param mode File creation mode (e.g., 0644)
  130. * @return Database handle, or null on error
  131. */
  132. [CCode (cname = "gdbm_open")]
  133. public static Database? open(string name, int block_size, int flags, int mode, void* fatal_func = null);
  134. /**
  135. * Checks if a key exists in the database.
  136. *
  137. * @param key The key to check
  138. * @return True if the key exists
  139. */
  140. [CCode (cname = "gdbm_exists_wrapper")]
  141. public bool exists(string key);
  142. /**
  143. * Retrieves a value by key.
  144. *
  145. * @param key The key to look up
  146. * @return The value as GBytes, or null if not found
  147. */
  148. [CCode (cname = "gdbm_fetch_wrapper")]
  149. public GLib.Bytes? fetch(string key);
  150. /**
  151. * Stores a key-value pair.
  152. *
  153. * @param key The key
  154. * @param content The value
  155. * @param flag Store flag (INSERT or REPLACE)
  156. * @return 0 on success, non-zero on error
  157. */
  158. [CCode (cname = "gdbm_store_wrapper")]
  159. public int store(string key, GLib.Bytes content, StoreFlag flag = StoreFlag.REPLACE);
  160. /**
  161. * Deletes a key from the database.
  162. *
  163. * @param key The key to delete
  164. * @return 0 on success, -1 on error
  165. */
  166. [CCode (cname = "gdbm_delete_wrapper")]
  167. public int delete(string key);
  168. /**
  169. * Gets the first key for iteration.
  170. *
  171. * @return First key, or null if database is empty
  172. */
  173. [CCode (cname = "gdbm_firstkey_wrapper")]
  174. public string? first_key();
  175. /**
  176. * Gets the next key in iteration.
  177. *
  178. * @param prev_key Previous key
  179. * @return Next key, or null if no more keys
  180. */
  181. [CCode (cname = "gdbm_nextkey_wrapper")]
  182. public string? next_key(string prev_key);
  183. /**
  184. * Synchronizes the database to disk.
  185. */
  186. [CCode (cname = "gdbm_sync")]
  187. public void sync();
  188. /**
  189. * Reorganizes the database to reclaim space.
  190. *
  191. * @return 0 on success, -1 on error
  192. */
  193. [CCode (cname = "gdbm_reorganize")]
  194. public int reorganize();
  195. /**
  196. * Gets the error code for the last operation.
  197. *
  198. * @return Error code
  199. */
  200. [CCode (cname = "gdbm_last_errno")]
  201. public ErrorCode last_errno();
  202. /**
  203. * Gets the error message for the last operation.
  204. *
  205. * @return Error message string
  206. */
  207. [CCode (cname = "gdbm_db_strerror")]
  208. public unowned string db_strerror();
  209. /**
  210. * Clears the error status.
  211. */
  212. [CCode (cname = "gdbm_clear_error")]
  213. public void clear_error();
  214. /**
  215. * Gets the file name of the database.
  216. *
  217. * @return File name string
  218. */
  219. [CCode (cname = "gdbm_dbname")]
  220. public unowned string? dbname();
  221. }
  222. /**
  223. * Gets a string describing an error code.
  224. *
  225. * @param error Error code
  226. * @return Error description string
  227. */
  228. [CCode (cname = "gdbm_strerror")]
  229. public unowned string strerror(ErrorCode error);
  230. }