]> git.ipfire.org Git - people/ms/libloc.git/commitdiff
Replace strerror(errno) with %m in format string throughout
authorMichael Tremer <michael.tremer@ipfire.org>
Mon, 15 Aug 2022 17:45:12 +0000 (17:45 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Mon, 15 Aug 2022 17:45:12 +0000 (17:45 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/database.c
src/python/writer.c
src/stringpool.c
src/test-as.c
src/test-country.c
src/test-database.c
src/test-network.c
src/test-signature.c
src/writer.c

index b57407eb860250ad634a9a5922e94d9c18c4f255..9ac80bc4f2d867c655830f0e1ea5f0a1f88e7f9a 100644 (file)
@@ -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;
        }
index c54596a1aba6af6a83e84a322d6c088705baae54..5d8027c88c57fde19e7af9610df7a5b83dfb1c60 100644 (file)
@@ -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;
        }
 
index 187c9d31d696dc3e3dabde0b7c4b6b800a7290cb..8911fb606996387c14ffd90924e7ff7cc5c3fae3 100644 (file)
@@ -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;
        }
index 91b62fd7651e4ef9406d6f0e98c87b3f4f8f8039..43052b4d88df0d881471019519c0721e64dd9417 100644 (file)
@@ -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);
        }
 
index c6aff49eb14f1c514adfa4091e85607352ed373a..e4edea0dabde149dac674dc559d5b9e041721dc0 100644 (file)
@@ -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);
        }
 
index 7037f6abe49a53fef607672119825332dafaf500..1d48661be45bb885f970637367320d38539acf02 100644 (file)
@@ -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);
        }
 
index 1c49d60658395e5fd10a882f8a41bb9ef4b725f1..dcb389a6ff3eeb265527221d0b998eadfa7e37e9 100644 (file)
@@ -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);
        }
 
index bc66c962631acc26b260ed737228650d87e093a7..6c4d398c97111cd87e9ff5994a70b623164b1e9f 100644 (file)
@@ -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);
        }
 
index 4420972975b7df36e79244bf464db3c9f07e80b4..af9a36d7f2fcab04c34df59673b801ac398aecc4 100644 (file)
@@ -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;
                }