From: nishi Date: Sat, 20 Apr 2024 12:59:17 +0000 (+0000) Subject: db write X-Git-Url: http://10.10.0.4:5575/?a=commitdiff_plain;h=084e0fb52485b2eb75a2a92138edb4bb598848f6;p=mandshurica.git db write git-svn-id: file:///raid/svn-main/nishi-mandshurica/trunk@57 f982e544-4a7d-3444-ad1a-fde59a2a69f1 --- diff --git a/Mandshurica/db.c b/Mandshurica/db.c index cd0dba6..f47c23e 100644 --- a/Mandshurica/db.c +++ b/Mandshurica/db.c @@ -37,7 +37,7 @@ #include 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; @@ -51,6 +51,16 @@ void mandshurica_db_close(struct ms_db* db) { 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); diff --git a/Mandshurica/file.c b/Mandshurica/file.c index 74eeffc..e259379 100644 --- a/Mandshurica/file.c +++ b/Mandshurica/file.c @@ -57,6 +57,9 @@ char* get_mime(const char* _path) { } 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; diff --git a/Mandshurica/ms_db.h b/Mandshurica/ms_db.h index 1327d1f..3722cfc 100644 --- a/Mandshurica/ms_db.h +++ b/Mandshurica/ms_db.h @@ -40,5 +40,6 @@ struct ms_db { 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