Subject: Patch to add _Exit()
To: None <tech-userlevel@netbsd.org>
From: Ben Harris <bjh21@netbsd.org>
List: tech-userlevel
Date: 04/23/2002 16:07:33
Starting at the beginning of the shiny new IEEE Std 1003.1-2001, the first
function we don't implement is _Exit(), which is apparently from C99.
Since it's just an alias for _exit(), this looks pretty simple, but it's
rather outside my area, so could someone cast an eye over this and tell me
what I've got wrong?

I haven't put the declaration in <stdlib.h> inside any feature-test macros
because _Exit() seems to be in the implementation namespace already, at
least for POSIX.  I haven't got a copy of C89 handy to check against,
though.

Index: include/stdlib.h
===================================================================
RCS file: /cvsroot/basesrc/include/stdlib.h,v
retrieving revision 1.55
diff -u -r1.55 stdlib.h
--- include/stdlib.h	2001/03/28 11:12:19	1.55
+++ include/stdlib.h	2002/04/23 15:05:35
@@ -99,6 +99,7 @@
 #define	MB_CUR_MAX	__mb_cur_max

 __BEGIN_DECLS
+__dead	 void _Exit __P((int)) __attribute__((__noreturn__));
 __dead	 void abort __P((void)) __attribute__((__noreturn__));
 __pure	 int abs __P((int));
 int	 atexit __P((void (*)(void)));
Index: lib/libc/stdlib/Makefile.inc
===================================================================
RCS file: /cvsroot/basesrc/lib/libc/stdlib/Makefile.inc,v
retrieving revision 1.52
diff -u -r1.52 Makefile.inc
--- lib/libc/stdlib/Makefile.inc	2001/04/28 15:41:30	1.52
+++ lib/libc/stdlib/Makefile.inc	2002/04/23 15:05:35
@@ -4,7 +4,7 @@
 # stdlib sources
 .PATH: ${ARCHDIR}/stdlib ${.CURDIR}/stdlib

-SRCS+=	_rand48.c _strtoimax.c _strtoumax.c _strtoll.c _strtoull.c \
+SRCS+=	_Exit.c _rand48.c _strtoimax.c _strtoumax.c _strtoll.c _strtoull.c \
 	a64l.c abort.c atexit.c atof.c atoi.c atol.c atoll.c \
 	bsearch.c calloc.c drand48.c erand48.c exit.c \
 	getenv.c getopt.c getopt_long.c getsubopt.c \
Index: lib/libc/stdlib/_Exit.c
===================================================================
RCS file: _Exit.c
diff -N _Exit.c
--- /dev/null	Tue Apr 23 18:05:34 2002
+++ _Exit.c	Tue Apr 23 18:05:35 2002
@@ -0,0 +1,21 @@
+/*	$NetBSD$	*/
+
+/*
+ * Ben Harris, 2002
+ * This file is in the Public Domain
+ */
+
+#include <stdlib.h>
+#include <unistd.h>
+
+/*
+ * IEEE 1003.1-2001 says:
+ * The _Exit() and _exit() functions shall be functionally equivalent.
+ */
+
+void
+_Exit(int status)
+{
+
+	_exit(status);
+}
Index: lib/libc/sys/Makefile.inc
===================================================================
RCS file: /cvsroot/basesrc/lib/libc/sys/Makefile.inc,v
retrieving revision 1.124
diff -u -r1.124 Makefile.inc
--- lib/libc/sys/Makefile.inc	2002/01/29 19:01:18	1.124
+++ lib/libc/sys/Makefile.inc	2002/04/23 15:05:35
@@ -132,6 +132,7 @@
 	sync.2 sysarch.2 syscall.2 truncate.2 umask.2 undelete.2 \
 	unlink.2 utimes.2 utrace.2 vfork.2 wait.2 write.2

+MLINKS+=_exit.2 _Exit.2
 MLINKS+=brk.2 sbrk.2
 MLINKS+=clone.2 __clone.2
 MLINKS+=dup.2 dup2.2
Index: lib/libc/sys/_exit.2
===================================================================
RCS file: /cvsroot/basesrc/lib/libc/sys/_exit.2,v
retrieving revision 1.13
diff -u -r1.13 _exit.2
--- lib/libc/sys/_exit.2	2002/02/08 01:28:15	1.13
+++ lib/libc/sys/_exit.2	2002/04/23 15:05:35
@@ -37,18 +37,24 @@
 .Dt EXIT 2
 .Os
 .Sh NAME
-.Nm _exit
+.Nm _Exit, _exit
 .Nd terminate the calling process
 .Sh LIBRARY
 .Lb libc
 .Sh SYNOPSIS
+.Fd #include \*[Lt]stdlib.h\*[Gt]
+.Ft void
+.Fn _Exit "int status"
 .Fd #include \*[Lt]unistd.h\*[Gt]
 .Ft void
 .Fn _exit "int status"
 .Sh DESCRIPTION
 The
+.Fn _Exit
+and
 .Fn _exit
-function terminates a process with the following consequences:
+functions are equivalent.
+They each terminate a process with the following consequences:
 .Bl -bullet
 .It
 All of the descriptors open in the calling process are closed.
@@ -101,6 +107,8 @@
 calling
 .Fn _exit .
 .Sh RETURN VALUES
+.Fn _Exit
+and
 .Fn _exit
 can never return.
 .Sh SEE ALSO
@@ -113,3 +121,7 @@
 .Fn _exit
 function conforms to
 .St -p1003.1-90 .
+The
+.Fn _Exit
+function conforms to
+.St -isoC99 .

-- 
Ben Harris                                                   <bjh21@netbsd.org>
Portmaster, NetBSD/acorn26           <URL:http://www.netbsd.org/Ports/acorn26/>