1 /** \file archdep_file_exists.c
2 * \brief Check if a file exisys
3 * \author Bas Wassink <b.wassink@ziggo.nl>
4 */
5
6 /*
7 * This file is part of VICE, the Versatile Commodore Emulator.
8 * See README for copyright notice.
9 *
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
14 *
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
19 *
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
23 * 02111-1307 USA.
24 *
25 */
26
27 #include "vice.h"
28 #include <stdio.h>
29 #include <stdlib.h>
30 #include <errno.h>
31
32 #include "archdep.h"
33 #include "archdep_defs.h"
34
35
36 #ifdef ARCHDEP_OS_UNIX
37 # include <unistd.h>
38 #endif
39
40 #ifdef ARCHDEP_OS_WINDOWS
41 #define WIN32_LEAN_AND_MEAN
42 #include <windows.h>
43 #endif
44
45 #include "archdep_file_exists.h"
46
47
archdep_file_exists(const char * path)48 bool archdep_file_exists(const char *path)
49 {
50 #ifdef ARCHDEP_OS_UNIX
51
52 if (access(path, F_OK) == 0) {
53 return true;
54 }
55 #endif
56
57 #ifdef ARCHDEP_OS_WINDOWS
58 /* Possible TODO: convert path from UTF-8 to UTF-16LE and use the
59 * more consistent GetFileAttributesW call */
60 if (GetFileAttributesA(path) != INVALID_FILE_ATTRIBUTES) {
61 return true;
62 }
63 #endif
64
65 return false;
66
67 }
68
69