summaryrefslogtreecommitdiff
path: root/src/lib/libc/stdlib/insque.c
diff options
context:
space:
mode:
authorguenther <>2014-08-15 04:14:36 +0000
committerguenther <>2014-08-15 04:14:36 +0000
commit3ea4545f65c31073396b3f70460f5e9426064b79 (patch)
treead98e89509d81894a7205c6b5bc0cb6747d59cd6 /src/lib/libc/stdlib/insque.c
parentca8ede79a0636ab46503a89fd990988aa6393a33 (diff)
downloadopenbsd-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@
Diffstat (limited to 'src/lib/libc/stdlib/insque.c')
-rw-r--r--src/lib/libc/stdlib/insque.c20
1 files changed, 13 insertions, 7 deletions
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}