2 * CDE - Common Desktop Environment
4 * Copyright (c) 1993-2012, The Open Group. All rights reserved.
6 * These libraries and programs are free software; you can
7 * redistribute them and/or modify them under the terms of the GNU
8 * Lesser General Public License as published by the Free Software
9 * Foundation; either version 2 of the License, or (at your option)
12 * These libraries and programs are distributed in the hope that
13 * they will be useful, but WITHOUT ANY WARRANTY; without even the
14 * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15 * PURPOSE. See the GNU Lesser General Public License for more
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with these libraries and programs; if not, write
20 * to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
21 * Floor, Boston, MA 02110-1301 USA
23 /*%% (c) Copyright 1993, 1994 Hewlett-Packard Company */
24 /*%% (c) Copyright 1993, 1994 International Business Machines Corp. */
25 /*%% (c) Copyright 1993, 1994 Sun Microsystems, Inc. */
26 /*%% (c) Copyright 1993, 1994 Novell, Inc. */
27 /*%% $TOG: isdlink.c /main/4 1999/09/29 15:03:15 mgreess $ */
30 * Copyright (c) 1988 by Sun Microsystems, Inc.
37 * Double link list functions
40 #include "isam_impl.h"
42 /* _isdln_base_insert () - Insert element into list (at the front) -----------*/
43 void _isdln_base_insert (char *base, struct dlink *l,
46 e->dln_forward = l->dln_forward;
47 l->dln_forward = (char *)e - base;
49 e->dln_backward = (char *)l - base;
50 ((struct dlink *)(base + e->dln_forward))->dln_backward = (char *)e - base;
53 /* _isdln_base_append () - Append element to list (at the end) -------------*/
54 void _isdln_base_append (char *base, struct dlink *l,
57 e->dln_backward = l->dln_backward;
58 l->dln_backward = (char *)e - base;
60 e->dln_forward = (char *)l - base;
61 ((struct dlink *)(base + e->dln_backward))->dln_forward = (char *)e - base;
64 /* _isdln_base_remove () - Remove element from list -------------------------*/
65 void _isdln_base_remove (char *base, struct dlink *e)
67 ((struct dlink *)(base + e->dln_backward))->dln_forward = e->dln_forward;
68 ((struct dlink *)(base + e->dln_forward))->dln_backward = e->dln_backward;
71 /* _isdln_base_first () - Return first element of the list -------------------*/
72 struct dlink * _isdln_base_first(char *base, struct dlink *l)
74 struct dlink *val = (struct dlink *)(base + l->dln_forward);
77 if (NULL == (struct dlink *)(base + l->dln_forward) &&
78 NULL == (struct dlink *)(base + l->dln_backward))
79 _isdln_base_makeempty(base, l);
85 /* _isdln_base_next () - Return next element in the list --------------------*/
86 struct dlink * _isdln_base_next(char *base, struct dlink *l)
88 return (((struct dlink *)(base + l->dln_forward)));
91 /* _isdln_base_prev () - Return previous element in the list ----------------*/
92 struct dlink * _isdln_base_prev(char *base, struct dlink *l)
94 return (((struct dlink *)(base + l->dln_backward)));
97 /* _isdln_base_makeempty () - Make head of empty list -----------------------*/
98 void _isdln_base_makeempty(char *base, struct dlink *l)
100 l->dln_forward = l->dln_backward = (char *)l - base;
103 /* _isdln_base_isempty () - Test if list is empty---------------------------*/
104 int _isdln_base_isempty(char *base, struct dlink *l)
106 return (l->dln_forward == (char *)l - base &&
107 l->dln_backward == (char *)l - base);