update.
[chise/libchise.git] / chise.c
diff --git a/chise.c b/chise.c
index b5ede8a..da12d1b 100644 (file)
--- a/chise.c
+++ b/chise.c
@@ -1,4 +1,7 @@
 #include <stdlib.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <unistd.h>
 #ifdef HAVE_CONFIG_H
 #  include "config.h"
 #endif
@@ -244,6 +247,35 @@ chise_feature_setup_db (CHISE_Feature feature, int writable)
 }
 
 int
+chise_feature_sync (CHISE_Feature feature)
+{
+  int status;
+
+  if (feature->db == NULL)
+    status = 0;
+  else
+    status = CHISE_Attribute_Table_close (feature->db);
+  feature->db = NULL;
+  feature->access = 0;
+  return status;
+}
+
+int
+chise_char_set_feature_value (CHISE_Char_ID cid,
+                             CHISE_Feature feature,
+                             unsigned char *value)
+{
+  unsigned char key_buf[8];
+
+  if (feature == NULL)
+    return -1;
+  if (chise_feature_setup_db (feature, 1))
+    return -1;
+  chise_format_char_id (cid, key_buf, 8);
+  return chise_attribute_table_put (feature->db, key_buf, value);
+}
+
+int
 chise_char_load_feature_value (CHISE_Char_ID cid,
                               CHISE_Feature_Table *table,
                               CHISE_Value *valdatum)
@@ -468,11 +500,15 @@ CHISE_Attribute_Table_open (const unsigned char *db_dir,
   int len, flen, i;
   int size;
   char *db_file_name, *sp;
+  struct stat statbuf;
 
   status = db_create (&dbase, NULL, 0);
   if (status)
     return NULL;
 
+  if ( (accessmask & DB_CREATE) && stat (db_dir, &statbuf) )
+    mkdir (db_dir, modemask);
+
   len = strlen (db_dir);
   flen = strlen (feature);
   size = len + strlen (encoding) + flen * 3 + 4;
@@ -484,6 +520,10 @@ CHISE_Attribute_Table_open (const unsigned char *db_dir,
       db_file_name[len] = '\0';
     }
   strcat (db_file_name, encoding);
+
+  if ( (accessmask & DB_CREATE) && stat (db_file_name, &statbuf) )
+    mkdir (db_file_name, modemask);
+
   strcat (db_file_name, "/");
   /* strcat (db_file_name, feature); */
   sp = &db_file_name[strlen (db_file_name)];