diff options
author | guenther <> | 2014-08-15 04:14:36 +0000 |
---|---|---|
committer | guenther <> | 2014-08-15 04:14:36 +0000 |
commit | 3ea4545f65c31073396b3f70460f5e9426064b79 (patch) | |
tree | ad98e89509d81894a7205c6b5bc0cb6747d59cd6 | |
parent | ca8ede79a0636ab46503a89fd990988aa6393a33 (diff) | |
download | openbsd-3ea4545f65c31073396b3f70460f5e9426064b79.tar.gz openbsd-3ea4545f65c31073396b3f70460f5e9426064b79.tar.bz2 openbsd-3ea4545f65c31073396b3f70460f5e9426064b79.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@
-rw-r--r-- | src/lib/libc/stdlib/Makefile.inc | 15 | ||||
-rw-r--r-- | src/lib/libc/stdlib/insque.c | 20 | ||||
-rw-r--r-- | src/lib/libc/stdlib/remque.c | 12 |
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 | ||
6 | SRCS+= a64l.c abort.c atexit.c atoi.c atof.c atol.c atoll.c bsearch.c \ | 6 | SRCS+= 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 | |||
24 | SRCS+= abs.c div.c labs.c ldiv.c | 25 | SRCS+= abs.c div.c labs.c ldiv.c |
25 | .endif | 26 | .endif |
26 | 27 | ||
27 | .if (${MACHINE_CPU} == "vax") | ||
28 | SRCS+= insque.S remque.S | ||
29 | .else | ||
30 | SRCS+= insque.c remque.c | ||
31 | .endif | ||
32 | |||
33 | MAN+= a64l.3 abort.3 abs.3 alloca.3 atexit.3 atof.3 atoi.3 atol.3 atoll.3 \ | 28 | MAN+= 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 | ||
33 | struct qelem { | 34 | struct qelem { |
@@ -38,11 +39,16 @@ struct qelem { | |||
38 | void | 39 | void |
39 | insque(void *entry, void *pred) | 40 | insque(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 | ||
33 | struct qelem { | 34 | struct qelem { |
@@ -38,7 +39,10 @@ struct qelem { | |||
38 | void | 39 | void |
39 | remque(void *element) | 40 | remque(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 | } |