]> git.ipfire.org Git - people/ms/libloc.git/blobdiff - src/writer.c
Add license attribute to the database
[people/ms/libloc.git] / src / writer.c
index 1867e90ee0ebef6fb80cfb4a628a6bfd4d62efed..12a2c52ea5636f084483e0bb4fe33bdf8ed8e14f 100644 (file)
@@ -36,6 +36,7 @@ struct loc_writer {
        struct loc_stringpool* pool;
        off_t vendor;
        off_t description;
+       off_t license;
 
        struct loc_as** as;
        size_t as_count;
@@ -130,6 +131,20 @@ LOC_EXPORT int loc_writer_set_description(struct loc_writer* writer, const char*
        return 0;
 }
 
+LOC_EXPORT const char* loc_writer_get_license(struct loc_writer* writer) {
+       return loc_stringpool_get(writer->pool, writer->license);
+}
+
+LOC_EXPORT int loc_writer_set_license(struct loc_writer* writer, const char* license) {
+       // Add the string to the string pool
+       off_t offset = loc_stringpool_add(writer->pool, license);
+       if (offset < 0)
+               return offset;
+
+       writer->license = offset;
+       return 0;
+}
+
 static int __loc_as_cmp(const void* as1, const void* as2) {
        return loc_as_cmp(*(struct loc_as**)as1, *(struct loc_as**)as2);
 }
@@ -401,6 +416,7 @@ LOC_EXPORT int loc_writer_write(struct loc_writer* writer, FILE* f) {
        struct loc_database_header_v0 header;
        header.vendor      = htobe32(writer->vendor);
        header.description = htobe32(writer->description);
+       header.license     = htobe32(writer->license);
 
        time_t now = time(NULL);
        header.created_at = htobe64(now);