#include <string.h>
struct ms_db* mandshurica_db_open(const char* path) {
- FILE* fp = fopen(path, "rb");
+ FILE* fp = fopen(path, "r+b");
if(fp != NULL) {
struct ms_db* db = malloc(sizeof(*db));
db->fp = fp;
free(db);
}
+void mandshurica_db_write(struct ms_db* db, const char* key, const char* value) {
+ flockfile(db->fp);
+ fseek(db->fp, 0, SEEK_END);
+ fwrite(key, 1, strlen(key), db->fp);
+ fwrite(":", 1, 1, db->fp);
+ fwrite(value, 1, strlen(value), db->fp);
+ fwrite("\n", 1, 1, db->fp);
+ funlockfile(db->fp);
+}
+
/* key:value */
char* mandshurica_db_get(struct ms_db* db, const char* key) {
fseek(db->fp, 0, SEEK_SET);
} else if(strcmp(ext, "html") == 0) {
free(typ);
typ = mandshurica_strdup("text/html");
+ } else if(strcmp(ext, "ico") == 0) {
+ free(typ);
+ typ = mandshurica_strdup("image/vnd.microsoft.icon");
}
free(path);
return typ;
struct ms_db* mandshurica_db_open(const char* path);
void mandshurica_db_close(struct ms_db* db);
char* mandshurica_db_get(struct ms_db* db, const char* key);
+void mandshurica_db_write(struct ms_db* db, const char* key, const char* value);
#endif