1a2027c5dSToomas Soome /*-
2a2027c5dSToomas Soome * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
3199767f8SToomas Soome *
4a2027c5dSToomas Soome * Copyright (c) 2021 Toomas Soome <tsoome@me.com>
5199767f8SToomas Soome *
6199767f8SToomas Soome * Redistribution and use in source and binary forms, with or without
7199767f8SToomas Soome * modification, are permitted provided that the following conditions
8199767f8SToomas Soome * are met:
9199767f8SToomas Soome * 1. Redistributions of source code must retain the above copyright
10199767f8SToomas Soome * notice, this list of conditions and the following disclaimer.
11199767f8SToomas Soome * 2. Redistributions in binary form must reproduce the above copyright
12199767f8SToomas Soome * notice, this list of conditions and the following disclaimer in the
13199767f8SToomas Soome * documentation and/or other materials provided with the distribution.
14199767f8SToomas Soome *
15a2027c5dSToomas Soome * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
16199767f8SToomas Soome * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17199767f8SToomas Soome * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18a2027c5dSToomas Soome * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
19199767f8SToomas Soome * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
20199767f8SToomas Soome * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
21199767f8SToomas Soome * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
22199767f8SToomas Soome * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
23199767f8SToomas Soome * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
24199767f8SToomas Soome * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
25199767f8SToomas Soome * SUCH DAMAGE.
26199767f8SToomas Soome */
27199767f8SToomas Soome
28199767f8SToomas Soome #include <sys/cdefs.h>
29199767f8SToomas Soome
30199767f8SToomas Soome #include "stand.h"
31199767f8SToomas Soome
32199767f8SToomas Soome void
closeall(void)330384eafeSToomas Soome closeall(void)
34199767f8SToomas Soome {
35a2027c5dSToomas Soome struct open_file *f;
36199767f8SToomas Soome
37a2027c5dSToomas Soome /*
38a2027c5dSToomas Soome * Pick up last entry and close it, this will also trigger
39a2027c5dSToomas Soome * the removal of this entry, and we end up with empty list.
40a2027c5dSToomas Soome */
41a2027c5dSToomas Soome while ((f = TAILQ_LAST(&files, file_list)) != NULL) {
42a2027c5dSToomas Soome (void) close(f->f_id);
43a2027c5dSToomas Soome }
44a2027c5dSToomas Soome /* reset errno from close() */
45a2027c5dSToomas Soome errno = 0;
46199767f8SToomas Soome }
47