summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorguenther <>2014-08-15 04:14:36 +0000
committerguenther <>2014-08-15 04:14:36 +0000
commit3851718ce44d5d845cba0e7519642aa1c24624ca (patch)
treead98e89509d81894a7205c6b5bc0cb6747d59cd6 /src
parent1b0c3c7c757651ec07c6eba0d0be4a0966409111 (diff)
downloadopenbsd-3851718ce44d5d845cba0e7519642aa1c24624ca.tar.gz
openbsd-3851718ce44d5d845cba0e7519642aa1c24624ca.tar.bz2
openbsd-3851718ce44d5d845cba0e7519642aa1c24624ca.zip
XPG requires insque() and remque() to work with linear lists and not just
circular lists. Amazingly, they managed to extend the requirements to no longer match the behavior of the VAX instructions they were modeled after, so the trivial VAX ASM versions have to go. Nice job breaking it, X/Open! Based on a diff from enh (at) google.com ok miod@
Diffstat (limited to 'src')
-rw-r--r--src/lib/libc/stdlib/Makefile.inc15
-rw-r--r--src/lib/libc/stdlib/insque.c20
-rw-r--r--src/lib/libc/stdlib/remque.c12
3 files changed, 26 insertions, 21 deletions
diff --git a/src/lib/libc/stdlib/Makefile.inc b/src/lib/libc/stdlib/Makefile.inc
index 80c3e5f5a1..0c0b1499f8 100644
--- a/src/lib/libc/stdlib/Makefile.inc
+++ b/src/lib/libc/stdlib/Makefile.inc
@@ -1,13 +1,14 @@
1# $OpenBSD: Makefile.inc,v 1.53 2014/05/08 21:43:49 deraadt Exp $ 1# $OpenBSD: Makefile.inc,v 1.54 2014/08/15 04:14:36 guenther Exp $
2 2
3# stdlib sources 3# stdlib sources
4.PATH: ${LIBCSRCDIR}/arch/${MACHINE_CPU}/stdlib ${LIBCSRCDIR}/stdlib 4.PATH: ${LIBCSRCDIR}/arch/${MACHINE_CPU}/stdlib ${LIBCSRCDIR}/stdlib
5 5
6SRCS+= a64l.c abort.c atexit.c atoi.c atof.c atol.c atoll.c bsearch.c \ 6SRCS+= a64l.c abort.c atexit.c atoi.c atof.c atol.c atoll.c bsearch.c \
7 cfree.c exit.c ecvt.c gcvt.c getenv.c getopt_long.c \ 7 cfree.c exit.c ecvt.c gcvt.c getenv.c getopt_long.c \
8 getsubopt.c hcreate.c heapsort.c imaxabs.c imaxdiv.c l64a.c llabs.c \ 8 getsubopt.c hcreate.c heapsort.c imaxabs.c imaxdiv.c insque.c \
9 lldiv.c lsearch.c malloc.c reallocarray.c merge.c posix_pty.c \ 9 l64a.c llabs.c lldiv.c lsearch.c malloc.c reallocarray.c \
10 qsort.c radixsort.c rand.c random.c realpath.c setenv.c strtoimax.c \ 10 merge.c posix_pty.c qsort.c radixsort.c rand.c random.c \
11 realpath.c remque.c setenv.c strtoimax.c \
11 strtol.c strtoll.c strtonum.c strtoul.c strtoull.c strtoumax.c \ 12 strtol.c strtoll.c strtonum.c strtoul.c strtoull.c strtoumax.c \
12 system.c tfind.c tsearch.c _rand48.c drand48.c erand48.c jrand48.c \ 13 system.c tfind.c tsearch.c _rand48.c drand48.c erand48.c jrand48.c \
13 lcong48.c lrand48.c mrand48.c nrand48.c seed48.c srand48.c qabs.c \ 14 lcong48.c lrand48.c mrand48.c nrand48.c seed48.c srand48.c qabs.c \
@@ -24,12 +25,6 @@ SRCS+= abs.c div.c labs.c ldiv.c
24SRCS+= abs.c div.c labs.c ldiv.c 25SRCS+= abs.c div.c labs.c ldiv.c
25.endif 26.endif
26 27
27.if (${MACHINE_CPU} == "vax")
28SRCS+= insque.S remque.S
29.else
30SRCS+= insque.c remque.c
31.endif
32
33MAN+= a64l.3 abort.3 abs.3 alloca.3 atexit.3 atof.3 atoi.3 atol.3 atoll.3 \ 28MAN+= a64l.3 abort.3 abs.3 alloca.3 atexit.3 atof.3 atoi.3 atol.3 atoll.3 \
34 bsearch.3 div.3 ecvt.3 exit.3 getenv.3 getopt.3 getopt_long.3 \ 29 bsearch.3 div.3 ecvt.3 exit.3 getenv.3 getopt.3 getopt_long.3 \
35 getsubopt.3 hcreate.3 imaxabs.3 imaxdiv.3 insque.3 labs.3 ldiv.3 \ 30 getsubopt.3 hcreate.3 imaxabs.3 imaxdiv.3 insque.3 labs.3 ldiv.3 \
diff --git a/src/lib/libc/stdlib/insque.c b/src/lib/libc/stdlib/insque.c
index 8724efec74..590ff837b8 100644
--- a/src/lib/libc/stdlib/insque.c
+++ b/src/lib/libc/stdlib/insque.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: insque.c,v 1.2 2005/08/08 08:05:36 espie Exp $ */ 1/* $OpenBSD: insque.c,v 1.3 2014/08/15 04:14:36 guenther Exp $ */
2 2
3/* 3/*
4 * Copyright (c) 1993 John Brezak 4 * Copyright (c) 1993 John Brezak
@@ -28,6 +28,7 @@
28 * POSSIBILITY OF SUCH DAMAGE. 28 * POSSIBILITY OF SUCH DAMAGE.
29 */ 29 */
30 30
31#include <stdlib.h>
31#include <search.h> 32#include <search.h>
32 33
33struct qelem { 34struct qelem {
@@ -38,11 +39,16 @@ struct qelem {
38void 39void
39insque(void *entry, void *pred) 40insque(void *entry, void *pred)
40{ 41{
41 struct qelem *e = (struct qelem *) entry; 42 struct qelem *e = entry;
42 struct qelem *p = (struct qelem *) pred; 43 struct qelem *p = pred;
43 44
44 e->q_forw = p->q_forw; 45 if (p == NULL)
45 e->q_back = p; 46 e->q_forw = e->q_back = NULL;
46 p->q_forw->q_back = e; 47 else {
47 p->q_forw = e; 48 e->q_forw = p->q_forw;
49 e->q_back = p;
50 if (p->q_forw != NULL)
51 p->q_forw->q_back = e;
52 p->q_forw = e;
53 }
48} 54}
diff --git a/src/lib/libc/stdlib/remque.c b/src/lib/libc/stdlib/remque.c
index ae249ae053..71b74b2dce 100644
--- a/src/lib/libc/stdlib/remque.c
+++ b/src/lib/libc/stdlib/remque.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: remque.c,v 1.2 2005/08/08 08:05:37 espie Exp $ */ 1/* $OpenBSD: remque.c,v 1.3 2014/08/15 04:14:36 guenther Exp $ */
2 2
3/* 3/*
4 * Copyright (c) 1993 John Brezak 4 * Copyright (c) 1993 John Brezak
@@ -28,6 +28,7 @@
28 * POSSIBILITY OF SUCH DAMAGE. 28 * POSSIBILITY OF SUCH DAMAGE.
29 */ 29 */
30 30
31#include <stdlib.h>
31#include <search.h> 32#include <search.h>
32 33
33struct qelem { 34struct qelem {
@@ -38,7 +39,10 @@ struct qelem {
38void 39void
39remque(void *element) 40remque(void *element)
40{ 41{
41 struct qelem *e = (struct qelem *) element; 42 struct qelem *e = element;
42 e->q_forw->q_back = e->q_back; 43
43 e->q_back->q_forw = e->q_forw; 44 if (e->q_forw != NULL)
45 e->q_forw->q_back = e->q_back;
46 if (e->q_back != NULL)
47 e->q_back->q_forw = e->q_forw;
44} 48}