shithub: scc

Download patch

ref: 6b1309ac40e3f1842f42b5fbd995b40dbf8e3932
parent: f22374d59ae47eaf74ad42b55b576a442c608517
author: Roberto E. Vargas Caballero <k0ga@shike2.com>
date: Thu Jun 30 10:22:29 EDT 2022

libc: Fix all the constness problems

The const warnings were ignored based in wrong assumptions about how
the C standard specifies the type qualifier behaviour related to
pointers.

--- a/include/bits/darwin/sys.h
+++ b/include/bits/darwin/sys.h
@@ -23,7 +23,7 @@
 struct sigaction;
 struct rusage;
 
-extern int _execve(char *, char *[], char *[]);
+extern int _execve(const char *, const char *[], const char *[]);
 extern int _fork(void);
 extern pid_t _getpid(void);
 extern int _kill(pid_t, int);
--- a/include/bits/dragonfly/sys.h
+++ b/include/bits/dragonfly/sys.h
@@ -23,7 +23,7 @@
 struct sigaction;
 struct rusage;
 
-extern int _execve(char *, char *[], char *[]);
+extern int _execve(const char *, const char *[], const char *[]);
 extern int _fork(void);
 extern pid_t _getpid(void);
 extern int _kill(pid_t, int);
--- a/include/bits/linux/sys.h
+++ b/include/bits/linux/sys.h
@@ -23,7 +23,7 @@
 struct sigaction;
 struct rusage;
 
-extern int _execve(char *, char *[], char *[]);
+extern int _execve(const char *, const char *[], const char *[]);
 extern int _fork(void);
 extern pid_t _getpid(void);
 extern int _kill(pid_t, int);
--- a/include/bits/netbsd/sys.h
+++ b/include/bits/netbsd/sys.h
@@ -23,7 +23,7 @@
 struct sigaction;
 struct rusage;
 
-extern int _execve(char *, char *[], char *[]);
+extern int _execve(const char *, const char *[], const char *[]);
 extern int _fork(void);
 extern pid_t _getpid(void);
 extern int _kill(pid_t, int);
--- a/include/bits/openbsd/sys.h
+++ b/include/bits/openbsd/sys.h
@@ -23,7 +23,7 @@
 struct sigaction;
 struct rusage;
 
-extern int _execve(char *, char *[], char *[]);
+extern int _execve(const char *, const char *[], const char *[]);
 extern int _fork(void);
 extern pid_t _getpid(void);
 extern int _kill(pid_t, int);
--- a/src/libc/arch/posix/getenv.c
+++ b/src/libc/arch/posix/getenv.c
@@ -3,17 +3,17 @@
 
 #undef getenv
 
-extern char **_environ;
+extern const char **_environ;
 
 char *
 getenv(const char *name)
 {
-	char **p, *s;
+	const char **p, *s;
 	size_t len = strlen(name);
 
 	for (p = _environ; s = *p; ++p) {
 		if (!strncmp(name, s, len) && s[len] == '=')
-			return s + len + 1;
+			return (char *) s + len + 1;
 	}
 	return NULL;
 }
--- a/src/libc/arch/posix/system.c
+++ b/src/libc/arch/posix/system.c
@@ -9,7 +9,7 @@
 
 #undef system
 
-extern char **_environ;
+extern const char **_environ;
 
 int
 system(const char *cmd)
@@ -24,7 +24,7 @@
 	case -1:
 		return -1;
 	case 0:
-		_execve(SHELL, (char*[]) {"sh", "-c", cmd, NULL}, _environ);
+		_execve(SHELL, (const char*[]) {"sh", "-c", cmd, NULL}, _environ);
 		_exit(127);
 	default:
 		while (_waitpid(pid, &st, 0) < 0 && errno == EINTR)
--- a/src/libc/stdlib/bsearch.c
+++ b/src/libc/stdlib/bsearch.c
@@ -7,7 +7,7 @@
 {
 	int t;
 	size_t mid, low, high;
-	char *cur, *base = ary;
+	char *cur, *base = (char *) ary;
 
 	low = 0;
 	high = n - 1;
--- a/src/libc/stdlib/strtol.c
+++ b/src/libc/stdlib/strtol.c
@@ -9,11 +9,11 @@
 #undef strtol
 
 long
-strtol(const char * restrict s, char ** restrict end, int base)
+strtol(const char * restrict ptr, char ** restrict end, int base)
 {
 	int d, sign = -1;
 	long n;
-	const char *t;
+	char *t, *s = (char *) ptr;
 
 	if (end)
 		*end = s;
--- a/src/libc/stdlib/strtoll.c
+++ b/src/libc/stdlib/strtoll.c
@@ -9,11 +9,11 @@
 #undef strtoll
 
 long long
-strtoll(const char * restrict s, char ** restrict end, int base)
+strtoll(const char * restrict ptr, char ** restrict end, int base)
 {
 	int d, sign = -1;
 	long long n;
-	const char *t;
+	char *t, *s = (char *) ptr;
 
 	if (end)
 		*end = s;
--- a/src/libc/stdlib/strtoul.c
+++ b/src/libc/stdlib/strtoul.c
@@ -9,11 +9,11 @@
 #undef strtoul
 
 unsigned long
-strtoul(const char * restrict s, char ** restrict end, int base)
+strtoul(const char * restrict ptr, char ** restrict end, int base)
 {
 	int d, sign = 1;
 	unsigned long n;
-	const char *t;
+	char *t, *s = (char *) ptr;
 
 	if (end)
 		*end = s;
--- a/src/libc/stdlib/strtoull.c
+++ b/src/libc/stdlib/strtoull.c
@@ -9,11 +9,11 @@
 #undef strtoull
 
 unsigned long long
-strtoull(const char * restrict s, char ** restrict end, int base)
+strtoull(const char * restrict ptr, char ** restrict end, int base)
 {
 	int d, sign = 1;
 	unsigned long long n;
-	const char *t;
+	char *t, *s = (char *) ptr;
 
 	if (end)
 		*end = s;
--- a/src/libc/string/memchr.c
+++ b/src/libc/string/memchr.c
@@ -5,7 +5,7 @@
 void *
 memchr(const void *s, int c, size_t n)
 {
-	const unsigned char *bp = s;
+	unsigned char *bp = (unsigned char *) s;
 
 	while (n > 0 && *bp++ != c)
 		--n;
--- a/src/libc/string/strchr.c
+++ b/src/libc/string/strchr.c
@@ -8,5 +8,5 @@
 	while (*s && *s != c)
 		++s;
 
-	return (*s == c) ? s : NULL;
+	return (*s == c) ? (char *) s : NULL;
 }
--- a/src/libc/string/strpbrk.c
+++ b/src/libc/string/strpbrk.c
@@ -16,5 +16,5 @@
 	while ((ch = *s) != 0 && !map[ch])
 		s++;
 
-	return (ch == '\0') ? NULL : s;
+	return (ch == '\0') ? NULL : (char *) s;
 }
--- a/src/libc/string/strrchr.c
+++ b/src/libc/string/strrchr.c
@@ -12,5 +12,5 @@
 	while (t > s && *t != c)
 		--t;
 
-	return (*t == c) ? t : NULL;
+	return (*t == c) ? (char *) t : NULL;
 }
--- a/src/libc/string/strstr.c
+++ b/src/libc/string/strstr.c
@@ -11,11 +11,11 @@
 	int len;
 
 	if ((len = strlen(s2)) == 0)
-		return s1;
+		return (char *) s1;
 
 	for (p = s1; p = strchr(p, c); ++p) {
 		if (!strncmp(p, s2, len))
-			return p;
+			return (char *) p;
 	}
 
 	return NULL;