openat: don’t close (-1)
[gnulib.git] / tests / test-supersede.c
blob778f1675cff48845d3c9e3c06ba2c304dda757e4
1 /* Tests for opening a file without destroying an old file with the same name.
3 Copyright (C) 2020-2024 Free Software Foundation, Inc.
5 This program is free software: you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation, either version 3 of the License, or
8 (at your option) any later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program. If not, see <https://www.gnu.org/licenses/>. */
18 /* Written by Bruno Haible, 2020. */
20 #include <config.h>
22 /* Specification. */
23 #include "supersede.h"
25 #include <errno.h>
26 #include <fcntl.h>
27 #include <stdlib.h>
28 #include <string.h>
29 #include <sys/stat.h>
30 #include <unistd.h>
32 #include "filenamecat.h"
33 #include "read-file.h"
34 #include "macros.h"
36 /* The name of the "always silent" device. */
37 #if defined _WIN32 && ! defined __CYGWIN__
38 /* Native Windows API. */
39 # define DEV_NULL "NUL"
40 #else
41 /* Unix API. */
42 # define DEV_NULL "/dev/null"
43 #endif
45 #include "test-supersede-open.h"
46 #include "test-supersede-fopen.h"
48 int
49 main (void)
51 test_open_supersede (false, false);
52 test_open_supersede (false, true);
53 test_open_supersede (true, false);
54 test_open_supersede (true, true);
56 test_fopen_supersede (false, false);
57 test_fopen_supersede (false, true);
58 test_fopen_supersede (true, false);
59 test_fopen_supersede (true, true);
61 return test_exit_status;