-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathse-list.c
More file actions
44 lines (34 loc) · 748 Bytes
/
se-list.c
File metadata and controls
44 lines (34 loc) · 748 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
/*
* S-Expressions: List
*
* Copyright (c) 2019-2023 Alexei A. Smekalkine
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#include <stdarg.h>
#include "se-int.h"
static struct se **se_list_add (struct se **tail, struct se *o)
{
struct se *p;
if ((p = se_pair (o, NULL)) == NULL)
return NULL;
*tail = p;
return &se_to_pair (p)->tail;
}
struct se *se_list (struct se *arg, ...)
{
va_list ap;
struct se *o = arg, *head = NULL, **tail = &head;
if (o == NULL || (tail = se_list_add (tail, o)) == NULL)
return NULL;
va_start (ap, arg);
while ((o = va_arg (ap, struct se *)) != NULL)
if ((tail = se_list_add (tail, o)) == NULL)
goto no_add;
va_end (ap);
return head;
no_add:
va_end (ap);
se_free (head);
return NULL;
}