From 9c50c74888fbc81bd47081f50e844346c98347f8 Mon Sep 17 00:00:00 2001 From: Robert Pengelly Date: Fri, 21 Mar 2025 05:59:06 +0000 Subject: [PATCH] Don't hardcode values --- append.c | 12 ++++++------ conv.c | 11 +++++++++-- delete.c | 2 +- ranlib.c | 12 ++++++------ replace.c | 2 +- 5 files changed, 23 insertions(+), 16 deletions(-) diff --git a/append.c b/append.c index bab69e9..96c625b 100644 --- a/append.c +++ b/append.c @@ -50,7 +50,7 @@ void append (FILE *ofp, char *fname) { } - memset (temp, 0x20, 16); + memset (temp, ' ', 16); temp[0] = '0'; if ((p = strrchr (fname, '/'))) { @@ -66,7 +66,7 @@ void append (FILE *ofp, char *fname) { memcpy (header.name, name, len); while (len < 16) { - header.name[len++] = 0x20; + header.name[len++] = ' '; } memcpy (header.mtime, temp, 12); @@ -78,12 +78,12 @@ void append (FILE *ofp, char *fname) { bytes = ftell (tfp); len = sprintf (temp, "%ld", bytes); - temp[len] = 0x20; + temp[len] = ' '; memcpy (header.size, temp, 10); - header.endsig[0] = 0x60; - header.endsig[1] = 0x0A; + header.endsig[0] = '`'; + header.endsig[1] = '\n'; need_newline = (bytes % 2); @@ -137,7 +137,7 @@ void append (FILE *ofp, char *fname) { if (need_newline) { - temp[0] = 0x0A; + temp[0] = '\n'; if (fwrite (temp, 1, 1, ofp) != 1) { diff --git a/conv.c b/conv.c index f8267ab..991968a 100644 --- a/conv.c +++ b/conv.c @@ -5,12 +5,19 @@ uint32_t conv_dec (char *str, int32_t max) { + char ch; uint32_t value = 0; - while (*str != ' ' && max-- > 0) { + while ((ch = *str)) { + if (ch == ' ' || max == 0) { + break; + } + value *= 10; - value += *str++ - '0'; + + value += (ch - '0'); + str++; } diff --git a/delete.c b/delete.c index e190ce0..40038c5 100644 --- a/delete.c +++ b/delete.c @@ -16,7 +16,7 @@ void delete (char *fname) { char temp[17], *name, *p, *contents; long bytes, len, read; - if (fwrite ("!\x0A", 8, 1, tfp) != 1) { + if (fwrite ("!\n", 8, 1, tfp) != 1) { fclose (tfp); diff --git a/ranlib.c b/ranlib.c index 3a88817..76370ec 100644 --- a/ranlib.c +++ b/ranlib.c @@ -314,7 +314,7 @@ void ranlib (void) { } - if (fwrite ("!\x0A", 8, 1, tfp) != 1) { + if (fwrite ("!\n", 8, 1, tfp) != 1) { fclose (tfp); @@ -323,14 +323,14 @@ void ranlib (void) { } - memset (temp, 0x20, 16); + memset (temp, ' ', 16); temp[0] = '0'; len = 1; memcpy (header.name, "/", len); while (len < 16) { - header.name[len++] = 0x20; + header.name[len++] = ' '; } memcpy (header.mtime, temp, 12); @@ -339,12 +339,12 @@ void ranlib (void) { memcpy (header.mode, temp, 8); len = sprintf (temp, "%ld", bytes + 4); - temp[len] = 0x20; + temp[len] = ' '; memcpy (header.size, temp, 10); - header.endsig[0] = 0x60; - header.endsig[1] = 0x0A; + header.endsig[0] = '`'; + header.endsig[1] = '\n'; if (fwrite (&header, sizeof (header), 1, tfp) != 1) { diff --git a/replace.c b/replace.c index 3df068c..fba834d 100644 --- a/replace.c +++ b/replace.c @@ -16,7 +16,7 @@ void replace (char *fname) { char temp[17], *name, *p, *contents; long bytes, len, read; - if (fwrite ("!\x0A", 8, 1, tfp) != 1) { + if (fwrite ("!\n", 8, 1, tfp) != 1) { fclose (tfp); -- 2.34.1