Browse Source

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@
OPENBSD_5_7
guenther 10 years ago
parent
commit
ba0ca3d3cf
3 changed files with 26 additions and 21 deletions
  1. +5
    -10
      src/lib/libc/stdlib/Makefile.inc
  2. +13
    -7
      src/lib/libc/stdlib/insque.c
  3. +8
    -4
      src/lib/libc/stdlib/remque.c

+ 5
- 10
src/lib/libc/stdlib/Makefile.inc View File

@ -1,13 +1,14 @@
# $OpenBSD: Makefile.inc,v 1.53 2014/05/08 21:43:49 deraadt Exp $
# $OpenBSD: Makefile.inc,v 1.54 2014/08/15 04:14:36 guenther Exp $
# stdlib sources # stdlib sources
.PATH: ${LIBCSRCDIR}/arch/${MACHINE_CPU}/stdlib ${LIBCSRCDIR}/stdlib .PATH: ${LIBCSRCDIR}/arch/${MACHINE_CPU}/stdlib ${LIBCSRCDIR}/stdlib
SRCS+= a64l.c abort.c atexit.c atoi.c atof.c atol.c atoll.c bsearch.c \ SRCS+= a64l.c abort.c atexit.c atoi.c atof.c atol.c atoll.c bsearch.c \
cfree.c exit.c ecvt.c gcvt.c getenv.c getopt_long.c \ cfree.c exit.c ecvt.c gcvt.c getenv.c getopt_long.c \
getsubopt.c hcreate.c heapsort.c imaxabs.c imaxdiv.c l64a.c llabs.c \
lldiv.c lsearch.c malloc.c reallocarray.c merge.c posix_pty.c \
qsort.c radixsort.c rand.c random.c realpath.c setenv.c strtoimax.c \
getsubopt.c hcreate.c heapsort.c imaxabs.c imaxdiv.c insque.c \
l64a.c llabs.c lldiv.c lsearch.c malloc.c reallocarray.c \
merge.c posix_pty.c qsort.c radixsort.c rand.c random.c \
realpath.c remque.c setenv.c strtoimax.c \
strtol.c strtoll.c strtonum.c strtoul.c strtoull.c strtoumax.c \ strtol.c strtoll.c strtonum.c strtoul.c strtoull.c strtoumax.c \
system.c tfind.c tsearch.c _rand48.c drand48.c erand48.c jrand48.c \ system.c tfind.c tsearch.c _rand48.c drand48.c erand48.c jrand48.c \
lcong48.c lrand48.c mrand48.c nrand48.c seed48.c srand48.c qabs.c \ 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
SRCS+= abs.c div.c labs.c ldiv.c SRCS+= abs.c div.c labs.c ldiv.c
.endif .endif
.if (${MACHINE_CPU} == "vax")
SRCS+= insque.S remque.S
.else
SRCS+= insque.c remque.c
.endif
MAN+= a64l.3 abort.3 abs.3 alloca.3 atexit.3 atof.3 atoi.3 atol.3 atoll.3 \ MAN+= a64l.3 abort.3 abs.3 alloca.3 atexit.3 atof.3 atoi.3 atol.3 atoll.3 \
bsearch.3 div.3 ecvt.3 exit.3 getenv.3 getopt.3 getopt_long.3 \ bsearch.3 div.3 ecvt.3 exit.3 getenv.3 getopt.3 getopt_long.3 \
getsubopt.3 hcreate.3 imaxabs.3 imaxdiv.3 insque.3 labs.3 ldiv.3 \ getsubopt.3 hcreate.3 imaxabs.3 imaxdiv.3 insque.3 labs.3 ldiv.3 \


+ 13
- 7
src/lib/libc/stdlib/insque.c View File

@ -1,4 +1,4 @@
/* $OpenBSD: insque.c,v 1.2 2005/08/08 08:05:36 espie Exp $ */
/* $OpenBSD: insque.c,v 1.3 2014/08/15 04:14:36 guenther Exp $ */
/* /*
* Copyright (c) 1993 John Brezak * Copyright (c) 1993 John Brezak
@ -28,6 +28,7 @@
* POSSIBILITY OF SUCH DAMAGE. * POSSIBILITY OF SUCH DAMAGE.
*/ */
#include <stdlib.h>
#include <search.h> #include <search.h>
struct qelem { struct qelem {
@ -38,11 +39,16 @@ struct qelem {
void void
insque(void *entry, void *pred) insque(void *entry, void *pred)
{ {
struct qelem *e = (struct qelem *) entry;
struct qelem *p = (struct qelem *) pred;
struct qelem *e = entry;
struct qelem *p = pred;
e->q_forw = p->q_forw;
e->q_back = p;
p->q_forw->q_back = e;
p->q_forw = e;
if (p == NULL)
e->q_forw = e->q_back = NULL;
else {
e->q_forw = p->q_forw;
e->q_back = p;
if (p->q_forw != NULL)
p->q_forw->q_back = e;
p->q_forw = e;
}
} }

+ 8
- 4
src/lib/libc/stdlib/remque.c View File

@ -1,4 +1,4 @@
/* $OpenBSD: remque.c,v 1.2 2005/08/08 08:05:37 espie Exp $ */
/* $OpenBSD: remque.c,v 1.3 2014/08/15 04:14:36 guenther Exp $ */
/* /*
* Copyright (c) 1993 John Brezak * Copyright (c) 1993 John Brezak
@ -28,6 +28,7 @@
* POSSIBILITY OF SUCH DAMAGE. * POSSIBILITY OF SUCH DAMAGE.
*/ */
#include <stdlib.h>
#include <search.h> #include <search.h>
struct qelem { struct qelem {
@ -38,7 +39,10 @@ struct qelem {
void void
remque(void *element) remque(void *element)
{ {
struct qelem *e = (struct qelem *) element;
e->q_forw->q_back = e->q_back;
e->q_back->q_forw = e->q_forw;
struct qelem *e = element;
if (e->q_forw != NULL)
e->q_forw->q_back = e->q_back;
if (e->q_back != NULL)
e->q_back->q_forw = e->q_forw;
} }

Loading…
Cancel
Save