shithub: scc

Download patch

ref: c22a72acf6627d779b527dfd43e6abc7148f2886
parent: 1d263bb8b0a2b372050ec285a1306431c203542e
author: Roberto E. Vargas Caballero <k0ga@shike2.com>
date: Tue May 17 13:02:09 EDT 2022

libc: Add _access() macros

_access() is used in tmpnam() and the flag value is just hardcoded
which theoretically could cause some problems in some systems with
different values.

--- a/include/bits/darwin/sys.h
+++ b/include/bits/darwin/sys.h
@@ -11,6 +11,11 @@
 #define CLOCKS_PER_SEC ((clock_t) 1000000)
 #define RUSAGE_SELF 0
 
+#define F_OK    0
+#define X_OK    1
+#define R_OK    4
+#define W_OK    2
+
 typedef int pid_t;
 
 extern pid_t _getpid(void);
--- a/include/bits/linux/sys.h
+++ b/include/bits/linux/sys.h
@@ -11,6 +11,11 @@
 #define CLOCKS_PER_SEC ((clock_t) 1000000)
 #define RUSAGE_SELF 0
 
+#define F_OK    0
+#define X_OK    1
+#define R_OK    4
+#define W_OK    2
+
 typedef int pid_t;
 
 struct sigaction;
--- a/include/bits/netbsd/sys.h
+++ b/include/bits/netbsd/sys.h
@@ -11,6 +11,11 @@
 #define CLOCKS_PER_SEC ((clock_t) 100)
 #define RUSAGE_SELF 0
 
+#define F_OK    0
+#define X_OK    1
+#define R_OK    4
+#define W_OK    2
+
 typedef int pid_t;
 
 extern pid_t _getpid(void);
--- a/include/bits/openbsd/sys.h
+++ b/include/bits/openbsd/sys.h
@@ -11,6 +11,11 @@
 #define CLOCKS_PER_SEC ((clock_t) 100)
 #define RUSAGE_SELF 0
 
+#define F_OK    0
+#define X_OK    1
+#define R_OK    4
+#define W_OK    2
+
 typedef int pid_t;
 
 struct sigaction;
--- a/src/libc/stdio/tmpnam.c
+++ b/src/libc/stdio/tmpnam.c
@@ -1,3 +1,5 @@
+#include <sys.h>
+
 #include <stdio.h>
 #include <string.h>
 
@@ -24,7 +26,8 @@
 		if (*p == '\0')
 			return NULL;
 		++*p;
-		if (_access(buf, 0) != 0)
+
+		if (_access(buf, F_OK) != 0)
 			break;
 	}
 	if (s)