]> git.ipfire.org Git - people/ms/libloc.git/blobdiff - src/writer.c
python: Use closest match for countries
[people/ms/libloc.git] / src / writer.c
index 26d5c32f3eb96c2266b700d88e8bc2757d4b6e89..6cd0027d2403bef8655616f440ae86613c770303 100644 (file)
@@ -530,6 +530,8 @@ static int loc_writer_create_signature(struct loc_writer* writer,
        struct loc_database_magic magic;
        fread(&magic, 1, sizeof(magic), f);
 
+       hexdump(writer->ctx, &magic, sizeof(magic));
+
        // Feed magic into the signature
        r = EVP_DigestSignUpdate(mdctx, &magic, sizeof(magic));
        if (r != 1) {
@@ -537,15 +539,17 @@ static int loc_writer_create_signature(struct loc_writer* writer,
                goto END;
        }
 
+       hexdump(writer->ctx, header, sizeof(*header));
+
        // Feed the header into the signature
-       r = EVP_DigestSignUpdate(mdctx, header, sizeof(header));
+       r = EVP_DigestSignUpdate(mdctx, header, sizeof(*header));
        if (r != 1) {
                ERROR(writer->ctx, "%s\n", ERR_error_string(ERR_get_error(), NULL));
                goto END;
        }
 
        // Skip header
-       fseek(f, sizeof(header), SEEK_CUR);
+       fseek(f, sizeof(*header), SEEK_CUR);
 
        // Walk through the file in chunks of 64kB
        char buffer[64 * 1024];
@@ -558,6 +562,8 @@ static int loc_writer_create_signature(struct loc_writer* writer,
                        goto END;
                }
 
+               hexdump(writer->ctx, buffer, bytes_read);
+
                r = EVP_DigestSignUpdate(mdctx, buffer, bytes_read);
                if (r != 1) {
                        ERROR(writer->ctx, "%s\n", ERR_error_string(ERR_get_error(), NULL));
@@ -609,6 +615,10 @@ LOC_EXPORT int loc_writer_write(struct loc_writer* writer, FILE* f) {
        for (unsigned int i = 0; i < sizeof(header.signature); i++)
                header.signature[i] = '\0';
 
+       // Clear the padding
+       for (unsigned int i = 0; i < sizeof(header.padding); i++)
+               header.padding[i] = '\0';
+
        int r;
        off_t offset = 0;