Browse Source

Fix include/errno.h to not use kernel header, and instead use bits/errno.h.
This required we use _LIBC instead of __LIBC__ to be consistent with glibc.
This had some sideffects in sys/syscalls.h. While fixing things, I made
everything use __set_errno() for (eventual) thread support.
-Erik

Eric Andersen 23 years ago
parent
commit
6278781655
61 changed files with 176 additions and 109 deletions
  1. 1 1
      Rules.mak
  2. 6 3
      include/errno.h
  3. 1 1
      include/features.h
  4. 1 1
      include/grp.h
  5. 1 1
      include/pwd.h
  6. 1 1
      include/utmp.h
  7. 1 1
      libc/inet/hostid.c
  8. 2 2
      libc/inet/rpc/bindresvport.c
  9. 2 2
      libc/misc/dirent/closedir.c
  10. 1 1
      libc/misc/dirent/dirfd.c
  11. 3 3
      libc/misc/dirent/opendir.c
  12. 3 3
      libc/misc/dirent/readdir.c
  13. 1 1
      libc/misc/dirent/rewinddir.c
  14. 1 1
      libc/misc/dirent/seekdir.c
  15. 2 2
      libc/misc/dirent/telldir.c
  16. 1 1
      libc/misc/internals/__uClibc_main.c
  17. 1 1
      libc/misc/lock/flock.c
  18. 3 0
      libc/misc/regex/regex.c
  19. 1 1
      libc/misc/syslog/syslog.c
  20. 1 1
      libc/misc/time/adjtime.c
  21. 1 1
      libc/pwd_grp/fgetgrent.c
  22. 1 1
      libc/pwd_grp/fgetpwent.c
  23. 1 1
      libc/pwd_grp/getgrnam.c
  24. 2 2
      libc/pwd_grp/getpw.c
  25. 1 1
      libc/pwd_grp/getpwnam.c
  26. 1 1
      libc/pwd_grp/putpwent.c
  27. 1 1
      libc/signal/sigaddset.c
  28. 1 1
      libc/signal/sigdelset.c
  29. 1 1
      libc/signal/sigemptyset.c
  30. 1 1
      libc/signal/sigfillset.c
  31. 1 1
      libc/signal/sigismem.c
  32. 3 3
      libc/stdio/getdelim.c
  33. 1 1
      libc/stdio/popen.c
  34. 1 1
      libc/stdio/remove.c
  35. 7 7
      libc/stdio/stdio.c
  36. 1 1
      libc/stdlib/atexit.c
  37. 2 2
      libc/stdlib/mkstemp.c
  38. 2 2
      libc/stdlib/mktemp.c
  39. 4 4
      libc/stdlib/realpath.c
  40. 1 1
      libc/stdlib/setenv.c
  41. 3 3
      libc/stdlib/strto_l.c
  42. 3 3
      libc/stdlib/strto_ll.c
  43. 1 1
      libc/stdlib/strtod.c
  44. 2 2
      libc/string/config.c
  45. 60 0
      libc/sysdeps/linux/arm/bits/errno.h
  46. 1 1
      libc/sysdeps/linux/common/create_module.c
  47. 1 0
      libc/sysdeps/linux/common/errno.c
  48. 2 2
      libc/sysdeps/linux/common/getdnnm.c
  49. 2 2
      libc/sysdeps/linux/common/gethstnm.c
  50. 1 1
      libc/sysdeps/linux/common/seteuid.c
  51. 1 1
      libc/sysdeps/linux/common/syscalls.c
  52. 3 3
      libc/sysdeps/linux/i386/__init_brk.c
  53. 3 3
      libc/sysdeps/linux/i386/brk.c
  54. 3 3
      libc/sysdeps/linux/i386/sbrk.c
  55. 2 2
      libc/sysdeps/linux/m68k/ptrace.c
  56. 2 2
      libc/termios/tcgetsid.c
  57. 3 3
      libc/termios/tcsetattr.c
  58. 3 3
      libc/termios/termios.c
  59. 3 3
      libc/termios/ttyname.c
  60. 5 5
      libc/unistd/getcwd.c
  61. 4 4
      libc/unistd/sysconf.c

+ 1 - 1
Rules.mak

@@ -34,7 +34,7 @@ endif
 
 ARFLAGS=r
 
-CCFLAGS=$(WARNINGS) $(OPTIMIZATION) -fno-builtin -nostdinc $(CPUFLAGS) -I$(TOPDIR)include -I$(GCCINCDIR) -I. -D__LIBC__
+CCFLAGS=$(WARNINGS) $(OPTIMIZATION) -fno-builtin -nostdinc $(CPUFLAGS) -I$(TOPDIR)include -I$(GCCINCDIR) -I. -D_LIBC
 
 CFLAGS=$(ARCH_CFLAGS) $(CCFLAGS) $(DEFS) $(ARCH_CFLAGS2)
 

+ 6 - 3
include/errno.h

@@ -1,8 +1,8 @@
-#ifndef __ERRNO_H
-#define __ERRNO_H
+#ifndef _ERRNO_H
+#define _ERRNO_H
 
 #include <features.h>
-#include <linux/errno.h>
+#include <bits/errno.h>
 
 extern int sys_nerr;
 extern const char *const sys_errlist[];
@@ -10,8 +10,11 @@ extern const char *const sys_errlist[];
 #define _sys_nerr sys_nerr
 #define _sys_errlist sys_errlist
 
+#ifndef	errno
 extern int	errno;
+#endif
 extern void	perror __P ((__const char* __s));
 extern char*	strerror __P ((int __errno));
 
+
 #endif

+ 1 - 1
include/features.h

@@ -15,7 +15,7 @@
  *  their developers intended.  This is IMHO, pardonable, since these defines
  *  are not really intended to check for the presence of a particular library,
  *  but rather are used to define an _interface_.  */
-#if !defined __LIBC__ || defined __FORCE_GLIBC__ 
+#if !defined _LIBC || defined __FORCE_GLIBC__ 
 #   define __GNU_LIBRARY__ 6
 #   define __GLIBC__       2
 #   define __GLIBC_MINOR__ 1

+ 1 - 1
include/grp.h

@@ -27,7 +27,7 @@ extern int setgroups __P ((size_t n, __const gid_t * groups));
 extern int initgroups __P ((__const char * user, gid_t gid));
 
 
-#ifdef __LIBC__
+#ifdef _LIBC
 extern struct group * __getgrent __P ((int grp_fd));
 #endif
 

+ 1 - 1
include/pwd.h

@@ -47,7 +47,7 @@ extern int fgetpwent_r __P ((FILE *__restrict __stream,
 			     char *__restrict __buffer, size_t __buflen,
 			     struct passwd **__restrict __result));
 
-#ifdef __LIBC__
+#ifdef _LIBC
 /* This is used internally to uClibc */
 extern int __getpwent_r(struct passwd * passwd, char * line_buff, 
 	size_t buflen, int pwd_fd);

+ 1 - 1
include/utmp.h

@@ -45,7 +45,7 @@ extern struct utmp *    getutline __P ((struct utmp *));
 extern struct utmp *    pututline __P ((struct utmp *));
 extern void             endutent __P ((void));
 
-#ifdef __LIBC__
+#ifdef _LIBC
 struct utmp *           __getutent __P ((int));
 #endif
 

+ 1 - 1
libc/inet/hostid.c

@@ -17,7 +17,7 @@ int sethostid(long int new_id)
 	int fd;
 	int ret;
 
-	if (geteuid() || getuid()) return errno=EPERM;
+	if (geteuid() || getuid()) return __set_errno(EPERM);
 	if ((fd=open(HOSTID,O_CREAT|O_WRONLY,0644))<0) return -1;
 	ret = write(fd,(void *)&new_id,sizeof(new_id)) == sizeof(new_id)
 		? 0 : -1;

+ 2 - 2
libc/inet/rpc/bindresvport.c

@@ -62,14 +62,14 @@ struct sockaddr_in *sin;
 		bzero(sin, sizeof(*sin));
 		sin->sin_family = AF_INET;
 	} else if (sin->sin_family != AF_INET) {
-		errno = EPFNOSUPPORT;
+		__set_errno(EPFNOSUPPORT);
 		return (-1);
 	}
 	if (port == 0) {
 		port = (getpid() % NPORTS) + STARTPORT;
 	}
 	res = -1;
-	errno = EADDRINUSE;
+	__set_errno(EADDRINUSE);
 	for (i = 0; i < NPORTS && res < 0 && errno == EADDRINUSE; i++) {
 		sin->sin_port = htons(port++);
 		if (port > ENDPORT) {

+ 2 - 2
libc/misc/dirent/closedir.c

@@ -9,13 +9,13 @@ int closedir(DIR * dir)
 	int fd;
 
 	if (!dir) {
-		errno = EBADF;
+		__set_errno(EBADF);
 		return -1;
 	}
 
 	/* We need to check dd_fd. */
 	if (dir->dd_fd == -1) {
-		errno = EBADF;
+		__set_errno(EBADF);
 		return -1;
 	}
 	fd = dir->dd_fd;

+ 1 - 1
libc/misc/dirent/dirfd.c

@@ -4,7 +4,7 @@
 int dirfd(DIR * dir)
 {
 	if (!dir || dir->dd_fd == -1) {
-		errno = EBADF;
+		__set_errno(EBADF);
 		return -1;
 	}
 

+ 3 - 3
libc/misc/dirent/opendir.c

@@ -21,7 +21,7 @@ DIR *opendir(const char *name)
 	if (stat(name, &statbuf))
 		return NULL;
 	if (!S_ISDIR(statbuf.st_mode)) {
-		errno = ENOTDIR;
+		__set_errno(ENOTDIR);
 		return NULL;
 	}
 	if ((fd = open(name, O_RDONLY)) < 0)
@@ -33,7 +33,7 @@ DIR *opendir(const char *name)
 		return NULL;
 	if (!(ptr = malloc(sizeof(*ptr)))) {
 		close(fd);
-		errno = ENOMEM;
+		__set_errno(ENOMEM);
 		return NULL;
 	}
 
@@ -44,7 +44,7 @@ DIR *opendir(const char *name)
 	if (!(buf = malloc(ptr->dd_max))) {
 		close(fd);
 		free(ptr);
-		errno = ENOMEM;
+		__set_errno(ENOMEM);
 		return NULL;
 	}
 	ptr->dd_fd = fd;

+ 3 - 3
libc/misc/dirent/readdir.c

@@ -14,7 +14,7 @@ struct dirent *readdir(DIR * dir)
 	struct dirent *de;
 
 	if (!dir) {
-		errno = EBADF;
+		__set_errno(EBADF);
 		return NULL;
 	}
 
@@ -37,7 +37,7 @@ struct dirent *readdir(DIR * dir)
 					dir->dd_getdents = no_getdents;
 					abort();
 				}
-				errno = result;
+				__set_errno(result);
 			}
 
 			return NULL;
@@ -63,7 +63,7 @@ struct dirent *readdir(DIR * dir)
 	if (strlen((char *) &de->d_type) > 10)
 		de->d_name[10] = 0;
 	strcpy(dir->dd_buf->d_name, (char *) &de->d_name);
-	errno = 0;
+	__set_errno(0);
 
 	return dir->dd_buf;
 }

+ 1 - 1
libc/misc/dirent/rewinddir.c

@@ -7,7 +7,7 @@
 void rewinddir(DIR * dir)
 {
 	if (!dir) {
-		errno = EBADF;
+		__set_errno(EBADF);
 		return;
 	}
 	lseek(dir->dd_fd, 0, SEEK_SET);

+ 1 - 1
libc/misc/dirent/seekdir.c

@@ -6,7 +6,7 @@
 void seekdir(DIR * dir, off_t offset)
 {
 	if (!dir) {
-		errno = EBADF;
+		__set_errno(EBADF);
 		return;
 	}
 	dir->dd_nextoff = lseek(dir->dd_fd, offset, SEEK_SET);

+ 2 - 2
libc/misc/dirent/telldir.c

@@ -8,7 +8,7 @@ off_t telldir(DIR * dir)
 	off_t offset;
 
 	if (!dir) {
-		errno = EBADF;
+		__set_errno(EBADF);
 		return -1;
 	}
 
@@ -27,7 +27,7 @@ off_t telldir(DIR * dir)
 		break;
 
 	default:
-		errno = EBADF;
+		__set_errno(EBADF);
 		offset = -1;
 	}
 

+ 1 - 1
libc/misc/internals/__uClibc_main.c

@@ -64,7 +64,7 @@ void __uClibc_main(int argc, char **argv, char **envp)
 	 * have resulted in errno being set nonzero, so set it to 0 before
 	 * we call main.
 	 */
-	errno = 0;
+	__set_errno(0);
 
 	/*
 	 * Finally, invoke application's main and then exit.

+ 1 - 1
libc/misc/lock/flock.c

@@ -42,7 +42,7 @@ int flock( int fd, int operation)
 		lbuf.l_type = F_UNLCK;
 		break;
 	default:
-		errno = EINVAL;
+		__set_errno(EINVAL);
 		return -1;
 	}
 

+ 3 - 0
libc/misc/regex/regex.c

@@ -19,6 +19,9 @@
    write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
    Boston, MA 02111-1307, USA.  */
 
+/* To exclude some unwanted junk.... */
+#undef _LIBC
+
 /* AIX requires this to be the first thing in the file. */
 #if defined _AIX && !defined REGEX_MALLOC
 #pragma alloca

+ 1 - 1
libc/misc/syslog/syslog.c

@@ -224,7 +224,7 @@ vsyslog( int pri, const char *fmt, va_list ap )
 	 */
 
 	end = tbuf + sizeof(tbuf) - 1;
-	errno = saved_errno;
+	__set_errno(saved_errno);
 	p += vsnprintf(p, end - p, fmt, ap);
 	if (p >= end || p < head_end) {	/* Returned -1 in case of error... */
 		static char truncate_msg[12] = "[truncated] ";

+ 1 - 1
libc/misc/time/adjtime.c

@@ -24,7 +24,7 @@ adjtime(const struct timeval * itv, struct timeval * otv)
     tmp.tv_usec = itv->tv_usec % 1000000L;
     if (tmp.tv_sec > MAX_SEC || tmp.tv_sec < MIN_SEC)
     {
-	errno = EINVAL;
+	__set_errno(EINVAL);
 	return -1;
     }
     tntx.offset = tmp.tv_usec + tmp.tv_sec * 1000000L;

+ 1 - 1
libc/pwd_grp/fgetgrent.c

@@ -25,7 +25,7 @@
 struct group *fgetgrent(FILE * file)
 {
 	if (file == NULL) {
-		errno = EINTR;
+		__set_errno(EINTR);
 		return NULL;
 	}
 

+ 1 - 1
libc/pwd_grp/fgetpwent.c

@@ -32,7 +32,7 @@ int fgetpwent_r (FILE *file, struct passwd *password,
 	char *buff, size_t buflen, struct passwd **crap)
 {
 	if (file == NULL) {
-		errno = EINTR;
+		__set_errno(EINTR);
 		return -1;
 	}
 	return(__getpwent_r(password, buff, buflen, fileno(file)));

+ 1 - 1
libc/pwd_grp/getgrnam.c

@@ -30,7 +30,7 @@ struct group *getgrnam(const char *name)
 	struct group *group;
 
 	if (name == NULL) {
-		errno = EINVAL;
+		__set_errno(EINVAL);
 		return NULL;
 	}
 

+ 2 - 2
libc/pwd_grp/getpw.c

@@ -28,7 +28,7 @@ int getpw(uid_t uid, char *buf)
 	struct passwd *passwd;
 
 	if (buf == NULL) {
-		errno = EINVAL;
+		__set_errno(EINVAL);
 		return -1;
 	}
 	if ((passwd = getpwuid(uid)) == NULL)
@@ -38,7 +38,7 @@ int getpw(uid_t uid, char *buf)
 		(buf, "%s:%s:%u:%u:%s:%s:%s", passwd->pw_name, passwd->pw_passwd,
 		 passwd->pw_gid, passwd->pw_uid, passwd->pw_gecos, passwd->pw_dir,
 		 passwd->pw_shell) < 0) {
-		errno = ENOBUFS;
+		__set_errno(ENOBUFS);
 		return -1;
 	}
 

+ 1 - 1
libc/pwd_grp/getpwnam.c

@@ -38,7 +38,7 @@ int getpwnam_r (const char *name, struct passwd *password,
 	int passwd_fd;
 
 	if (name == NULL) {
-		errno = EINVAL;
+		__set_errno(EINVAL);
 		return -1;
 	}
 

+ 1 - 1
libc/pwd_grp/putpwent.c

@@ -25,7 +25,7 @@
 int putpwent(const struct passwd *passwd, FILE * f)
 {
 	if (passwd == NULL || f == NULL) {
-		errno = EINVAL;
+		__set_errno(EINVAL);
 		return -1;
 	}
 	if (fprintf

+ 1 - 1
libc/signal/sigaddset.c

@@ -25,7 +25,7 @@
 int sigaddset ( sigset_t *set, int signo)
 {
   if (set == NULL || signo <= 0 || signo >= NSIG) {
-      errno = EINVAL;
+      __set_errno(EINVAL);
       return -1;
     }
 

+ 1 - 1
libc/signal/sigdelset.c

@@ -23,7 +23,7 @@
 int sigdelset ( sigset_t *set, int signo)
 {
   if (set == NULL || signo <= 0 || signo >= NSIG) {
-      errno = EINVAL;
+      __set_errno(EINVAL);
       return -1;
     }
 

+ 1 - 1
libc/signal/sigemptyset.c

@@ -25,7 +25,7 @@ int
 sigemptyset ( sigset_t *set)
 {
   if (set == NULL) {
-      errno = EINVAL;
+      __set_errno(EINVAL);
       return -1;
     }
 

+ 1 - 1
libc/signal/sigfillset.c

@@ -27,7 +27,7 @@ sigfillset (set)
 {
   if (set == NULL)
     {
-      errno = EINVAL;
+      __set_errno(EINVAL);
       return -1;
     }
 

+ 1 - 1
libc/signal/sigismem.c

@@ -25,7 +25,7 @@
 int sigismember ( const sigset_t *set, int signo)
 {
   if (set == NULL || signo <= 0 || signo >= NSIG) {
-      errno=EINVAL;
+      __set_errno(EINVAL);
       return -1;
     }
 

+ 3 - 3
libc/stdio/getdelim.c

@@ -43,14 +43,14 @@ ssize_t getdelim(char **linebuf, size_t *linebufsz, int delimiter, FILE *file)
 
 	if ((file == NULL || linebuf==NULL || *linebuf == NULL || *linebufsz == 0)
 			&& !(*linebuf == NULL && *linebufsz ==0 )) {
-	    errno=EINVAL;
+	    __set_errno(EINVAL);
 	    return -1;
 	}
 
 	if (*linebuf == NULL && *linebufsz == 0){
 		*linebuf = malloc(GROWBY);
 		if (!*linebuf) {
-			errno=ENOMEM;
+			__set_errno(ENOMEM);
 			return -1;
 		}
 		*linebufsz += GROWBY;
@@ -64,7 +64,7 @@ ssize_t getdelim(char **linebuf, size_t *linebufsz, int delimiter, FILE *file)
 		while (idx > *linebufsz-2) {
 			*linebuf = realloc(*linebuf, *linebufsz += GROWBY);
 			if (!*linebuf) {
-				errno=ENOMEM;
+				__set_errno(ENOMEM);
 				return -1;
 			}
 		}

+ 1 - 1
libc/stdio/popen.c

@@ -21,7 +21,7 @@ FILE *popen (const char *command, const char *mode)
 
 	reading = (mode[0] == 'r');
 	if ((!reading && (mode[0] != 'w')) || mode[1]) {
-		errno = EINVAL;			/* Invalid mode arg. */
+		__set_errno(EINVAL);			/* Invalid mode arg. */
 	} else if (pipe(pipe_fd) == 0) {
 		pr = pipe_fd[reading];
 		pnr = pipe_fd[1-reading];

+ 1 - 1
libc/stdio/remove.c

@@ -17,7 +17,7 @@ __const char *src;
 	if (rv < 0 && errno == EISDIR)
 		rv = rmdir(src);
 	if (rv >= 0)
-		errno = er;
+		__set_errno(er);
 	return rv;
 }
 

+ 7 - 7
libc/stdio/stdio.c

@@ -279,7 +279,7 @@ int fflush(FILE *fp)
 		 * ANSI says behavior in this case is undefined but also says you
 		 * shouldn't flush a stream you were reading from.
 		 */
-		errno = EBADF;			/* Should we set stream error indicator? */
+		__set_errno(EBADF);			/* Should we set stream error indicator? */
 		rv = -1;
 	}
 
@@ -560,7 +560,7 @@ int fseek(FILE *fp, long int offset, int ref)
 #endif
 
 	if ((ref < 0) || (ref > 2)) {
-		errno = EINVAL;
+		__set_errno(EINVAL);
 		return -1;
 	}
 
@@ -610,7 +610,7 @@ FILE *fp;
 			--pos;
 		}
 		if (pos < 0) {			/* ungetcs at start of file? */
-			errno = EIO;
+			__set_errno(EIO);
 			pos = -1;
 		}
 	}
@@ -666,7 +666,7 @@ const char *mode;
 			open_mode = (O_WRONLY | O_CREAT | O_APPEND);
 			break;
 		default:				/* illegal mode */
-			errno = EINVAL;
+			__set_errno(EINVAL);
 			goto _fopen_ERROR;
 	}
 
@@ -709,7 +709,7 @@ const char *mode;
 			fd = -1;
 		} else if (!(cur_mode & O_RDWR) 
 				   && ((cur_mode ^ open_mode) & O_ACCMODE)) {
-			errno = EINVAL;
+			__set_errno(EINVAL);
 			fd = -1;
 		}
 	}
@@ -1037,7 +1037,7 @@ int fgetpos(FILE *fp, fpos_t *pos)
 	fpos_t p;
 
 	if (!pos) {					/* NULL pointer. */
-		errno = EINVAL;
+		__set_errno(EINVAL);
 		return -1;
 	}
 
@@ -1056,7 +1056,7 @@ int fsetpos(FILE *fp, __const fpos_t *pos)
 	if (pos) {					/* Pointer ok. */
 		return fseek(fp, *pos, SEEK_SET);
 	}
-	errno = EINVAL;				/* NULL pointer. */
+	__set_errno(EINVAL);				/* NULL pointer. */
 	return EOF;
 }
 #endif

+ 1 - 1
libc/stdlib/atexit.c

@@ -51,7 +51,7 @@ static void atexit_handler(void)
 int atexit(vfuncp ptr)
 {
 	if ((__uClibc_cleanup == 0) || (__atexit_count >= __UCLIBC_MAX_ATEXIT)) {
-		errno = ENOMEM;
+		__set_errno(ENOMEM);
 		return -1;
 	}
 	if (ptr) {

+ 2 - 2
libc/stdlib/mkstemp.c

@@ -13,13 +13,13 @@ char *template;
 	int l = strlen(template);
 
 	if (l < 6) {
-		errno = EINVAL;
+		__set_errno(EINVAL);
 		return -1;
 	}
 
 	for (i = l - 6; i < l; i++)
 		if (template[i] != 'X') {
-			errno = EINVAL;
+			__set_errno(EINVAL);
 			return -1;
 		}
 

+ 2 - 2
libc/stdlib/mktemp.c

@@ -15,13 +15,13 @@ char *template;
 	struct stat stbuf;
 
 	if (l < 6) {
-		errno = EINVAL;
+		__set_errno(EINVAL);
 		return 0;
 	}
 
 	for (i = l - 6; i < l; i++)
 		if (template[i] != 'X') {
-			errno = EINVAL;
+			__set_errno(EINVAL);
 			return 0;
 		}
 

+ 4 - 4
libc/stdlib/realpath.c

@@ -60,7 +60,7 @@ char resolved_path[];
 
 	/* Make a copy of the source path since we may need to modify it. */
 	if (strlen(path) >= PATH_MAX - 2) {
-		errno = ENAMETOOLONG;
+		__set_errno(ENAMETOOLONG);
 		return NULL;
 	}
 	strcpy(copy_path, path);
@@ -110,7 +110,7 @@ char resolved_path[];
 		/* Safely copy the next pathname component. */
 		while (*path != '\0' && *path != '/') {
 			if (path > max_path) {
-				errno = ENAMETOOLONG;
+				__set_errno(ENAMETOOLONG);
 				return NULL;
 			}
 			*new_path++ = *path++;
@@ -118,7 +118,7 @@ char resolved_path[];
 #ifdef S_IFLNK
 		/* Protect against infinite loops. */
 		if (readlinks++ > MAX_READLINKS) {
-			errno = ELOOP;
+			__set_errno(ELOOP);
 			return NULL;
 		}
 		/* See if latest pathname component is a symlink. */
@@ -143,7 +143,7 @@ char resolved_path[];
 				while (*(--new_path) != '/');
 			/* Safe sex check. */
 			if (strlen(path) + n >= PATH_MAX - 2) {
-				errno = ENAMETOOLONG;
+				__set_errno(ENAMETOOLONG);
 				return NULL;
 			}
 			/* Insert symlink contents into path. */

+ 1 - 1
libc/stdlib/setenv.c

@@ -83,7 +83,7 @@ int setenv(const char *name, const char *value, int replace)
       if (new_environ[size] == NULL)
 	{
 	  free (new_environ);
-	  errno = ENOMEM;
+	  __set_errno(ENOMEM);
 	  result = -1;
 	  goto do_return;
 	}

+ 3 - 3
libc/stdlib/strto_l.c

@@ -137,7 +137,7 @@ unsigned long _strto_l(const char *str, char **endptr, int base, int uflag)
 		negative = 0; /* since unsigned returns ULONG_MAX */
 	    }
 #if _STRTO_ERRNO
-	    errno = ERANGE;
+	    __set_errno(ERANGE);
 #endif
 	} else {
 	    number = number * base + digit;
@@ -155,7 +155,7 @@ unsigned long _strto_l(const char *str, char **endptr, int base, int uflag)
     if (negative) {
 	if (!uflag && (number > ((unsigned long)(-(1+LONG_MIN)))+1)) {
 #if _STRTO_ERRNO
-	    errno = ERANGE;
+	    __set_errno(ERANGE);
 #endif
 	    return (unsigned long) LONG_MIN;
 	}
@@ -163,7 +163,7 @@ unsigned long _strto_l(const char *str, char **endptr, int base, int uflag)
     } else {
 	if (!uflag && (number > (unsigned long) LONG_MAX)) {
 #if _STRTO_ERRNO
-	    errno = ERANGE;
+	    __set_errno(ERANGE);
 #endif
 	    return LONG_MAX;
 	}

+ 3 - 3
libc/stdlib/strto_ll.c

@@ -137,7 +137,7 @@ unsigned long long _strto_ll(const char *str, char **endptr, int base, int uflag
 		negative = 0; /* since unsigned returns ULONG_LONG_MAX */
 	    }
 #if _STRTO_ERRNO
-	    errno = ERANGE;
+	    __set_errno(ERANGE);
 #endif
 	} else {
 	    number = number * base + digit;
@@ -155,7 +155,7 @@ unsigned long long _strto_ll(const char *str, char **endptr, int base, int uflag
     if (negative) {
 	if (!uflag && (number > ((unsigned long long)(-(1+LONG_LONG_MIN)))+1)) {
 #if _STRTO_ERRNO
-	    errno = ERANGE;
+	    __set_errno(ERANGE);
 #endif
 	    return (unsigned long long) LONG_LONG_MIN;
 	}
@@ -163,7 +163,7 @@ unsigned long long _strto_ll(const char *str, char **endptr, int base, int uflag
     } else {
 	if (!uflag && (number > (unsigned long long) LONG_LONG_MAX)) {
 #if _STRTO_ERRNO
-	    errno = ERANGE;
+	    __set_errno(ERANGE);
 #endif
 	    return LONG_LONG_MAX;
 	}

+ 1 - 1
libc/stdlib/strtod.c

@@ -248,7 +248,7 @@ double strtod(const char *str, char **endptr)
 
 #if _STRTOD_ERRNO
     if (_zero_or_inf_check(number)) {
-	errno=ERANGE;
+	__set_errno(ERANGE);
     }
 #endif
 

+ 2 - 2
libc/string/config.c

@@ -42,7 +42,7 @@ char **cfgread(FILE * fp)
 	int i;
 
 	if (!fp) {
-		errno = EIO;
+		__set_errno(EIO);
 		return (void *) 0;
 	}
 
@@ -73,7 +73,7 @@ char **cfgfind(FILE * fp, char *var)
 	char search[80];
 
 	if (!fp || !var) {
-		errno = EIO;
+		__set_errno(EIO);
 		return (void *) 0;
 	}
 

+ 60 - 0
libc/sysdeps/linux/arm/bits/errno.h

@@ -0,0 +1,60 @@
+/* Error constants.  Linux specific version.
+   Copyright (C) 1996, 1997, 1998, 1999 Free Software Foundation, Inc.
+   This file is part of the GNU C Library.
+
+   The GNU C Library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Library General Public License as
+   published by the Free Software Foundation; either version 2 of the
+   License, or (at your option) any later version.
+
+   The GNU C Library is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Library General Public License for more details.
+
+   You should have received a copy of the GNU Library General Public
+   License along with the GNU C Library; see the file COPYING.LIB.  If not,
+   write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+   Boston, MA 02111-1307, USA.  */
+
+#ifdef _ERRNO_H
+
+# undef EDOM
+# undef EILSEQ
+# undef ERANGE
+# include <linux/errno.h>
+
+/* Linux has no ENOTSUP error code.  */
+# define ENOTSUP EOPNOTSUPP
+
+/* Linux also has no ECANCELED error code.  Since it is not used here
+   we define it to an invalid value.  */
+# define ECANCELED	125
+
+# ifndef __ASSEMBLER__
+/* We now need a declaration of the `errno' variable.  */
+extern int errno;
+
+/* Function to get address of global `errno' variable.  */
+extern int *__errno_location (void) __THROW __attribute__ ((__const__));
+
+#  if defined _LIBC
+/* We wouldn't need a special macro anymore but it is history.  */
+#   define __set_errno(val) (*__errno_location ()) = (val)
+#  endif /* _LIBC */
+
+#  if !defined _LIBC || defined _LIBC_REENTRANT
+/* When using threads, errno is a per-thread value.  */
+#   define errno (*__errno_location ())
+#  endif
+# endif /* !__ASSEMBLER__ */
+#endif /* _ERRNO_H */
+
+#if !defined _ERRNO_H && defined __need_Emath
+/* This is ugly but the kernel header is not clean enough.  We must
+   define only the values EDOM, EILSEQ and ERANGE in case __need_Emath is
+   defined.  */
+# define EDOM	33	/* Math argument out of domain of function.  */
+# define EILSEQ	84	/* Illegal byte sequence.  */
+# define ERANGE	34	/* Math result not representable.  */
+#endif /* !_ERRNO_H && __need_Emath */

+ 1 - 1
libc/sysdeps/linux/common/create_module.c

@@ -42,7 +42,7 @@ unsigned long create_module(const char *name, size_t size)
 	/* Jump through hoops to fixup error return codes */
 	if (ret == -1 && errno > 125) {
 		ret = -errno;
-		errno = 0;
+		__set_errno(0);
 	}
 	return ret;
 }

+ 1 - 0
libc/sysdeps/linux/common/errno.c

@@ -6,3 +6,4 @@ int * __errno_location ( void )
 {
   return &errno;
 }
+

+ 2 - 2
libc/sysdeps/linux/common/getdnnm.c

@@ -9,14 +9,14 @@ getdomainname(char *name, size_t len)
   struct utsname uts;
 
   if (name == NULL) {
-    errno = EINVAL;
+    __set_errno(EINVAL);
     return -1;
   }
 
   if (uname(&uts) == -1) return -1;
 
   if (strlen(uts.domainname)+1 > len) {
-    errno = EINVAL;
+    __set_errno(EINVAL);
     return -1;
   }
   strcpy(name, uts.domainname);

+ 2 - 2
libc/sysdeps/linux/common/gethstnm.c

@@ -9,14 +9,14 @@ gethostname(char *name, size_t len)
   struct utsname uts;
 
   if (name == NULL) {
-    errno = EINVAL;
+    __set_errno(EINVAL);
     return -1;
   }
 
   if (uname(&uts) == -1) return -1;
 
   if (strlen(uts.nodename)+1 > len) {
-    errno = EINVAL;
+    __set_errno(EINVAL);
     return -1;
   }
   strcpy(name, uts.nodename);

+ 1 - 1
libc/sysdeps/linux/common/seteuid.c

@@ -9,7 +9,7 @@ int seteuid(uid_t uid)
   case 2:
     if (uid == 65535)
     {
-      errno = EINVAL;
+      __set_errno(EINVAL);
       return -1;
     }
     break;

+ 1 - 1
libc/sysdeps/linux/common/syscalls.c

@@ -139,7 +139,7 @@ int _xmknod (int version, const char * path, mode_t mode, dev_t *dev)
 		case 1:
 			return mknod (path, mode, *dev);
 		default:
-			errno = EINVAL;
+			__set_errno(EINVAL);
 			return -1;
 	}
 }

+ 3 - 3
libc/sysdeps/linux/i386/__init_brk.c

@@ -17,15 +17,15 @@ __init_brk ()
 			  "int $0x80\n\t"
 			  "popl %%ebx"
 		:"=a" (___brk_addr)
-		:"0" (SYS_brk));
+		:"0" (__NR_brk));
 #else
 	__asm__ volatile ("int $0x80"
 		:"=a" (___brk_addr)
-		:"0" (SYS_brk),"b" (0));
+		:"0" (__NR_brk),"b" (0));
 #endif
 	if (___brk_addr == 0)
 	{
-	  errno = ENOMEM;
+	  __set_errno(ENOMEM);
 	  return -1;
 	}
     }

+ 3 - 3
libc/sysdeps/linux/i386/brk.c

@@ -18,15 +18,15 @@ int brk(void * end_data_seg)
 			  "int $0x80\n\t"
 			  "popl %%ebx"
 		:"=a" (___brk_addr)
-		:"0" (SYS_brk),"c" (end_data_seg));
+		:"0" (__NR_brk),"c" (end_data_seg));
 #else
 	__asm__ volatile ("int $0x80"
 		:"=a" (___brk_addr)
-		:"0" (SYS_brk),"b" (end_data_seg));
+		:"0" (__NR_brk),"b" (end_data_seg));
 #endif
 	if (___brk_addr == end_data_seg)
 		return 0;
-	errno = ENOMEM;
+	__set_errno(ENOMEM);
     }
     return -1;
 }

+ 3 - 3
libc/sysdeps/linux/i386/sbrk.c

@@ -20,15 +20,15 @@ sbrk(ptrdiff_t increment)
                           "int $0x80\n\t"
                           "popl %%ebx"
 		:"=a" (___brk_addr)
-		:"0" (SYS_brk),"c" (tmp));
+		:"0" (__NR_brk),"c" (tmp));
 #else
 	__asm__ volatile ("int $0x80"
 		:"=a" (___brk_addr)
-		:"0" (SYS_brk),"b" (tmp));
+		:"0" (__NR_brk),"b" (tmp));
 #endif
 	if (___brk_addr == tmp)
 		return tmp-increment;
-	errno = ENOMEM;
+	__set_errno(ENOMEM);
 	return ((void *) -1);
     }
     return ((void *) -1);

+ 2 - 2
libc/sysdeps/linux/m68k/ptrace.c

@@ -23,11 +23,11 @@ ptrace(int request, int pid, int addr, int data)
 
 	if (res >= 0) {
 		if (request > 0 && request < 4) {
-			errno = 0;
+			__set_errno(0);
 			return (ret);
 		}
 		return (int) res;
 	}
-	errno = -res;
+	__set_errno(-res);
 	return -1;
 }

+ 2 - 2
libc/termios/tcgetsid.c

@@ -42,7 +42,7 @@ pid_t tcgetsid (int fd)
 	    if (errno == EINVAL)
 	    {
 		tiocgsid_does_not_work = 1;
-		errno=serrno;
+		__set_errno(serrno);
 	    }
 	    else
 		return (pid_t) -1;
@@ -58,7 +58,7 @@ pid_t tcgetsid (int fd)
 
     sid = getsid (pgrp);
     if (sid == -1 && errno == ESRCH)
-	errno=ENOTTY;
+	__set_errno(ENOTTY);
 
     return sid;
 }

+ 3 - 3
libc/termios/tcsetattr.c

@@ -69,7 +69,7 @@ tcsetattr (fd, optional_actions, termios_p)
       cmd = TCSETSF;
       break;
     default:
-      errno=EINVAL;
+      __set_errno(EINVAL);
       return -1;
     }
 
@@ -99,7 +99,7 @@ tcsetattr (fd, optional_actions, termios_p)
 	{
 	  /* We cannot verify if the setting is ok. We don't return
 	     an error (?). */
-	  errno=save;
+	  __set_errno(save);
 	  retval = 0;
 	}
       else if ((termios_p->c_cflag & (PARENB | CREAD))
@@ -111,7 +111,7 @@ tcsetattr (fd, optional_actions, termios_p)
 	  /* It looks like the Linux kernel silently changed the
 	     PARENB/CREAD/CSIZE bits in c_cflag. Report it as an
 	     error. */
-	  errno=EINVAL;
+	  __set_errno(EINVAL);
 	  retval = -1;
 	}
     }

+ 3 - 3
libc/termios/termios.c

@@ -88,7 +88,7 @@ int tcsendbreak( int fd, int duration)
 	 * changed to use trickery (e.g. lower speed and send a '\0') to send
 	 * the break, but for now just return an error.
 	 */
-	errno = EINVAL;
+	__set_errno(EINVAL);
 	return -1;
 }
 #endif
@@ -151,7 +151,7 @@ int cfsetospeed  (struct termios *termios_p, speed_t speed)
     if ((speed & ~CBAUD) != 0
 	    && (speed < B57600 || speed > B460800))
     {
-	errno=EINVAL;
+	__set_errno(EINVAL);
 	return -1;
     }
 
@@ -172,7 +172,7 @@ int cfsetispeed ( struct termios *termios_p, speed_t speed)
     if ((speed & ~CBAUD) != 0
 	    && (speed < B57600 || speed > B460800))
     {
-	errno=EINVAL;
+	__set_errno(EINVAL);
 	return -1;
     }
 

+ 3 - 3
libc/termios/ttyname.c

@@ -17,7 +17,7 @@ int fd;
 	if (fstat(fd, &st) < 0)
 		return 0;
 	if (!isatty(fd)) {
-		errno = ENOTTY;
+		__set_errno(ENOTTY);
 		return 0;
 	}
 
@@ -32,11 +32,11 @@ int fd;
 		if (stat(name, &dst) == 0
 			&& st.st_dev == dst.st_dev && st.st_ino == dst.st_ino) {
 			closedir(fp);
-			errno = noerr;
+			__set_errno(noerr);
 			return name;
 		}
 	}
 	closedir(fp);
-	errno = noerr;
+	__set_errno(noerr);
 	return 0;
 }

+ 5 - 5
libc/unistd/getcwd.c

@@ -21,7 +21,7 @@ char *getcwd( char *buf, int size)
 	path_size = size;
 
 	if (size < 3) {
-		errno = ERANGE;
+		__set_errno(ERANGE);
 		return NULL;
 	}
 
@@ -59,7 +59,7 @@ static char *recurser()
 		return path_buf;
 	}
 	if (strlen(path_buf) + 4 > path_size) {
-		errno = ERANGE;
+		__set_errno(ERANGE);
 		return 0;
 	}
 	strcat(path_buf, "/..");
@@ -90,7 +90,7 @@ ino_t this_ino;
 	ptr = path_buf + slen - 1;
 	if (*ptr != '/') {
 		if (slen + 2 > path_size) {
-			errno = ERANGE;
+			__set_errno(ERANGE);
 			return 0;
 		}
 		strcpy(++ptr, "/");
@@ -105,7 +105,7 @@ ino_t this_ino;
 	while ((d = readdir(dp)) != 0) {
 		if (slow_search || this_ino == d->d_ino) {
 			if (slen + strlen(d->d_name) > path_size) {
-				errno = ERANGE;
+				__set_errno(ERANGE);
 				return 0;
 			}
 			strcpy(ptr + 1, d->d_name);
@@ -119,6 +119,6 @@ ino_t this_ino;
 	}
 
 	closedir(dp);
-	errno = ENOENT;
+	__set_errno(ENOENT);
 	return 0;
 }

+ 4 - 4
libc/unistd/sysconf.c

@@ -52,8 +52,8 @@
  *    a constant.  The pagesize on the target arch should not vary,
  *    so it should be safe to set this as 0.
  */
-#define RETURN_NEG_1 errno = ENOSYS; return -1
-#define RETURN_FUNCTION(f) errno = EISNAM ; return (long int) #f
+#define RETURN_NEG_1 __set_errno(ENOSYS); return -1
+#define RETURN_FUNCTION(f) __set_errno(EISNAM); return (long int) #f
 #define GETPAGESIZE_IS_DYNAMIC 0
 #else
 #define RETURN_NEG_1 return -1
@@ -66,7 +66,7 @@ long int sysconf(int name)
   switch (name)
     {
     default:
-      errno=EINVAL;
+      __set_errno(EINVAL);
       return -1;
 
     case _SC_ARG_MAX:
@@ -935,7 +935,7 @@ int main(void)
 	}
 
 	for (i=0; i<_UCLIBC_SYSCONF_NUM_VALID_ARGS ; i++) {
-		errno = 0;
+		__set_errno(0);
 		r = ret_vals[i] = sysconf(i);
 		switch(errno) {
 			case EINVAL:		/* we're missing a case! */