db_file = char_attribute_system_db_file (CHARSET_NAME (cs),
                                           Qsystem_char_id, 1);
-  db = Fopen_database (db_file, Qnil, Qnil, Qnil, Qnil);
-      
+  db = Fopen_database (db_file, Qnil, Qnil, build_string ("w+"), Qnil);
+
   byte_min = CHARSET_BYTE_OFFSET (cs);
   byte_max = byte_min + CHARSET_BYTE_SIZE (cs);
   switch (CHARSET_DIMENSION (cs))
     = char_attribute_system_db_file (XCHARSET_NAME(ccs), Qsystem_char_id,
                                     0);
 
-  db = Fopen_database (db_file, Qnil, Qnil, Qnil, Qnil);
+  db = Fopen_database (db_file, Qnil, Qnil, build_string ("r"), Qnil);
   if (!NILP (db))
     {
       Lisp_Object ret