Debian Codegraph @

libretro-common/file/retro_stat.c

raw symbols SCIP
1 /* Copyright (C) 2010-2015 The RetroArch team
2 *
3 * ---------------------------------------------------------------------------------------
4 * The following license statement only applies to this file (retro_stat.c).
5 * ---------------------------------------------------------------------------------------
6 *
7 * Permission is hereby granted, free of charge,
8 * to any person obtaining a copy of this software and associated documentation files (the "Software"),
9 * to deal in the Software without restriction, including without limitation the rights to
10 * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software,
11 * and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
12 *
13 * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
14 *
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
16 * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
18 * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
19 * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
21 */
22
23 #include <stdio.h>
24 #include <stdlib.h>
25 #include <string.h>
26 #include <errno.h>
27
28 #if defined(_WIN32)
29 #ifdef _MSC_VER
30 #define setmode _setmode
31 #endif
32 #ifdef _XBOX
33 #include <xtl.h>
34 #define INVALID_FILE_ATTRIBUTES -1
35 #else
36 #include <io.h>
37 #include <fcntl.h>
38 #include <direct.h>
39 #include <windows.h>
40 #endif
41 #elif defined(VITA)
42 #define SCE_ERROR_ERRNO_EEXIST 0x80010011
43 #include <psp2/io/fcntl.h>
44 #include <psp2/io/dirent.h>
45 #include <psp2/io/stat.h>
46 #else
47 #include <sys/types.h>
48 #include <sys/stat.h>
49 #include <unistd.h>
50 #endif
51
52 #if defined(PSP)
53 #include <pspkernel.h>
54 #endif
55
56 #ifdef __HAIKU__
57 #include <kernel/image.h>
58 #endif
59
60 #if defined(__CELLOS_LV2__)
61 #include <cell/cell_fs.h>
62 #endif
63
64 #if defined(VITA)
65 #define FIO_S_ISDIR PSP2_S_ISDIR
66 #endif
67
68 #if (defined(__CELLOS_LV2__) && !defined(__PSL1GHT__)) || defined(__QNX__) || defined(PSP)
69 #include <unistd.h> /* stat() is defined here */
70 #endif
71
72 #include <retro_miscellaneous.h>cxx . . $ `<file>/libretro-common/include/retro_miscellaneous.h`/
73 #include <boolean.h>cxx . . $ `<file>/libretro-common/include/boolean.h`/
74
75 enum stat_modecxx . . $ stat_mode#
76 {
77 IS_DIRECTORYcxx . . $ IS_DIRECTORY. = 0,
78 IS_CHARACTER_SPECIALcxx . . $ IS_CHARACTER_SPECIAL.,
79 IS_VALIDcxx . . $ IS_VALID.
80 };
81
82 static boolcxx . . $ `<external>/14268322491693841775/stdbool.h:36:9`! path_statcxx . . $ path_stat(35218e7b3689708a).(const char *path, enum stat_modecxx . . $ stat_mode# mode, int32_tcxx . . $ int32_t# *size)
83 {
84 #if defined(VITA) || defined(PSP)
85 SceIoStat buf;
86 char *tmp = strdup(path);
87 size_t len = strlen(tmp);
88 if (tmp[len-1] == '/')
89 tmp[len-1]='\0';
90
91 if (sceIoGetstat(tmp, &buf) < 0)
92 {
93 free(tmp);
94 return false;
95 }
96 free(tmp);
97
98 #elif defined(__CELLOS_LV2__)
99 CellFsStat buf;
100 if (cellFsStat(path, &buf) < 0)
101 return false;
102 #elif defined(_WIN32)
103 WIN32_FILE_ATTRIBUTE_DATA file_info;
104 GET_FILEEX_INFO_LEVELS fInfoLevelId = GetFileExInfoStandard;
105 DWORD ret = GetFileAttributesEx(path, fInfoLevelId, &file_info);
106 if (ret == 0)
107 return false;
108 #else
109 struct statcxx . . $ stat# buf;
110 if (statcxx . . $ stat(a9cd1e23e96f423c).(path, &buf) < 0)
111 return falsecxx . . $ `<external>/14268322491693841775/stdbool.h:38:9`!;
112 #endif
113
114 #if defined(_WIN32)
115 if (size)
116 *size = file_info.nFileSizeLow;
117 #else
118 if (size)
119 *size = buf.st_sizecxx . . $ stat#st_size.;
120 #endif
121
122 switch (mode)
123 {
124 case IS_DIRECTORYcxx . . $ IS_DIRECTORY.:
125 #if defined(VITA) || defined(PSP)
126 return FIO_S_ISDIR(buf.st_mode);
127 #elif defined(__CELLOS_LV2__)
128 return ((buf.st_mode & S_IFMT) == S_IFDIR);
129 #elif defined(_WIN32)
130 return (file_info.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY);
131 #else
132 return S_ISDIRcxx . . $ `<external>/531885356569766532/stat.h:125:9`!(buf.st_mode);
133 #endif
134 case IS_CHARACTER_SPECIALcxx . . $ IS_CHARACTER_SPECIAL.:
135 #if defined(VITA) || defined(PSP) || defined(__CELLOS_LV2__) || defined(_WIN32)
136 return false;
137 #else
138 return S_ISCHRcxx . . $ `<external>/531885356569766532/stat.h:126:9`!(buf.st_mode);
139 #endif
140 case IS_VALIDcxx . . $ IS_VALID.:
141 return truecxx . . $ `<external>/14268322491693841775/stdbool.h:37:9`!;
142 }
143
144 return falsecxx . . $ `<external>/14268322491693841775/stdbool.h:38:9`!;
145 }
146
147 /**
148 * path_is_directory:
149 * @path : path
150 *
151 * Checks if path is a directory.
152 *
153 * Returns: true (1) if path is a directory, otherwise false (0).
154 */
155 boolcxx . . $ `<external>/14268322491693841775/stdbool.h:36:9`! path_is_directorycxx . . $ path_is_directory(c5f7da30cbc0f4e9).(const char *path)
156 {
157 return path_statcxx . . $ path_stat(35218e7b3689708a).(path, IS_DIRECTORYcxx . . $ IS_DIRECTORY., NULLcxx . . $ `<external>/15298297234472979974/stddef.h:419:9`!);
158 }
159
160 boolcxx . . $ `<external>/14268322491693841775/stdbool.h:36:9`! path_is_character_specialcxx . . $ path_is_character_special(c5f7da30cbc0f4e9).(const char *path)
161 {
162 return path_statcxx . . $ path_stat(35218e7b3689708a).(path, IS_CHARACTER_SPECIALcxx . . $ IS_CHARACTER_SPECIAL., NULLcxx . . $ `<external>/15298297234472979974/stddef.h:419:9`!);
163 }
164
165 boolcxx . . $ `<external>/14268322491693841775/stdbool.h:36:9`! path_is_validcxx . . $ path_is_valid(c5f7da30cbc0f4e9).(const char *path)
166 {
167 return path_statcxx . . $ path_stat(35218e7b3689708a).(path, IS_VALIDcxx . . $ IS_VALID., NULLcxx . . $ `<external>/15298297234472979974/stddef.h:419:9`!);
168 }
169
170 int32_tcxx . . $ int32_t# path_get_sizecxx . . $ path_get_size(5c4306d8553b3696).(const char *path)
171 {
172 int32_tcxx . . $ int32_t# filesize = 0;
173 if (path_statcxx . . $ path_stat(35218e7b3689708a).(path, IS_VALIDcxx . . $ IS_VALID., &filesize))
174 return filesize;
175
176 return -1;
177 }
178
179 /**
180 * path_mkdir_norecurse:
181 * @dir : directory
182 *
183 * Create directory on filesystem.
184 *
185 * Returns: true (1) if directory could be created, otherwise false (0).
186 **/
187 boolcxx . . $ `<external>/14268322491693841775/stdbool.h:36:9`! mkdir_norecursecxx . . $ mkdir_norecurse(c5f7da30cbc0f4e9).(const char *dir)
188 {
189 int ret;
190 #if defined(_WIN32)
191 ret = _mkdir(dir);
192 #elif defined(IOS)
193 ret = mkdir(dir, 0755);
194 #elif defined(VITA) || defined(PSP)
195 ret = sceIoMkdir(dir, 0777);
196 #else
197 ret = mkdircxx . . $ mkdir(1df18506ef0a631b).(dir, 0750);
198 #endif
199 /* Don't treat this as an error. */
200 #if defined(VITA)
201 if ((ret == SCE_ERROR_ERRNO_EEXIST) && path_is_directory(dir))
202 ret = 0;
203 #elif defined(PSP)
204 if ((ret == -1) && path_is_directory(dir))
205 ret = 0;
206 #else
207 if (ret < 0 && errnocxx . . $ `<external>/17633486526465735210/errno.h:38:10`! == EEXISTcxx . . $ `<external>/8987895939074593727/errno-base.h:21:9`! && path_is_directorycxx . . $ path_is_directory(c5f7da30cbc0f4e9).(dir))
208 ret = 0;
209 #endif
210 if (ret < 0)
211 printfcxx . . $ printf(581fddd72a8db8fc).("mkdir(%s) error: %s.\n", dir, strerrorcxx . . $ strerror(ff224f080444ee45).(errnocxx . . $ `<external>/17633486526465735210/errno.h:38:10`!));
212 return ret == 0;
213 }