[PATCH] tools/nolibc: rename SET_ERRNO() to __nolibc_set_errno()

Thomas Weißschuh posted 1 patch 3 weeks, 5 days ago
tools/include/nolibc/dirent.h   |  4 ++--
tools/include/nolibc/errno.h    |  4 ++--
tools/include/nolibc/stdio.h    | 12 ++++++------
tools/include/nolibc/stdlib.h   |  6 +++---
tools/include/nolibc/sys.h      | 13 ++++++++-----
tools/include/nolibc/sys/mman.h |  4 ++--
tools/include/nolibc/sys/wait.h |  2 +-
tools/include/nolibc/unistd.h   |  4 ++--
8 files changed, 26 insertions(+), 23 deletions(-)
[PATCH] tools/nolibc: rename SET_ERRNO() to __nolibc_set_errno()
Posted by Thomas Weißschuh 3 weeks, 5 days ago
The previous name infringes on the application's namespace.

Rename it to a nolibc-private name.

Signed-off-by: Thomas Weißschuh <linux@weissschuh.net>
---
 tools/include/nolibc/dirent.h   |  4 ++--
 tools/include/nolibc/errno.h    |  4 ++--
 tools/include/nolibc/stdio.h    | 12 ++++++------
 tools/include/nolibc/stdlib.h   |  6 +++---
 tools/include/nolibc/sys.h      | 13 ++++++++-----
 tools/include/nolibc/sys/mman.h |  4 ++--
 tools/include/nolibc/sys/wait.h |  2 +-
 tools/include/nolibc/unistd.h   |  4 ++--
 8 files changed, 26 insertions(+), 23 deletions(-)

diff --git a/tools/include/nolibc/dirent.h b/tools/include/nolibc/dirent.h
index 4e02ef25e72d..49e5190cc1f0 100644
--- a/tools/include/nolibc/dirent.h
+++ b/tools/include/nolibc/dirent.h
@@ -31,7 +31,7 @@ static __attribute__((unused))
 DIR *fdopendir(int fd)
 {
 	if (fd < 0) {
-		SET_ERRNO(EBADF);
+		__nolibc_set_errno(EBADF);
 		return NULL;
 	}
 	return (DIR *)(intptr_t)~fd;
@@ -54,7 +54,7 @@ int closedir(DIR *dirp)
 	intptr_t i = (intptr_t)dirp;
 
 	if (i >= 0) {
-		SET_ERRNO(EBADF);
+		__nolibc_set_errno(EBADF);
 		return -1;
 	}
 	return close(~i);
diff --git a/tools/include/nolibc/errno.h b/tools/include/nolibc/errno.h
index a2325596d550..9c2fe7810073 100644
--- a/tools/include/nolibc/errno.h
+++ b/tools/include/nolibc/errno.h
@@ -13,12 +13,12 @@
 #include <linux/errno.h>
 
 #ifndef NOLIBC_IGNORE_ERRNO
-#define SET_ERRNO(v) do { errno = (v); } while (0)
+#define __nolibc_set_errno(v) do { errno = (v); } while (0)
 int errno __attribute__((weak));
 char *program_invocation_name __attribute__((weak)) = (char *)"";
 char *program_invocation_short_name __attribute__((weak)) = (char *)"";
 #else
-#define SET_ERRNO(v) do { } while (0)
+#define __nolibc_set_errno(v) do { } while (0)
 #define program_invocation_name ""
 #define program_invocation_short_name ""
 #endif
diff --git a/tools/include/nolibc/stdio.h b/tools/include/nolibc/stdio.h
index ebdd413d13ec..25205d40e2b3 100644
--- a/tools/include/nolibc/stdio.h
+++ b/tools/include/nolibc/stdio.h
@@ -50,7 +50,7 @@ static __attribute__((unused))
 FILE *fdopen(int fd, const char *mode __attribute__((unused)))
 {
 	if (fd < 0) {
-		SET_ERRNO(EBADF);
+		__nolibc_set_errno(EBADF);
 		return NULL;
 	}
 	return (FILE*)(intptr_t)~fd;
@@ -72,7 +72,7 @@ FILE *fopen(const char *pathname, const char *mode)
 		flags = O_WRONLY | O_CREAT | O_APPEND;
 		break;
 	default:
-		SET_ERRNO(EINVAL); return NULL;
+		__nolibc_set_errno(EINVAL); return NULL;
 	}
 
 	if (mode[1] == '+')
@@ -89,7 +89,7 @@ int fileno(FILE *stream)
 	intptr_t i = (intptr_t)stream;
 
 	if (i >= 0) {
-		SET_ERRNO(EBADF);
+		__nolibc_set_errno(EBADF);
 		return -1;
 	}
 	return ~i;
@@ -103,7 +103,7 @@ int fflush(FILE *stream)
 
 	/* NULL is valid here. */
 	if (i > 0) {
-		SET_ERRNO(EBADF);
+		__nolibc_set_errno(EBADF);
 		return -1;
 	}
 
@@ -118,7 +118,7 @@ int fclose(FILE *stream)
 	intptr_t i = (intptr_t)stream;
 
 	if (i >= 0) {
-		SET_ERRNO(EBADF);
+		__nolibc_set_errno(EBADF);
 		return -1;
 	}
 
@@ -900,7 +900,7 @@ int vsscanf(const char *str, const char *format, va_list args)
 			} else if (*format == 'p') {
 				*va_arg(args, void **) = (void *)strtoul(str, &endptr, 16);
 			} else {
-				SET_ERRNO(EILSEQ);
+				__nolibc_set_errno(EILSEQ);
 				goto done;
 			}
 
diff --git a/tools/include/nolibc/stdlib.h b/tools/include/nolibc/stdlib.h
index 1816c2368b68..400f160e2fa5 100644
--- a/tools/include/nolibc/stdlib.h
+++ b/tools/include/nolibc/stdlib.h
@@ -148,7 +148,7 @@ void *calloc(size_t size, size_t nmemb)
 	size_t x;
 
 	if (__builtin_expect(__builtin_mul_overflow(size, nmemb, &x), 0)) {
-		SET_ERRNO(ENOMEM);
+		__nolibc_set_errno(ENOMEM);
 		return NULL;
 	}
 
@@ -440,7 +440,7 @@ uintmax_t __strtox(const char *nptr, char **endptr, int base, intmax_t lower_lim
 	char c;
 
 	if (base < 0 || base > 36) {
-		SET_ERRNO(EINVAL);
+		__nolibc_set_errno(EINVAL);
 		goto out;
 	}
 
@@ -496,7 +496,7 @@ uintmax_t __strtox(const char *nptr, char **endptr, int base, intmax_t lower_lim
 
 out:
 	if (overflow) {
-		SET_ERRNO(ERANGE);
+		__nolibc_set_errno(ERANGE);
 		val = limit;
 	}
 	if (endptr)
diff --git a/tools/include/nolibc/sys.h b/tools/include/nolibc/sys.h
index 548f94d96ed2..650b7a85e0f1 100644
--- a/tools/include/nolibc/sys.h
+++ b/tools/include/nolibc/sys.h
@@ -40,9 +40,12 @@
 #define __sysret(arg)							\
 ({									\
 	__typeof__(arg) __sysret_arg = (arg);				\
-	(__sysret_arg < 0)                              /* error ? */	\
-		? (({ SET_ERRNO(-__sysret_arg); }), -1) /* ret -1 with errno = -arg */ \
-		: __sysret_arg;                         /* return original value */ \
+	/* error ? */							\
+	(__sysret_arg < 0)						\
+		/* return -1 with errno = -arg */			\
+		? (({ __nolibc_set_errno(-__sysret_arg); }), -1)	\
+		/* return original value */				\
+		: __sysret_arg;						\
 })
 
 /* Syscall ENOSYS helper: Avoids unused-parameter warnings, provides compile
@@ -121,7 +124,7 @@ int brk(void *addr)
 	void *ret = _sys_brk(addr);
 
 	if (!ret) {
-		SET_ERRNO(ENOMEM);
+		__nolibc_set_errno(ENOMEM);
 		return -1;
 	}
 	return 0;
@@ -136,7 +139,7 @@ void *sbrk(intptr_t inc)
 	if (ret && _sys_brk(ret + inc) == ret + inc)
 		return ret + inc;
 
-	SET_ERRNO(ENOMEM);
+	__nolibc_set_errno(ENOMEM);
 	return (void *)-1;
 }
 
diff --git a/tools/include/nolibc/sys/mman.h b/tools/include/nolibc/sys/mman.h
index 72bc1d43d1d4..e5eb42825783 100644
--- a/tools/include/nolibc/sys/mman.h
+++ b/tools/include/nolibc/sys/mman.h
@@ -37,7 +37,7 @@ void *mmap(void *addr, size_t length, int prot, int flags, int fd, off_t offset)
 	void *ret = _sys_mmap(addr, length, prot, flags, fd, offset);
 
 	if ((unsigned long)ret >= -4095UL) {
-		SET_ERRNO(-(long)ret);
+		__nolibc_set_errno(-(long)ret);
 		ret = MAP_FAILED;
 	}
 	return ret;
@@ -56,7 +56,7 @@ void *mremap(void *old_address, size_t old_size, size_t new_size, int flags, voi
 	void *ret = _sys_mremap(old_address, old_size, new_size, flags, new_address);
 
 	if ((unsigned long)ret >= -4095UL) {
-		SET_ERRNO(-(long)ret);
+		__nolibc_set_errno(-(long)ret);
 		ret = MAP_FAILED;
 	}
 	return ret;
diff --git a/tools/include/nolibc/sys/wait.h b/tools/include/nolibc/sys/wait.h
index 7a1feb2b66fc..7fb4b3fca013 100644
--- a/tools/include/nolibc/sys/wait.h
+++ b/tools/include/nolibc/sys/wait.h
@@ -41,7 +41,7 @@ pid_t waitpid(pid_t pid, int *status, int options)
 	pid_t id;
 
 	if (pid == INT_MIN) {
-		SET_ERRNO(ESRCH);
+		__nolibc_set_errno(ESRCH);
 		return -1;
 	} else if (pid < -1) {
 		idtype = P_PGID;
diff --git a/tools/include/nolibc/unistd.h b/tools/include/nolibc/unistd.h
index a264a20da13d..d48f02a00f5f 100644
--- a/tools/include/nolibc/unistd.h
+++ b/tools/include/nolibc/unistd.h
@@ -90,7 +90,7 @@ char *getcwd(char *buf, size_t size)
 
 	/* Unlike other libc's we don't handle passing NULL for buf */
 	if (!buf || !size) {
-		SET_ERRNO(EINVAL);
+		__nolibc_set_errno(EINVAL);
 		return NULL;
 	}
 
@@ -105,7 +105,7 @@ char *getcwd(char *buf, size_t size)
 	 * This matches what musl is doing.
 	 */
 	if (ret == 0 || buf[0] != '/') {
-		SET_ERRNO(ENOENT);
+		__nolibc_set_errno(ENOENT);
 		return NULL;
 	}
 

---
base-commit: 9c47af906bc655c8f45aaf1f156656239c2c5073
change-id: 20260831-nolibc-set-errno-6df408a688f9

Best regards,
--  
Thomas Weißschuh <linux@weissschuh.net>