1 |
|
|
/* $OpenBSD: lstAddNew.c,v 1.8 2010/07/19 19:46:44 espie Exp $ */ |
2 |
|
|
/* ex:ts=8 sw=4: |
3 |
|
|
*/ |
4 |
|
|
|
5 |
|
|
/* |
6 |
|
|
* Copyright (c) 1999 Marc Espie. |
7 |
|
|
* |
8 |
|
|
* Code written for the OpenBSD project. |
9 |
|
|
* |
10 |
|
|
* Redistribution and use in source and binary forms, with or without |
11 |
|
|
* modification, are permitted provided that the following conditions |
12 |
|
|
* are met: |
13 |
|
|
* 1. Redistributions of source code must retain the above copyright |
14 |
|
|
* notice, this list of conditions and the following disclaimer. |
15 |
|
|
* 2. Redistributions in binary form must reproduce the above copyright |
16 |
|
|
* notice, this list of conditions and the following disclaimer in the |
17 |
|
|
* documentation and/or other materials provided with the distribution. |
18 |
|
|
* |
19 |
|
|
* THIS SOFTWARE IS PROVIDED BY THE OPENBSD PROJECT AND CONTRIBUTORS |
20 |
|
|
* ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
21 |
|
|
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
22 |
|
|
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OPENBSD |
23 |
|
|
* PROJECT OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
24 |
|
|
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
25 |
|
|
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
26 |
|
|
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
27 |
|
|
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
28 |
|
|
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
29 |
|
|
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
30 |
|
|
*/ |
31 |
|
|
|
32 |
|
|
#include "lstInt.h" |
33 |
|
|
#include <stddef.h> |
34 |
|
|
|
35 |
|
|
/* Add datum to the end of a list only if it wasn't there already. |
36 |
|
|
* Returns false if datum was already there. |
37 |
|
|
*/ |
38 |
|
|
bool |
39 |
|
|
Lst_AddNew(Lst l, void *d) |
40 |
|
|
{ |
41 |
✓✓ |
6819868 |
if (Lst_Member(l, d) != NULL) |
42 |
|
355084 |
return false; |
43 |
|
|
else { |
44 |
|
3054850 |
Lst_AtEnd(l, d); |
45 |
|
3054850 |
return true; |
46 |
|
|
} |
47 |
|
3409934 |
} |
48 |
|
|
|