[uClibc-cvs] uClibc/libc/sysdeps/linux/common syscalls.c, 1.118, 1.119

Erik Andersen andersen at uclibc.org
Sat Nov 8 06:33:40 UTC 2003


Update of /var/cvs/uClibc/libc/sysdeps/linux/common
In directory winder:/tmp/cvs-serv5912/libc/sysdeps/linux/common

Modified Files:
	syscalls.c 
Log Message:
Fix up several errors related to filename length and errno that 
showed up while running the latest LTP testsuite.
 -Erik


Index: syscalls.c
===================================================================
RCS file: /var/cvs/uClibc/libc/sysdeps/linux/common/syscalls.c,v
retrieving revision 1.118
retrieving revision 1.119
diff -u -d -r1.118 -r1.119
--- syscalls.c	2 Nov 2003 10:00:45 -0000	1.118
+++ syscalls.c	8 Nov 2003 06:33:36 -0000	1.119
@@ -78,23 +78,38 @@
 //#define __NR_open             5
 #ifdef L___syscall_open
 #define __NR___syscall_open __NR_open
+#include <stdlib.h>
 #include <stdarg.h>
 #include <fcntl.h>
+#include <string.h>
+#include <sys/param.h>
 static inline
-_syscall3(int, __syscall_open, const char *, fn, int, flags, __kernel_mode_t, mode);
-int __libc_open (const char * fn, int flags, ...)
+_syscall3(int, __syscall_open, const char *, file, int, flags, __kernel_mode_t, mode);
+int __libc_open (const char * file, int flags, ...)
 {
 	mode_t mode;
+	if (unlikely(file==NULL || *file=='\0')) {
+		__set_errno(EINVAL);
+		return -1;
+	}
+	if (unlikely(((strlen(file)+1) > NAME_MAX))) {
+		__set_errno(ENAMETOOLONG);
+		return -1;
+	}
 	if (flags & O_CREAT) {
 		va_list ap;
 		va_start(ap, flags);
 		mode = va_arg(ap, mode_t);
 		va_end(ap);
 	}
-	return __syscall_open(fn, flags, mode);
+	return __syscall_open(file, flags, mode);
 }
-
 weak_alias(__libc_open, open)
+
+int creat(const char *file, mode_t mode)
+{
+	  return __libc_open (file, O_WRONLY|O_CREAT|O_TRUNC, mode);
+}
 #endif
 
 //#define __NR_close            6
@@ -109,23 +124,7 @@
 // Implemented using wait4 
 
 //#define __NR_creat            8
-#ifdef L___syscall_creat
-#include <fcntl.h>
-#ifdef __NR_creat
-#define __NR___syscall_creat __NR_creat
-_syscall2(int, __syscall_creat, const char *, file, __kernel_mode_t, mode);
-int creat (const char *file, mode_t mode)
-{
-	return __syscall_creat (file, mode);
-}
-#else
-extern int __libc_open (const char *file, int flags, mode_t mode);
-int creat (const char *file, mode_t mode)
-{
-	  return __libc_open (file, O_WRONLY|O_CREAT|O_TRUNC, mode);
-}
-#endif
-#endif
+// Implemented using open
 
 //#define __NR_link             9
 #ifdef L_link
@@ -140,16 +139,47 @@
 #endif
 
 //#define __NR_execve           11
-#ifdef L_execve
+#ifdef L___syscall_execve
+#define __NR___syscall_execve __NR_execve
 #include <unistd.h>
-_syscall3(int, execve, const char *, filename, char *const *, argv,
-		  char *const *, envp);
+#include <string.h>
+#include <sys/param.h>
+static inline
+_syscall3(int, __syscall_execve, const char *, filename, 
+		char *const *, argv, char *const *, envp);
+int execve(const char *filename, char *const *argv, char *const *envp)
+{ 
+	if (unlikely(filename==NULL || *filename=='\0')) {
+		__set_errno(EINVAL);
+		return -1;
+	}
+	if (unlikely(((strlen(filename)+1) > NAME_MAX))) {
+		__set_errno(ENAMETOOLONG);
+		return -1;
+	}
+	return __syscall_execve(filename, argv, envp);
+}
 #endif
 
 //#define __NR_chdir            12
-#ifdef L_chdir
-#include <unistd.h>
-_syscall1(int, chdir, const char *, path);
+#ifdef L___syscall_chdir
+#define __NR___syscall_chdir __NR_chdir
+#include <string.h>
+#include <sys/param.h>
+static inline
+_syscall1(int, __syscall_chdir, const char *, path);
+int chdir(const char *path)
+{ 
+	if (unlikely(path==NULL || *path=='\0')) {
+		__set_errno(EINVAL);
+		return -1;
+	}
+	if (unlikely(((strlen(path)+1) > NAME_MAX))) {
+		__set_errno(ENAMETOOLONG);
+		return -1;
+	}
+	return __syscall_chdir(path);
+}
 #endif
 
 //#define __NR_time             13
@@ -471,9 +501,30 @@
 #endif
 
 //#define __NR_rename           38
-#ifdef L_rename
+#ifdef L___syscall_rename
+#define __NR___syscall_rename __NR_rename
+#include <unistd.h>
+#include <string.h>
+#include <sys/param.h>
 #include <stdio.h>
-_syscall2(int, rename, const char *, oldpath, const char *, newpath);
+static inline
+_syscall2(int, __syscall_rename, const char *, oldpath, const char *, newpath);
+int rename(const char *oldpath, const char *newpath)
+{ 
+	if (unlikely((oldpath==NULL || newpath==NULL ||
+					*oldpath=='\0' || *newpath=='\0'))) 
+	{
+		__set_errno(EINVAL);
+		return -1;
+	}
+	if (unlikely(((strlen(oldpath)+1) >= NAME_MAX) || 
+				((strlen(newpath)+1) >= NAME_MAX))) 
+	{
+		__set_errno(ENAMETOOLONG);
+		return -1;
+	}
+	return __syscall_rename(oldpath, newpath);
+}
 #endif
 
 //#define __NR_mkdir            39
@@ -682,9 +733,25 @@
 #endif
 
 //#define __NR_chroot           61
-#ifdef L_chroot
+#ifdef L___syscall_chroot
+#define __NR___syscall_chroot __NR_chroot
 #include <unistd.h>
-_syscall1(int, chroot, const char *, path);
+#include <string.h>
+#include <sys/param.h>
+static inline
+_syscall1(int, __syscall_chroot, const char *, path);
+int chroot(const char *path)
+{ 
+	if (unlikely(path==NULL || *path=='\0')) {
+		__set_errno(EINVAL);
+		return -1;
+	}
+	if (unlikely(((strlen(path)+1) > NAME_MAX))) {
+		__set_errno(ENAMETOOLONG);
+		return -1;
+	}
+	return __syscall_chroot(path);
+}
 #endif
 
 //#define __NR_ustat            62
@@ -1099,9 +1166,25 @@
 //#define __NR_profil           98
 
 //#define __NR_statfs           99
-#ifdef L_statfs
+#ifdef L___syscall_statfs
+#define __NR___syscall_statfs __NR_statfs
+#include <string.h>
+#include <sys/param.h>
 #include <sys/vfs.h>
-_syscall2(int, statfs, const char *, path, struct statfs *, buf);
+static inline
+_syscall2(int, __syscall_statfs, const char *, path, struct statfs *, buf);
+int statfs(const char *path, struct statfs *buf)
+{ 
+	if (unlikely(path==NULL || *path=='\0')) {
+		__set_errno(EINVAL);
+		return -1;
+	}
+	if (unlikely(((strlen(path)+1) > NAME_MAX))) {
+		__set_errno(ENAMETOOLONG);
+		return -1;
+	}
+	return __syscall_statfs(path, buf);
+}
 #endif
 
 //#define __NR_fstatfs          100
@@ -1411,6 +1494,8 @@
 #endif
 
 //#define __NR_sysfs            135
+//_syscall3(int, sysfs, int, option, unsigned int, index, char addr);
+
 
 //#define __NR_personality      136
 #ifdef __NR_personality




More information about the uClibc-cvs mailing list