From 6cd02f1df63ed79c8d1ccfa6ab546c4b59cd24de Mon Sep 17 00:00:00 2001 From: Michael Tremer Date: Mon, 15 Aug 2022 17:45:12 +0000 Subject: [PATCH] Replace strerror(errno) with %m in format string throughout Signed-off-by: Michael Tremer --- src/database.c | 12 ++++++------ src/python/writer.c | 4 ++-- src/stringpool.c | 4 ++-- src/test-as.c | 2 +- src/test-country.c | 2 +- src/test-database.c | 2 +- src/test-network.c | 2 +- src/test-signature.c | 10 +++++----- src/writer.c | 2 +- 9 files changed, 20 insertions(+), 20 deletions(-) diff --git a/src/database.c b/src/database.c index b57407e..9ac80bc 100644 --- a/src/database.c +++ b/src/database.c @@ -436,28 +436,28 @@ static void loc_database_free(struct loc_database* db) { if (db->as_v1) { r = munmap(db->as_v1, db->as_count * sizeof(*db->as_v1)); if (r) - ERROR(db->ctx, "Could not unmap AS section: %s\n", strerror(errno)); + ERROR(db->ctx, "Could not unmap AS section: %m\n"); } // Remove mapped network sections if (db->networks_v1) { r = munmap(db->networks_v1, db->networks_count * sizeof(*db->networks_v1)); if (r) - ERROR(db->ctx, "Could not unmap networks section: %s\n", strerror(errno)); + ERROR(db->ctx, "Could not unmap networks section: %m\n"); } // Remove mapped network nodes section if (db->network_nodes_v1) { r = munmap(db->network_nodes_v1, db->network_nodes_count * sizeof(*db->network_nodes_v1)); if (r) - ERROR(db->ctx, "Could not unmap network nodes section: %s\n", strerror(errno)); + ERROR(db->ctx, "Could not unmap network nodes section: %m\n"); } // Remove mapped countries section if (db->countries_v1) { r = munmap(db->countries_v1, db->countries_count * sizeof(*db->countries_v1)); if (r) - ERROR(db->ctx, "Could not unmap countries section: %s\n", strerror(errno)); + ERROR(db->ctx, "Could not unmap countries section: %m\n"); } if (db->pool) @@ -498,8 +498,8 @@ LOC_EXPORT int loc_database_verify(struct loc_database* db, FILE* f) { // Load public key EVP_PKEY* pkey = PEM_read_PUBKEY(f, NULL, NULL, NULL); if (!pkey) { - char* error = ERR_error_string(ERR_get_error(), NULL); - ERROR(db->ctx, "Could not parse public key: %s\n", error); + ERROR(db->ctx, "Could not parse public key: %s\n", + ERR_error_string(ERR_get_error(), NULL)); return -1; } diff --git a/src/python/writer.c b/src/python/writer.c index c54596a..5d8027c 100644 --- a/src/python/writer.c +++ b/src/python/writer.c @@ -227,7 +227,7 @@ static PyObject* Writer_write(WriterObject* self, PyObject* args) { FILE* f = fopen(path, "w+"); if (!f) { - PyErr_Format(PyExc_IOError, strerror(errno)); + PyErr_SetFromErrno(PyExc_OSError); return NULL; } @@ -236,7 +236,7 @@ static PyObject* Writer_write(WriterObject* self, PyObject* args) { // Raise any errors if (r) { - PyErr_Format(PyExc_IOError, strerror(errno)); + PyErr_SetFromErrno(PyExc_OSError); return NULL; } diff --git a/src/stringpool.c b/src/stringpool.c index 187c9d3..8911fb6 100644 --- a/src/stringpool.c +++ b/src/stringpool.c @@ -119,8 +119,8 @@ static void loc_stringpool_free(struct loc_stringpool* pool) { if (pool->data) { r = munmap(pool->data, pool->length); if (r) - ERROR(pool->ctx, "Could not unmap data at %p: %s\n", - pool->data, strerror(errno)); + ERROR(pool->ctx, "Could not unmap data at %p: %m\n", + pool->data); } break; } diff --git a/src/test-as.c b/src/test-as.c index 91b62fd..43052b4 100644 --- a/src/test-as.c +++ b/src/test-as.c @@ -55,7 +55,7 @@ int main(int argc, char** argv) { FILE* f = tmpfile(); if (!f) { - fprintf(stderr, "Could not open file for writing: %s\n", strerror(errno)); + fprintf(stderr, "Could not open file for writing: %m\n"); exit(EXIT_FAILURE); } diff --git a/src/test-country.c b/src/test-country.c index c6aff49..e4edea0 100644 --- a/src/test-country.c +++ b/src/test-country.c @@ -124,7 +124,7 @@ int main(int argc, char** argv) { FILE* f = tmpfile(); if (!f) { - fprintf(stderr, "Could not open file for writing: %s\n", strerror(errno)); + fprintf(stderr, "Could not open file for writing: %m\n"); exit(EXIT_FAILURE); } diff --git a/src/test-database.c b/src/test-database.c index 7037f6a..1d48661 100644 --- a/src/test-database.c +++ b/src/test-database.c @@ -167,7 +167,7 @@ int main(int argc, char** argv) { FILE* f = tmpfile(); if (!f) { - fprintf(stderr, "Could not open file for writing: %s\n", strerror(errno)); + fprintf(stderr, "Could not open file for writing: %m\n"); exit(EXIT_FAILURE); } diff --git a/src/test-network.c b/src/test-network.c index 1c49d60..dcb389a 100644 --- a/src/test-network.c +++ b/src/test-network.c @@ -260,7 +260,7 @@ int main(int argc, char** argv) { FILE* f = tmpfile(); if (!f) { - fprintf(stderr, "Could not open file for writing: %s\n", strerror(errno)); + fprintf(stderr, "Could not open file for writing: %m\n"); exit(EXIT_FAILURE); } diff --git a/src/test-signature.c b/src/test-signature.c index bc66c96..6c4d398 100644 --- a/src/test-signature.c +++ b/src/test-signature.c @@ -34,20 +34,20 @@ int main(int argc, char** argv) { // Open public key FILE* public_key = fopen(ABS_SRCDIR "/examples/public-key.pem", "r"); if (!public_key) { - fprintf(stderr, "Could not open public key file: %s\n", strerror(errno)); + fprintf(stderr, "Could not open public key file: %m\n"); exit(EXIT_FAILURE); } // Open private key FILE* private_key1 = fopen(ABS_SRCDIR "/examples/private-key.pem", "r"); if (!private_key1) { - fprintf(stderr, "Could not open private key file: %s\n", strerror(errno)); + fprintf(stderr, "Could not open private key file: %m\n"); exit(EXIT_FAILURE); } FILE* private_key2 = fopen(ABS_SRCDIR "/examples/private-key.pem", "r"); if (!private_key2) { - fprintf(stderr, "Could not open private key file: %s\n", strerror(errno)); + fprintf(stderr, "Could not open private key file: %m\n"); exit(EXIT_FAILURE); } @@ -67,7 +67,7 @@ int main(int argc, char** argv) { FILE* f = tmpfile(); if (!f) { - fprintf(stderr, "Could not open file for writing: %s\n", strerror(errno)); + fprintf(stderr, "Could not open file for writing: %m\n"); exit(EXIT_FAILURE); } @@ -96,7 +96,7 @@ int main(int argc, char** argv) { // Open another public key public_key = freopen(ABS_SRCDIR "/src/signing-key.pem", "r", public_key); if (!public_key) { - fprintf(stderr, "Could not open public key file: %s\n", strerror(errno)); + fprintf(stderr, "Could not open public key file: %m\n"); exit(EXIT_FAILURE); } diff --git a/src/writer.c b/src/writer.c index 4420972..af9a36d 100644 --- a/src/writer.c +++ b/src/writer.c @@ -583,7 +583,7 @@ static int loc_writer_create_signature(struct loc_writer* writer, size_t bytes_read = fread(buffer, 1, sizeof(buffer), f); if (ferror(f)) { - ERROR(writer->ctx, "Error reading from file: %s\n", strerror(errno)); + ERROR(writer->ctx, "Error reading from file: %m\n"); r = errno; goto END; } -- 2.39.2