commit: 0b85e0da3d7de10bddb31bacb313ccb18f321dd6
parent ff4e1030142efdd9ae2bb853f456ca669f3e84a9
Author: Haelwenn (lanodan) Monnier <contact@hacktivis.me>
Date: Sat, 24 Aug 2024 04:12:54 +0200
Respect `const char *` from string literals
Diffstat:
46 files changed, 130 insertions(+), 114 deletions(-)
diff --git a/cmd/base64.c b/cmd/base64.c
@@ -15,7 +15,8 @@
#include <unistd.h> /* read(), write(), close(), getopt(), opt* */
// 64(26+26+10+2)
-static char b64_encmap[64] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
+static const char b64_encmap[64] =
+ "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
static size_t c_out = 0;
// 76 is lowest of all base64 related RFCs
static long wrap_nl = 76;
@@ -270,11 +271,11 @@ main(int argc, char *argv[])
break;
case 'w':
errno = 0;
- char *e = "";
+ char *e = NULL;
wrap_nl = strtol(optarg, &e, 10);
// extraneous characters is invalid
- if(*e != 0) errno = EINVAL;
+ if(e && *e != 0) errno = EINVAL;
if(errno != 0)
{
diff --git a/cmd/chown.c b/cmd/chown.c
@@ -27,7 +27,7 @@
#include <getopt.h>
#endif
-char *argv0 = NULL;
+const char *argv0 = NULL;
static uid_t user = (uid_t)-1;
static uid_t group = (uid_t)-1;
diff --git a/cmd/chroot.c b/cmd/chroot.c
@@ -39,7 +39,7 @@ main(int argc, char *argv[])
errno = 0;
if(argc == 2)
{
- char *shell = getenv("SHELL");
+ const char *shell = getenv("SHELL");
if(shell == NULL) shell = "/bin/sh";
if(strnlen(shell, PATH_MAX) >= PATH_MAX)
{
diff --git a/cmd/cksum.c b/cmd/cksum.c
@@ -69,7 +69,7 @@ static const uint32_t crctab[256] = { 0x00000000,
// clang-format on
static int
-cksum(int fd, char *fdname)
+cksum(int fd, const char *fdname)
{
uint32_t crc = 0;
ssize_t total = 0;
@@ -127,17 +127,18 @@ main(int argc, char *argv[])
for(int i = 0; i < argc; i++)
{
int fd = -1;
- if(argv[i][0] == '-' && argv[i][1] == '\0')
+ const char *filename = argv[i];
+ if(filename[0] == '-' && filename[1] == '\0')
{
- argv[i] = "<stdin>";
+ filename = "<stdin>";
fd = STDIN_FILENO;
}
else
{
- fd = open(argv[i], O_RDONLY | O_NOCTTY);
+ fd = open(filename, O_RDONLY | O_NOCTTY);
if(fd < 0)
{
- fprintf(stderr, "cksum: Error: Failed opening file '%s': %s\n", argv[i], strerror(errno));
+ fprintf(stderr, "cksum: Error: Failed opening file '%s': %s\n", filename, strerror(errno));
return 1;
}
@@ -145,16 +146,16 @@ main(int argc, char *argv[])
if(ret != 0)
fprintf(stderr,
"cksum: Warning: posix_fadvise failed on file '%s': %s\n",
- argv[i],
+ filename,
strerror(ret));
}
int err = 0;
- if(cksum(fd, argv[i]) < 0) err = 1;
+ if(cksum(fd, filename) < 0) err = 1;
if(close(fd) < 0)
{
- fprintf(stderr, "cksum: Failed closing file '%s': %s\n", argv[i], strerror(errno));
+ fprintf(stderr, "cksum: Failed closing file '%s': %s\n", filename, strerror(errno));
return 1;
}
diff --git a/cmd/cut.c b/cmd/cut.c
@@ -126,7 +126,7 @@ parse_list(char *s)
}
static int
-cut_b(FILE *in, char *filename)
+cut_b(FILE *in, const char *filename)
{
char *line = NULL;
size_t line_len = 0;
@@ -165,7 +165,7 @@ cut_b(FILE *in, char *filename)
}
static int
-cut_c(FILE *in, char *filename)
+cut_c(FILE *in, const char *filename)
{
char *line = NULL;
size_t line_len = 0;
@@ -230,7 +230,7 @@ cut_c(FILE *in, char *filename)
}
static int
-cut_f(FILE *in, char *filename)
+cut_f(FILE *in, const char *filename)
{
char *line = NULL;
size_t line_len = 0;
@@ -284,7 +284,7 @@ cut_f(FILE *in, char *filename)
}
static int
-cut(FILE *in, char *filename)
+cut(FILE *in, const char *filename)
{
switch(mode)
{
diff --git a/cmd/date.c b/cmd/date.c
@@ -48,8 +48,8 @@ main(int argc, char *argv[])
.tv_sec = 0,
.tv_nsec = 0,
};
- char *format = "%c";
- char *input_format = NULL;
+ const char *format = "%c";
+ const char *input_format = NULL;
int uflag = 0;
int dflag = 0, rflag = 0;
int c;
@@ -73,7 +73,7 @@ main(int argc, char *argv[])
while((c = getopt(argc, argv, ":d:f:jr:Ru")) != -1)
{
- char *errstr = NULL;
+ const char *errstr = NULL;
switch(c)
{
case 'd': /* Custom datetime */
@@ -220,7 +220,7 @@ main(int argc, char *argv[])
if(input_format == NULL && argc > 0 && *argv && **argv != '+')
{
- char *fmt = "%m%d%H%M";
+ const char *fmt = "%m%d%H%M";
char *s = strptime(argv[0], fmt, &tm);
if(s == NULL)
{
diff --git a/cmd/head.c b/cmd/head.c
@@ -17,9 +17,9 @@
#define MIN(a, b) (((a) < (b)) ? (a) : (b))
-static char *header_fmt = "==> %s <==\n";
+static const char *header_fmt = "==> %s <==\n";
-char *argv0 = "head";
+const char *argv0 = "head";
size_t lines = 10;
size_t bytes = 0;
@@ -28,7 +28,7 @@ char *buf = NULL;
size_t buflen = 0;
static int
-copy_bytes(char *filename)
+copy_bytes(const char *filename)
{
if(buflen == 0)
{
@@ -95,7 +95,7 @@ copy_bytes(char *filename)
}
static int
-copy_lines(char *filename)
+copy_lines(const char *filename)
{
int err = 0;
FILE *in = NULL;
@@ -155,7 +155,7 @@ usage()
int
main(int argc, char *argv[])
{
- int (*copy_action)(char *filename) = copy_lines;
+ int (*copy_action)(const char *filename) = copy_lines;
int print_header = 0;
while(optind < argc)
@@ -244,7 +244,7 @@ main(int argc, char *argv[])
if(argc <= 0)
{
- char *filename = "-";
+ const char *filename = "-";
if(print_header == 1)
{
diff --git a/cmd/id.c b/cmd/id.c
@@ -101,7 +101,7 @@ list_groups(struct passwd *pw, int ngroups, gid_t *groups)
}
static int
-print_gid(char *field, struct group *gr, gid_t gid)
+print_gid(const char *field, struct group *gr, gid_t gid)
{
if(gr && gr->gr_name)
{
@@ -118,7 +118,7 @@ print_gid(char *field, struct group *gr, gid_t gid)
}
static int
-print_uid(char *field, struct passwd *pw, uid_t uid)
+print_uid(const char *field, struct passwd *pw, uid_t uid)
{
if(pw && pw->pw_name)
{
diff --git a/cmd/install.c b/cmd/install.c
@@ -34,7 +34,7 @@ mode_t mkdir_parents_filemask;
mode_t mode = 00755;
uid_t user = (uid_t)-1;
gid_t group = (gid_t)-1;
-char *argv0 = "install";
+const char *argv0 = "install";
static int
do_install(char *src, char *dest, bool is_dir)
diff --git a/cmd/mkdir.c b/cmd/mkdir.c
@@ -17,7 +17,7 @@
#include <sys/stat.h> // mkdir
#include <unistd.h> // getopt
-char *argv0 = "mkdir";
+const char *argv0 = "mkdir";
bool mkdir_parents_verbose = false;
mode_t mkdir_parents_filemask;
diff --git a/cmd/mknod.c b/cmd/mknod.c
@@ -122,7 +122,7 @@ main(int argc, char *argv[])
unsigned int maj = strtodev(argv[2]);
unsigned int min = strtodev(argv[3]);
- char *type_name;
+ const char *type_name;
switch(type[0])
{
case 'b':
diff --git a/cmd/mktemp.c b/cmd/mktemp.c
@@ -16,7 +16,7 @@ main(int argc, char *argv[])
{
bool o_create_dir = false, o_quiet = false;
char template[PATH_MAX] = "tmp.XXXXXXXXXX";
- char *tmpdir = NULL;
+ const char *tmpdir = NULL;
int c = -1;
while((c = getopt(argc, argv, ":dqp:t")) != -1)
diff --git a/cmd/mv.c b/cmd/mv.c
@@ -35,7 +35,7 @@
#define O_SEARCH O_PATH
#endif
-char *argv0 = "mv";
+const char *argv0 = "mv";
bool no_clob = false, force = false, interact = false, verbose = false;
@@ -44,7 +44,7 @@ static int stdin_tty = 0;
struct named_fd
{
int fd;
- char *name;
+ const char *name;
};
static int do_renameat(struct named_fd srcdir,
diff --git a/cmd/nice.c b/cmd/nice.c
@@ -30,11 +30,11 @@ main(int argc, char *argv[])
{
case 'n':
assert(errno == 0);
- char *endptr = "";
+ char *endptr = NULL;
incr = strtol(optarg, &endptr, 10);
- if(*endptr != 0) errno = EINVAL;
+ if(endptr && *endptr != 0) errno = EINVAL;
if(errno != 0)
{
fprintf(
diff --git a/cmd/rm.c b/cmd/rm.c
@@ -27,7 +27,7 @@
#include <unistd.h> // unlink, isatty
bool opt_d = false, force = false, recurse = false, verbose = false, opt_i = false;
-char *argv0 = "rm";
+const char *argv0 = "rm";
static int
do_unlinkat(int fd, char *name, char *acc_path)
diff --git a/cmd/seq.c b/cmd/seq.c
@@ -12,8 +12,8 @@
#include <string.h> // strerror
#include <unistd.h> // getopt, optarg, optind
-char *sep = "\n";
-char *term = "\n";
+const char *sep = "\n";
+const char *term = "\n";
int len = 0;
diff --git a/cmd/sha1sum.c b/cmd/sha1sum.c
@@ -19,7 +19,7 @@
#define SHA1SUM_LEN SHA1_DIGEST_LENGTH * 2 + 1
static int
-sha1sum(int fd, char *fdname, char sum[SHA1SUM_LEN])
+sha1sum(int fd, const char *fdname, char sum[SHA1SUM_LEN])
{
struct sha1 ctx;
@@ -52,7 +52,7 @@ sha1sum(int fd, char *fdname, char sum[SHA1SUM_LEN])
#define XSTR(s) STR(s)
static int
-check(FILE *file, char *filename)
+check(FILE *file, const char *filename)
{
int err = 0;
@@ -189,28 +189,29 @@ main(int argc, char *argv[])
for(int i = 0; i < argc; i++)
{
FILE *file = NULL;
+ const char *filename = argv[i];
- if(argv[i][0] == '-' && argv[i][1] == '\0')
+ if(filename[0] == '-' && filename[1] == '\0')
{
- argv[i] = "<stdin>";
+ filename = "<stdin>";
file = stdin;
}
else
{
- file = fopen(argv[i], "rb");
+ file = fopen(filename, "rb");
if(file == NULL)
{
fprintf(
- stderr, "sha1sum: Error: Failed opening file '%s': %s\n", argv[i], strerror(errno));
+ stderr, "sha1sum: Error: Failed opening file '%s': %s\n", filename, strerror(errno));
return 1;
}
}
- if(check(file, argv[i]) != 0) err = 1;
+ if(check(file, filename) != 0) err = 1;
if(fclose(file) < 0)
{
- fprintf(stderr, "sha1sum: Failed closing file '%s': %s\n", argv[i], strerror(errno));
+ fprintf(stderr, "sha1sum: Failed closing file '%s': %s\n", filename, strerror(errno));
return 1;
}
}
@@ -232,17 +233,19 @@ main(int argc, char *argv[])
for(int i = 0; i < argc; i++)
{
int fd = -1;
- if(argv[i][0] == '-' && argv[i][1] == '\0')
+ const char *filename = argv[i];
+ if(filename[0] == '-' && filename[1] == '\0')
{
- argv[i] = "<stdin>";
+ filename = "<stdin>";
fd = STDIN_FILENO;
}
else
{
- fd = open(argv[i], O_RDONLY | O_NOCTTY);
+ fd = open(filename, O_RDONLY | O_NOCTTY);
if(fd < 0)
{
- fprintf(stderr, "sha1sum: Error: Failed opening file '%s': %s\n", argv[i], strerror(errno));
+ fprintf(
+ stderr, "sha1sum: Error: Failed opening file '%s': %s\n", filename, strerror(errno));
return 1;
}
@@ -250,19 +253,19 @@ main(int argc, char *argv[])
if(ret != 0)
fprintf(stderr,
"sha1sum: Warning: posix_fadvise failed on file '%s': %s\n",
- argv[i],
+ filename,
strerror(ret));
}
int err = 0;
char sum[SHA1SUM_LEN] = "";
- if(sha1sum(fd, argv[i], sum) < 0) err = 1;
- printf("%s %s\n", sum, argv[i]);
+ if(sha1sum(fd, filename, sum) < 0) err = 1;
+ printf("%s %s\n", sum, filename);
if(close(fd) < 0)
{
- fprintf(stderr, "sha1sum: Failed closing file '%s': %s\n", argv[i], strerror(errno));
+ fprintf(stderr, "sha1sum: Failed closing file '%s': %s\n", filename, strerror(errno));
return 1;
}
diff --git a/cmd/split.c b/cmd/split.c
@@ -16,9 +16,9 @@
#include <sys/stat.h> // fstat
#include <unistd.h> // getopt
-char *argv0 = "split";
+const char *argv0 = "split";
-char *name = "x";
+const char *name = "x";
size_t name_len = 1;
size_t suffix_len = 2, bytes = 0, lines = 0;
@@ -201,7 +201,7 @@ split_lines()
return err;
}
-static char *error_opt_b_l = "split: Options -b and -l are mutually exclusive\n";
+static const char *error_opt_b_l = "split: Options -b and -l are mutually exclusive\n";
int
main(int argc, char *argv[])
diff --git a/cmd/strings.c b/cmd/strings.c
@@ -14,7 +14,7 @@
#include <unistd.h> /* read(), write(), close(), getopt(), optarg, optind */
size_t opt_min_strlen = 4;
-char *opt_offset_format = NULL;
+const char *opt_offset_format = NULL;
static int
print_string(char *buffer, size_t offset)
@@ -115,9 +115,9 @@ main(int argc, char *argv[])
break;
case 'n':
assert(errno == 0);
- char *endptr = "";
+ char *endptr = NULL;
opt_min_strlen = strtol(optarg, &endptr, 10);
- if(*endptr != 0)
+ if(endptr && *endptr != 0)
{
// extraneous characters is invalid
errno = EINVAL;
diff --git a/cmd/test.c b/cmd/test.c
@@ -112,9 +112,10 @@ static const struct t_op
{
char op_text[2];
short op_num;
-} ops1[] =
- {
- // clang-format off
+} ops1
+ [] =
+ {
+ // clang-format off
{"=", STREQ},
{"<", STRLT},
{">", STRGT},
@@ -158,7 +159,7 @@ static const struct t_op
{"nt", FILNT},
{"ot", FILOT},
{"ef", FILEQ},
- // clang-format on
+ // clang-format on
};
static int nargc;
diff --git a/cmd/timeout.c b/cmd/timeout.c
@@ -50,7 +50,7 @@ main(int argc, char *argv[])
{
struct timespec time_kill = {.tv_sec = 0, .tv_nsec = 0};
int term_sig = SIGTERM;
- char *term_signame = "SIGTERM";
+ const char *term_signame = "SIGTERM";
bool kill_child = true;
int cmd_exit_timeout = CMD_EXIT_TIMEOUT;
diff --git a/cmd/touch.c b/cmd/touch.c
@@ -22,7 +22,7 @@
// [[CC]YY]MMDDhhmm[.SS]
static struct timespec
-opt_t_parse(char *arg, char **errstr)
+opt_t_parse(char *arg, const char **errstr)
{
struct timespec res = {.tv_sec = 0, .tv_nsec = 0};
struct tm tm = {
@@ -64,7 +64,7 @@ opt_t_parse(char *arg, char **errstr)
}
}
- char *fmt = NULL;
+ const char *fmt = NULL;
switch(len)
{
@@ -127,7 +127,7 @@ main(int argc, char *argv[])
int c = 0;
while((c = getopt(argc, argv, ":achmr:t:d:")) != -1)
{
- char *errstr = NULL;
+ const char *errstr = NULL;
switch(c)
{
diff --git a/cmd/truncate.c b/cmd/truncate.c
@@ -17,7 +17,7 @@
#include <sys/stat.h>
#include <unistd.h> // getopt
-char *argv0 = "truncate";
+const char *argv0 = "truncate";
static void
usage()
diff --git a/cmd/wc.c b/cmd/wc.c
@@ -22,7 +22,7 @@
#include <getopt.h>
#endif
-static char *argv0 = "wc";
+static const char *argv0 = "wc";
static enum {
WC_OPT_C = 1 << 0,
@@ -34,9 +34,9 @@ static enum {
off_t total_bytes = 0, total_lines = 0, total_words = 0;
static void
-print_counts(off_t lines, off_t words, off_t bytes, char *filename)
+print_counts(off_t lines, off_t words, off_t bytes, const char *filename)
{
- char *fmt = "%ld";
+ const char *fmt = "%ld";
if(FIELD_MATCH(wc_opts, WC_OPT_L))
{
printf(fmt, lines);
diff --git a/cmd/yes.c b/cmd/yes.c
@@ -3,6 +3,7 @@
// SPDX-License-Identifier: MPL-2.0
#define _POSIX_C_SOURCE 200809L
+#include <assert.h>
#include <stdbool.h>
#include <stdio.h> // fwrite, perror, ferror
#include <string.h> // strlen
@@ -12,16 +13,20 @@ main(int argc, char *argv[])
{
size_t arg_len = 0;
- argv++;
- argc--;
+ assert(argc >= 1);
- if(argc == 0)
+ if(argc == 1)
{
- *argv = "y\n";
+ argv[0][0] = 'y';
+ argv[0][1] = '\n';
+ argv[0][2] = '\0';
arg_len = 2;
}
else
{
+ argv++;
+ argc--;
+
for(int i = 0; i < argc; i++)
{
size_t len = strlen(argv[i]);
@@ -31,7 +36,8 @@ main(int argc, char *argv[])
if(arg_len == 0)
{
- *argv = "\n";
+ argv[0][0] = '\n';
+ argv[0][1] = '\0';
arg_len = 1;
}
else
diff --git a/lib/bytes2hex.c b/lib/bytes2hex.c
@@ -10,7 +10,7 @@
void
bytes2hex(const uint8_t *data, size_t datalen, char *buf, size_t buflen)
{
- static char *hextab = "0123456789abcdef";
+ static const char *hextab = "0123456789abcdef";
assert(buflen >= datalen * 2);
diff --git a/lib/consent.h b/lib/consent.h
@@ -4,7 +4,7 @@
#include <stdbool.h>
-extern char *argv0;
+extern const char *argv0;
// Consent therefore defaults to no, including in cases of error
bool consentf(const char *restrict fmt, ...);
diff --git a/lib/humanize.c b/lib/humanize.c
@@ -12,12 +12,12 @@ struct si_scale
dtosi(double num, bool iec)
{
#define PFX 11
- char *si_prefixes[PFX] = {"", "k", "M", "G", "T", "P", "E", "Z", "Y", "R", "Q"};
- char *iec_prefixes[PFX] = {
+ const char *si_prefixes[PFX] = {"", "k", "M", "G", "T", "P", "E", "Z", "Y", "R", "Q"};
+ const char *iec_prefixes[PFX] = {
"B", "KiB", "MiB", "GiB", "TiB", "PiB", "EiB", "ZiB", "YiB", "RiB", "QiB"};
int div = iec ? 1024 : 1000;
- char **prefixes = iec ? iec_prefixes : si_prefixes;
+ const char **prefixes = iec ? iec_prefixes : si_prefixes;
struct si_scale ret = {
.number = num,
diff --git a/lib/humanize.h b/lib/humanize.h
@@ -8,7 +8,7 @@
struct si_scale
{
double number;
- char *prefix;
+ const char *prefix;
unsigned exponant;
};
diff --git a/lib/iso_parse.c b/lib/iso_parse.c
@@ -21,7 +21,7 @@
// Sets errstr on failure
// YYYY-MM-DD[T ]hh:mm:SS([,\.]frac)?(Z|[+\-]hh:?mm)?
char *
-iso_parse(char *arg, struct tm *time, long *nsec, char **errstr)
+iso_parse(char *arg, struct tm *time, long *nsec, const char **errstr)
{
// For Alpine's abuild compatibility
if(arg[0] == '@')
diff --git a/lib/iso_parse.h b/lib/iso_parse.h
@@ -6,7 +6,7 @@
// Sets errstr on failure
// YYYY-MM-DD[T ]hh:mm:SS([,\.]frac)?(Z|[+\-]hh:?mm)?
-extern char *iso_parse(char *arg, struct tm *time, long *nsec, char **errstr);
+extern char *iso_parse(char *arg, struct tm *time, long *nsec, const char **errstr);
// Because mktime() messes with tm_gmtoff yet doesn't applies the offset
// Returns (time_t)-1 on failure
diff --git a/lib/mkdir.h b/lib/mkdir.h
@@ -6,7 +6,7 @@
#include <sys/types.h> // mode_t
// to be declared in each utility
-extern char *argv0;
+extern const char *argv0;
extern bool mkdir_parents_verbose;
extern mode_t mkdir_parents_filemask;
diff --git a/lib/sys_signame.c b/lib/sys_signame.c
@@ -4,7 +4,7 @@
// /!\ File generated by lib/sys_signame.sh avoid editing
#include "sys_signame.h"
-char *util_sys_signame[NSIG] = {
+const char *util_sys_signame[NSIG] = {
#ifdef SIGABRT
[SIGABRT] = "ABRT",
#endif
diff --git a/lib/sys_signame.h b/lib/sys_signame.h
@@ -20,6 +20,6 @@
#endif
#endif
-extern char *util_sys_signame[NSIG];
+extern const char *util_sys_signame[NSIG];
static size_t util_sys_signame_len = NSIG;
diff --git a/lib/sys_signame.sh b/lib/sys_signame.sh
@@ -6,7 +6,7 @@ cat <<-EOF
// /!\ File generated by lib/sys_signame.sh avoid editing
#include "sys_signame.h"
-char *util_sys_signame[NSIG] = {
+const char *util_sys_signame[NSIG] = {
EOF
# From signal.h definition in POSIX
diff --git a/lib/tr_str.c b/lib/tr_str.c
@@ -145,7 +145,7 @@ bracket(STR *s)
typedef struct
{
- char *name;
+ const char *name;
int (*func)(int);
int *set;
} CLASS;
diff --git a/lib/tr_str.h b/lib/tr_str.h
@@ -49,10 +49,11 @@ typedef struct
SEQUENCE,
SET
} state;
- int cnt; /* character count */
- int lastch; /* last character */
- int equiv[2]; /* equivalence set */
- int *set; /* set of characters */
+ int cnt; /* character count */
+ int lastch; /* last character */
+ int equiv[2]; /* equivalence set */
+ int *set; /* set of characters */
+
unsigned char *str; /* user's string */
} STR;
diff --git a/lib/truncation.c b/lib/truncation.c
@@ -106,7 +106,7 @@ apply_size_suffix(unsigned long *size, char *endptr)
}
int
-parse_size(char *arg, struct truncation *buf)
+parse_size(const char *arg, struct truncation *buf)
{
assert(arg != NULL);
assert(buf != NULL);
diff --git a/lib/truncation.h b/lib/truncation.h
@@ -21,6 +21,6 @@ struct truncation
off_t size;
};
-int parse_size(char *arg, struct truncation *buf);
+int parse_size(const char *arg, struct truncation *buf);
int apply_size_suffix(unsigned long *size, char *endptr);
int apply_truncation(int fd, struct truncation tr, char *arg);
diff --git a/lib/user_group_parse.c b/lib/user_group_parse.c
@@ -34,7 +34,7 @@ parse_user(char *str, uid_t *user)
struct passwd *pw = getpwnam(str);
if(pw == NULL)
{
- char *e = strerror(errno);
+ const char *e = strerror(errno);
if(errno == 0) e = "Entry Not Found";
fprintf(stderr, "%s: Error: Failed to get entry for username '%s': %s\n", argv0, str, e);
@@ -67,7 +67,7 @@ parse_group(char *str, gid_t *group)
struct group *gr = getgrnam(str);
if(gr == NULL)
{
- char *e = strerror(errno);
+ const char *e = strerror(errno);
if(errno == 0) e = "Entry Not Found";
fprintf(stderr, "%s: Error: Failed to get entry for group '%s': %s\n", argv0, str, e);
diff --git a/lib/user_group_parse.h b/lib/user_group_parse.h
@@ -6,7 +6,7 @@
#include <sys/types.h> // uid_t, gid_t
-extern char *argv0;
+extern const char *argv0;
int parse_user(char *str, uid_t *user);
int parse_group(char *str, gid_t *group);
diff --git a/test-lib/mode.c b/test-lib/mode.c
@@ -14,7 +14,7 @@ int counter = 0;
int err = 0;
static void
-t_mode(char *str, mode_t old, mode_t expect)
+t_mode(const char *str, mode_t old, mode_t expect)
{
int id = ++counter;
const char *errstr = NULL;
@@ -32,7 +32,7 @@ t_mode(char *str, mode_t old, mode_t expect)
}
static void
-t_mode_errstr(char *str, mode_t old, char *expect_errstr)
+t_mode_errstr(const char *str, mode_t old, const char *expect_errstr)
{
assert(expect_errstr != NULL);
diff --git a/test-lib/sha1.c b/test-lib/sha1.c
@@ -15,7 +15,10 @@ int counter = 0;
int err = 0;
static void
-t_sha1(char *name, const void *data, size_t datalen, char expected[SHA1_DIGEST_LENGTH * 2])
+t_sha1(const char *name,
+ const void *data,
+ size_t datalen,
+ const char expected[SHA1_DIGEST_LENGTH * 2])
{
int id = ++counter;
diff --git a/test-lib/strtodur.c b/test-lib/strtodur.c
@@ -49,15 +49,15 @@ main()
// TODO: Capture errors, say with open_memstream(3)
t_strtodur(NULL, 0, 0);
- t_strtodur("", 0, 0);
- t_strtodur(",", 0, 0);
+ t_strtodur((char *)"", 0, 0);
+ t_strtodur((char *)",", 0, 0);
- t_strtodur("1", 1, 0);
- t_strtodur("1.", 1, 0);
- t_strtodur("1,", 1, 0);
+ t_strtodur((char *)"1", 1, 0);
+ t_strtodur((char *)"1.", 1, 0);
+ t_strtodur((char *)"1,", 1, 0);
- t_strtodur(".1", 0, 1000000000 * 0.1);
- t_strtodur("0.1", 0, 1000000000 * 0.1);
+ t_strtodur((char *)".1", 0, 1000000000 * 0.1);
+ t_strtodur((char *)"0.1", 0, 1000000000 * 0.1);
assert(counter == plan);
return err;
diff --git a/test-lib/symbolize_mode.c b/test-lib/symbolize_mode.c
@@ -13,7 +13,7 @@ int counter = 0;
int err = 0;
static void
-t_symbolize_mode(mode_t mode, char *expected)
+t_symbolize_mode(mode_t mode, const char *expected)
{
char str[11] = "";
symbolize_mode(mode, str);
diff --git a/test-lib/truncation.c b/test-lib/truncation.c
@@ -8,13 +8,13 @@
#include <assert.h>
#include <stdio.h> // printf
-char *argv0 = "test-lib/truncation";
+const char *argv0 = "test-lib/truncation";
int counter = 0;
int err = 0;
static void
-t_parse_size(char *str, off_t size, enum operation_e op)
+t_parse_size(const char *str, off_t size, enum operation_e op)
{
int id = ++counter;