Imported Upstream version 3.3.6
[platform/upstream/ccache.git] / test / util.c
1 // Copyright (C) 2010-2016 Joel Rosdahl
2 //
3 // This program is free software; you can redistribute it and/or modify it
4 // under the terms of the GNU General Public License as published by the Free
5 // Software Foundation; either version 3 of the License, or (at your option)
6 // any later version.
7 //
8 // This program is distributed in the hope that it will be useful, but WITHOUT
9 // ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
10 // FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
11 // more details.
12 //
13 // You should have received a copy of the GNU General Public License along with
14 // this program; if not, write to the Free Software Foundation, Inc., 51
15 // Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
16
17 #include "../system.h"
18 #include "util.h"
19
20 #ifdef _WIN32
21 #    define lstat(a, b) stat(a, b)
22 #endif
23
24 bool
25 path_exists(const char *path)
26 {
27         struct stat st;
28         return lstat(path, &st) == 0;
29 }
30
31 void
32 create_file(const char *path, const char *content)
33 {
34         FILE *f = fopen(path, "w");
35         if (!f || fputs(content, f) < 0) {
36                 fprintf(stderr, "create_file: %s: %s\n", path, strerror(errno));
37         }
38         if (f) {
39                 fclose(f);
40         }
41 }