From: Michael Tremer Date: Tue, 12 Dec 2017 13:29:10 +0000 (+0000) Subject: database: Save time when the database was created X-Git-Tag: 0.9.0~171 X-Git-Url: http://git.ipfire.org/?p=people%2Fms%2Flibloc.git;a=commitdiff_plain;h=96ea74a5181ddef4b3509fedb143f9be945296ef database: Save time when the database was created Signed-off-by: Michael Tremer --- diff --git a/src/database.c b/src/database.c index a263d02..f51931a 100644 --- a/src/database.c +++ b/src/database.c @@ -22,6 +22,7 @@ #include #include #include +#include #include #include @@ -38,6 +39,7 @@ struct loc_database { FILE* file; unsigned int version; + time_t created_at; off_t vendor; off_t description; @@ -57,6 +59,9 @@ LOC_EXPORT int loc_database_new(struct loc_ctx* ctx, struct loc_database** datab db->ctx = loc_ref(ctx); db->refcount = 1; + // Save creation time + db->created_at = time(NULL); + DEBUG(db->ctx, "Database allocated at %p\n", db); // Create string pool @@ -114,6 +119,10 @@ LOC_EXPORT struct loc_database* loc_database_unref(struct loc_database* db) { return NULL; } +LOC_EXPORT time_t loc_database_created_at(struct loc_database* db) { + return db->created_at; +} + LOC_EXPORT const char* loc_database_get_vendor(struct loc_database* db) { return loc_stringpool_get(db->pool, db->vendor); } @@ -274,6 +283,7 @@ static int loc_database_read_header_v0(struct loc_database* db) { } // Copy over data + db->created_at = be64toh(header.created_at); db->vendor = ntohl(header.vendor); db->description = ntohl(header.description); @@ -396,6 +406,7 @@ LOC_EXPORT int loc_database_write(struct loc_database* db, FILE* f) { // Make the header struct loc_database_header_v0 header; + header.created_at = htobe64(db->created_at); header.vendor = htonl(db->vendor); header.description = htonl(db->description); diff --git a/src/database.h b/src/database.h index 41142ab..407abcb 100644 --- a/src/database.h +++ b/src/database.h @@ -30,6 +30,7 @@ int loc_database_open(struct loc_ctx* ctx, struct loc_database** database, FILE* struct loc_database* loc_database_ref(struct loc_database* db); struct loc_database* loc_database_unref(struct loc_database* db); +time_t loc_database_created_at(struct loc_database* db); const char* loc_database_get_vendor(struct loc_database* db); int loc_database_set_vendor(struct loc_database* db, const char* vendor); const char* loc_database_get_description(struct loc_database* db); diff --git a/src/libloc.sym b/src/libloc.sym index 175c3fa..3469290 100644 --- a/src/libloc.sym +++ b/src/libloc.sym @@ -11,6 +11,7 @@ global: # Database loc_database_add_as; loc_database_count_as; + loc_database_created_at; loc_database_get_description; loc_database_get_vendor; loc_database_new; diff --git a/src/loc/format.h b/src/loc/format.h index e6f6dba..4a49628 100644 --- a/src/loc/format.h +++ b/src/loc/format.h @@ -32,6 +32,9 @@ struct loc_database_magic { }; struct loc_database_header_v0 { + // UNIX timestamp when the database was created + uint64_t created_at; + // Vendor who created the database uint32_t vendor;