From c196fd8d099c4454bba27aa6bb4bbebda5d41aaa Mon Sep 17 00:00:00 2001
From: cshapiro <cshapiro>
Date: Tue, 31 Jul 2007 10:08:47 +0000
Subject: [PATCH] Replace operating system private errno accessors with a
 common set of errno accessors shared by all ports.  Change the definition of
 UNIX:UNIX-ERRNO so that it always calls down to an accessor function.

---
 code/unix-glibc2.lisp | 15 +++++----------
 code/unix.lisp        | 11 ++---------
 lisp/Darwin-os.c      | 15 +--------------
 lisp/FreeBSD-os.c     | 14 +-------------
 lisp/Linux-os.c       | 10 +---------
 lisp/os-common.c      | 14 +++++++++++++-
 6 files changed, 23 insertions(+), 56 deletions(-)

diff --git a/code/unix-glibc2.lisp b/code/unix-glibc2.lisp
index e0af64cc4..41408c4d5 100644
--- a/code/unix-glibc2.lisp
+++ b/code/unix-glibc2.lisp
@@ -5,7 +5,7 @@
 ;;; Carnegie Mellon University, and has been placed in the public domain.
 ;;;
 (ext:file-comment
-  "$Header: /Volumes/share2/src/cmucl/cvs2git/cvsroot/src/code/unix-glibc2.lisp,v 1.37 2007/04/07 15:05:52 rtoy Exp $")
+  "$Header: /Volumes/share2/src/cmucl/cvs2git/cvsroot/src/code/unix-glibc2.lisp,v 1.38 2007/07/31 10:08:47 cshapiro Exp $")
 ;;;
 ;;; **********************************************************************
 ;;;
@@ -324,13 +324,11 @@
 
 
 ;;;; System calls.
-(def-alien-variable ("errno" unix-internal-errno) int)
 
-;;; later...
-(defun unix-get-errno ())
-
-(defun unix-errno () (unix-get-errno) unix-internal-errno)
-(defun (setf unix-errno) (newvalue) (setf unix-internal-errno newvalue))
+(def-alien-routine ("os_get_errno" unix-get-errno) int)
+(def-alien-routine ("os_set_errno" unix-set-errno) int (newvalue int))
+(defun unix-errno () (unix-get-errno))
+(defun (setf unix-errno) (newvalue) (unix-set-errno newvalue))
 
 ;;; GET-UNIX-ERROR-MSG -- public.
 ;;; 
@@ -371,9 +369,6 @@
 (defmacro int-syscall ((name &rest arg-types) &rest args)
   `(syscall (,name ,@arg-types) (values result 0) ,@args))
 
-(defun unix-get-errno ()
-  "Get the unix errno value in errno..."
-  (void-syscall ("update_errno")))
 ;;; From stdio.h
 
 ;;; Unix-rename accepts two files names and renames the first to the second.
diff --git a/code/unix.lisp b/code/unix.lisp
index 630661b4c..a624d787b 100644
--- a/code/unix.lisp
+++ b/code/unix.lisp
@@ -5,7 +5,7 @@
 ;;; Carnegie Mellon University, and has been placed in the public domain.
 ;;;
 (ext:file-comment
-  "$Header: /Volumes/share2/src/cmucl/cvs2git/cvsroot/src/code/unix.lisp,v 1.112 2007/07/30 06:44:19 cshapiro Exp $")
+  "$Header: /Volumes/share2/src/cmucl/cvs2git/cvsroot/src/code/unix.lisp,v 1.113 2007/07/31 10:08:47 cshapiro Exp $")
 ;;;
 ;;; **********************************************************************
 ;;;
@@ -912,17 +912,10 @@
 ;;; And now for something completely different ...
 (emit-unix-errors)
 
-#-bsd
-(progn
-(def-alien-variable ("errno" unix-internal-errno) int)
-(defun unix-errno () unix-internal-errno)
-(defun (setf unix-errno) (newvalue) (setf unix-internal-errno newvalue)))
-#+bsd
-(progn
 (def-alien-routine ("os_get_errno" unix-get-errno) int)
 (def-alien-routine ("os_set_errno" unix-set-errno) int (newvalue int))
 (defun unix-errno () (unix-get-errno))
-(defun (setf unix-errno) (newvalue) (unix-set-errno newvalue)))
+(defun (setf unix-errno) (newvalue) (unix-set-errno newvalue))
 
 ;;; GET-UNIX-ERROR-MSG -- public.
 ;;; 
diff --git a/lisp/Darwin-os.c b/lisp/Darwin-os.c
index f9f08da12..e51b539be 100644
--- a/lisp/Darwin-os.c
+++ b/lisp/Darwin-os.c
@@ -14,7 +14,7 @@
  * Frobbed for OpenBSD by Pierre R. Mai, 2001.
  * Frobbed for Darwin by Pierre R. Mai, 2003.
  *
- * $Header: /Volumes/share2/src/cmucl/cvs2git/cvsroot/src/lisp/Darwin-os.c,v 1.10 2007/07/15 21:33:13 cshapiro Exp $
+ * $Header: /Volumes/share2/src/cmucl/cvs2git/cvsroot/src/lisp/Darwin-os.c,v 1.11 2007/07/31 10:08:47 cshapiro Exp $
  *
  */
 
@@ -109,19 +109,6 @@ os_init(void)
 #endif
 }
 
-int
-os_get_errno(void)
-{
-    return errno;
-}
-
-int
-os_set_errno(int newvalue)
-{
-    errno = newvalue;
-    return errno;
-}
-
 #if defined(__ppc__)
 int *
 sc_reg(os_context_t * context, int offset)
diff --git a/lisp/FreeBSD-os.c b/lisp/FreeBSD-os.c
index eee8ab966..e48fb64c8 100644
--- a/lisp/FreeBSD-os.c
+++ b/lisp/FreeBSD-os.c
@@ -12,7 +12,7 @@
  * Much hacked by Paul Werkowski
  * GENCGC support by Douglas Crosher, 1996, 1997.
  *
- * $Header: /Volumes/share2/src/cmucl/cvs2git/cvsroot/src/lisp/FreeBSD-os.c,v 1.19 2007/07/30 07:24:46 cshapiro Exp $
+ * $Header: /Volumes/share2/src/cmucl/cvs2git/cvsroot/src/lisp/FreeBSD-os.c,v 1.20 2007/07/31 10:08:47 cshapiro Exp $
  *
  */
 
@@ -44,18 +44,6 @@ os_init(void)
     os_vm_page_size = getpagesize();
 }
 
-int
-os_get_errno(void)
-{
-    return errno;
-}
-
-int
-os_set_errno(int value)
-{
-    return errno = value;
-}
-
 int *
 sc_reg(ucontext_t *context, int offset)
 {
diff --git a/lisp/Linux-os.c b/lisp/Linux-os.c
index 1f8b75fa0..38990defb 100644
--- a/lisp/Linux-os.c
+++ b/lisp/Linux-os.c
@@ -15,7 +15,7 @@
  * GENCGC support by Douglas Crosher, 1996, 1997.
  * Alpha support by Julian Dolby, 1999.
  *
- * $Header: /Volumes/share2/src/cmucl/cvs2git/cvsroot/src/lisp/Linux-os.c,v 1.32 2007/07/30 07:24:46 cshapiro Exp $
+ * $Header: /Volumes/share2/src/cmucl/cvs2git/cvsroot/src/lisp/Linux-os.c,v 1.33 2007/07/31 10:08:47 cshapiro Exp $
  *
  */
 
@@ -54,14 +54,6 @@ size_t os_vm_page_size;
 #if defined GENCGC
 #include "gencgc.h"
 #endif
-
-int PVE_stub_errno;
-
-void
-update_errno(void)
-{
-    PVE_stub_errno = errno;
-}
 
 
 void
diff --git a/lisp/os-common.c b/lisp/os-common.c
index f76083f02..e1f90ba9b 100644
--- a/lisp/os-common.c
+++ b/lisp/os-common.c
@@ -1,6 +1,6 @@
 /*
 
- $Header: /Volumes/share2/src/cmucl/cvs2git/cvsroot/src/lisp/os-common.c,v 1.22 2007/07/06 08:04:39 cshapiro Exp $
+ $Header: /Volumes/share2/src/cmucl/cvs2git/cvsroot/src/lisp/os-common.c,v 1.23 2007/07/31 10:08:47 cshapiro Exp $
 
  This code was written as part of the CMU Common Lisp project at
  Carnegie Mellon University, and has been placed in the public domain.
@@ -113,6 +113,18 @@ os_reallocate(os_vm_address_t addr, os_vm_size_t old_len, os_vm_size_t len)
     }
 }
 
+int
+os_get_errno(void)
+{
+    return errno;
+}
+
+int
+os_set_errno(int value)
+{
+    return errno = value;
+}
+
 #ifdef LINKAGE_TABLE
 
 /* These declarations are lies.  They actually take args, but are
-- 
GitLab