diff --git a/core/sappyou.c b/core/sappyou.c index 4c60896..4048a81 100644 --- a/core/sappyou.c +++ b/core/sappyou.c @@ -168,3 +168,22 @@ int tanzaku_rem(Sappyou *sappyou, uint64_t tanzaku_id) { sappyou->modified_ts = time(NULL); return 0; } + +int tanzaku_upd(Sappyou *sappyou, uint64_t tanzaku_id, const char *name, const char *description) { + if (tanzaku_id == HOLE_ID || tanzaku_id >= sappyou->size) { + return 1; + } + _Bool changed = 0; + if (name != NULL) { + strcpy(sappyou->database[tanzaku_id].name, name); + changed = 1; + } + if (description != NULL) { + strcpy(sappyou->database[tanzaku_id].description, description); + changed = 1; + } + if (changed) { + sappyou->modified_ts = time(NULL); + } + return 0; +} diff --git a/core/sasahyou.c b/core/sasahyou.c index 13f956f..4f1fb8b 100644 --- a/core/sasahyou.c +++ b/core/sasahyou.c @@ -163,3 +163,14 @@ int sasa_rem(Sasahyou *sasahyou, uint64_t sasa_id) { sasahyou->modified_ts = time(NULL); return 0; } + +int sasa_upd(Sasahyou *sasahyou, uint64_t sasa_id, const char *path) { + if (sasa_id == HOLE_ID || sasa_id >= sasahyou->size) { + return 1; + } + if (path != NULL) { + strcpy(sasahyou->database[sasa_id].path, path); + sasahyou->modified_ts = time(NULL); + } + return 0; +} diff --git a/include/core.h b/include/core.h index f3e833b..4006d26 100644 --- a/include/core.h +++ b/include/core.h @@ -111,6 +111,9 @@ int sasa_add(Sasahyou *sasahyou, const char *path); // Remove sasa from sasahyou int sasa_rem(Sasahyou *sasahyou, uint64_t sasa_id); +// Update sasa file path +int sasa_upd(Sasahyou *sasahyou, uint64_t sasa_id, const char *path); + // ==================== SAPPYOU SECTION ==================== // // Initialize empty sappyou @@ -137,6 +140,9 @@ int tanzaku_add(Sappyou *sappyou, const char *name, const char *description); // Remove tanzaku from sappyou int tanzaku_rem(Sappyou *sappyou, uint64_t tanzaku_id); +// Update tanzaku name and description +int tanzaku_upd(Sappyou *sappyou, uint64_t tanzaku_id, const char *name, const char *description); + // ==================== SHOPPYOU SECTION ==================== // // Initialize empty shoppyou