Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
Libretro
tyrquake
Commits
2a7746f2
Commit
2a7746f2
authored
Sep 05, 2015
by
Libretro-Admin
Browse files
Use retro_dirent
parent
72f64f16
Changes
5
Hide whitespace changes
Inline
Side-by-side
Makefile.common
View file @
2a7746f2
INCFLAGS
:=
-I
$(CORE_DIR)
-I
$(CORE_DIR)
/NQ
-I
$(CORE_DIR)
/include
INCFLAGS
:=
\
-I
$(CORE_DIR)
\
-I
$(CORE_DIR)
/NQ
\
-I
$(CORE_DIR)
/libretro-common/include
\
-I
$(CORE_DIR)
/include
SOURCES_C
:=
$(CORE_DIR)
/NQ/cl_input.c
\
$(CORE_DIR)
/common/cd_common.c
\
$(CORE_DIR)
/common/alias_model.c
\
$(CORE_DIR)
/NQ/chase.c
\
$(CORE_DIR)
/NQ/cl_demo.c
\
$(CORE_DIR)
/NQ/cl_main.c
\
$(CORE_DIR)
/NQ/cl_parse.c
\
$(CORE_DIR)
/NQ/cl_tent.c
\
$(CORE_DIR)
/common/common.c
\
$(CORE_DIR)
/common/cmd.c
\
$(CORE_DIR)
/common/crc.c
\
$(CORE_DIR)
/common/console.c
\
$(CORE_DIR)
/common/cvar.c
\
$(CORE_DIR)
/common/d_edge.c
\
$(CORE_DIR)
/common/d_fill.c
\
$(CORE_DIR)
/common/d_init.c
\
$(CORE_DIR)
/common/d_part.c
\
$(CORE_DIR)
/common/d_modech.c
\
$(CORE_DIR)
/common/d_polyse.c
\
$(CORE_DIR)
/common/d_scan.c
\
$(CORE_DIR)
/common/d_sky.c
\
$(CORE_DIR)
/common/d_sprite.c
\
$(CORE_DIR)
/common/d_surf.c
\
$(CORE_DIR)
/common/d_vars.c
\
$(CORE_DIR)
/common/draw.c
\
$(CORE_DIR)
/NQ/host.c
\
$(CORE_DIR)
/NQ/host_cmd.c
\
$(CORE_DIR)
/common/keys.c
\
$(CORE_DIR)
/common/mathlib.c
\
$(CORE_DIR)
/NQ/menu.c
\
$(CORE_DIR)
/common/model.c
\
$(CORE_DIR)
/NQ/net_common.c
\
$(CORE_DIR)
/NQ/net_loop.c
\
$(CORE_DIR)
/NQ/net_main.c
\
$(CORE_DIR)
/common/nonintel.c
\
$(CORE_DIR)
/common/pr_cmds.c
\
$(CORE_DIR)
/common/pr_exec.c
\
$(CORE_DIR)
/common/pr_edict.c
\
$(CORE_DIR)
/common/r_aclip.c
\
$(CORE_DIR)
/common/r_alias.c
\
$(CORE_DIR)
/common/r_bsp.c
\
$(CORE_DIR)
/common/r_draw.c
\
$(CORE_DIR)
/common/r_edge.c
\
$(CORE_DIR)
/common/r_efrag.c
\
$(CORE_DIR)
/common/r_light.c
\
$(CORE_DIR)
/common/r_main.c
\
$(CORE_DIR)
/common/r_misc.c
\
$(CORE_DIR)
/common/r_model.c
\
$(CORE_DIR)
/common/r_part.c
\
$(CORE_DIR)
/common/r_sky.c
\
$(CORE_DIR)
/common/r_sprite.c
\
$(CORE_DIR)
/common/r_vars.c
\
$(CORE_DIR)
/common/r_surf.c
\
$(CORE_DIR)
/common/rb_tree.c
\
$(CORE_DIR)
/NQ/sbar.c
\
$(CORE_DIR)
/common/screen.c
\
$(CORE_DIR)
/common/shell.c
\
$(CORE_DIR)
/common/snd_dma.c
\
$(CORE_DIR)
/common/snd_mem.c
\
$(CORE_DIR)
/common/snd_mix.c
\
$(CORE_DIR)
/common/sprite_model.c
\
$(CORE_DIR)
/NQ/sv_main.c
\
$(CORE_DIR)
/common/sv_move.c
\
$(CORE_DIR)
/NQ/sv_phys.c
\
$(CORE_DIR)
/NQ/sv_user.c
\
$(CORE_DIR)
/common/sys_libretro.c
\
$(CORE_DIR)
/NQ/view.c
\
$(CORE_DIR)
/common/wad.c
\
$(CORE_DIR)
/common/zone.c
\
$(CORE_DIR)
/common/world.c
SOURCES_C
:=
$(CORE_DIR)
/libretro-common/file/retro_dirent.c
\
$(CORE_DIR)
/NQ/cl_input.c
\
$(CORE_DIR)
/common/cd_common.c
\
$(CORE_DIR)
/common/alias_model.c
\
$(CORE_DIR)
/NQ/chase.c
\
$(CORE_DIR)
/NQ/cl_demo.c
\
$(CORE_DIR)
/NQ/cl_main.c
\
$(CORE_DIR)
/NQ/cl_parse.c
\
$(CORE_DIR)
/NQ/cl_tent.c
\
$(CORE_DIR)
/common/common.c
\
$(CORE_DIR)
/common/cmd.c
\
$(CORE_DIR)
/common/crc.c
\
$(CORE_DIR)
/common/console.c
\
$(CORE_DIR)
/common/cvar.c
\
$(CORE_DIR)
/common/d_edge.c
\
$(CORE_DIR)
/common/d_fill.c
\
$(CORE_DIR)
/common/d_init.c
\
$(CORE_DIR)
/common/d_part.c
\
$(CORE_DIR)
/common/d_modech.c
\
$(CORE_DIR)
/common/d_polyse.c
\
$(CORE_DIR)
/common/d_scan.c
\
$(CORE_DIR)
/common/d_sky.c
\
$(CORE_DIR)
/common/d_sprite.c
\
$(CORE_DIR)
/common/d_surf.c
\
$(CORE_DIR)
/common/d_vars.c
\
$(CORE_DIR)
/common/draw.c
\
$(CORE_DIR)
/NQ/host.c
\
$(CORE_DIR)
/NQ/host_cmd.c
\
$(CORE_DIR)
/common/keys.c
\
$(CORE_DIR)
/common/mathlib.c
\
$(CORE_DIR)
/NQ/menu.c
\
$(CORE_DIR)
/common/model.c
\
$(CORE_DIR)
/NQ/net_common.c
\
$(CORE_DIR)
/NQ/net_loop.c
\
$(CORE_DIR)
/NQ/net_main.c
\
$(CORE_DIR)
/common/nonintel.c
\
$(CORE_DIR)
/common/pr_cmds.c
\
$(CORE_DIR)
/common/pr_exec.c
\
$(CORE_DIR)
/common/pr_edict.c
\
$(CORE_DIR)
/common/r_aclip.c
\
$(CORE_DIR)
/common/r_alias.c
\
$(CORE_DIR)
/common/r_bsp.c
\
$(CORE_DIR)
/common/r_draw.c
\
$(CORE_DIR)
/common/r_edge.c
\
$(CORE_DIR)
/common/r_efrag.c
\
$(CORE_DIR)
/common/r_light.c
\
$(CORE_DIR)
/common/r_main.c
\
$(CORE_DIR)
/common/r_misc.c
\
$(CORE_DIR)
/common/r_model.c
\
$(CORE_DIR)
/common/r_part.c
\
$(CORE_DIR)
/common/r_sky.c
\
$(CORE_DIR)
/common/r_sprite.c
\
$(CORE_DIR)
/common/r_vars.c
\
$(CORE_DIR)
/common/r_surf.c
\
$(CORE_DIR)
/common/rb_tree.c
\
$(CORE_DIR)
/NQ/sbar.c
\
$(CORE_DIR)
/common/screen.c
\
$(CORE_DIR)
/common/shell.c
\
$(CORE_DIR)
/common/snd_dma.c
\
$(CORE_DIR)
/common/snd_mem.c
\
$(CORE_DIR)
/common/snd_mix.c
\
$(CORE_DIR)
/common/sprite_model.c
\
$(CORE_DIR)
/NQ/sv_main.c
\
$(CORE_DIR)
/common/sv_move.c
\
$(CORE_DIR)
/NQ/sv_phys.c
\
$(CORE_DIR)
/NQ/sv_user.c
\
$(CORE_DIR)
/common/sys_libretro.c
\
$(CORE_DIR)
/NQ/view.c
\
$(CORE_DIR)
/common/wad.c
\
$(CORE_DIR)
/common/zone.c
\
$(CORE_DIR)
/common/world.c
SOURCES_C
+=
$(CORE_DIR)
/NQ/net_none.c
common/common.c
View file @
2a7746f2
...
...
@@ -20,11 +20,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
// common.c -- misc functions used in client and server
#include <ctype.h>
#ifdef _WIN32
#include "dirent_win32.h"
#else
#include <dirent.h>
#endif
#include <retro_dirent.h>
#include <stdarg.h>
#include <stdlib.h>
#include <string.h>
...
...
@@ -1589,30 +1585,30 @@ COM_FOpenFile(const char *filename, FILE **file)
return
-
1
;
}
static
void
COM_ScanDirDir
(
struct
stree_root
*
root
,
DIR
*
dir
,
const
char
*
pfx
,
static
void
COM_ScanDirDir
(
struct
stree_root
*
root
,
struct
R
DIR
*
dir
,
const
char
*
pfx
,
const
char
*
ext
,
qboolean
stripext
)
{
int
pfx_len
,
ext_len
;
struct
dirent
*
d
;
char
*
fname
;
int
pfx_len
=
pfx
?
strlen
(
pfx
)
:
0
;
int
ext_len
=
ext
?
strlen
(
ext
)
:
0
;
pfx_len
=
pfx
?
strlen
(
pfx
)
:
0
;
ext_len
=
ext
?
strlen
(
ext
)
:
0
;
while
((
d
=
readdir
(
dir
)))
{
if
((
!
pfx
||
!
strncasecmp
(
d
->
d_name
,
pfx
,
pfx_len
))
&&
(
!
ext
||
COM_CheckExtension
(
d
->
d_name
,
ext
)))
{
int
len
=
strlen
(
d
->
d_name
);
if
(
ext
&&
stripext
)
len
-=
ext_len
;
fname
=
(
char
*
)
Z_Malloc
(
len
+
1
);
if
(
fname
)
{
strncpy
(
fname
,
d
->
d_name
,
len
);
fname
[
len
]
=
'\0'
;
STree_InsertAlloc
(
root
,
fname
,
true
);
Z_Free
(
fname
);
}
}
while
(
retro_readdir
(
dir
))
{
if
((
!
pfx
||
!
strncasecmp
(
retro_dirent_get_name
(
dir
),
pfx
,
pfx_len
))
&&
(
!
ext
||
COM_CheckExtension
(
retro_dirent_get_name
(
dir
),
ext
)))
{
int
len
=
strlen
(
retro_dirent_get_name
(
dir
));
if
(
ext
&&
stripext
)
len
-=
ext_len
;
fname
=
(
char
*
)
Z_Malloc
(
len
+
1
)
;
if
(
fname
)
{
strncpy
(
fname
,
retro_dirent_get_name
(
dir
)
,
len
);
fname
[
len
]
=
'\0'
;
STree_InsertAlloc
(
root
,
fname
,
true
);
Z_Free
(
fname
);
}
}
}
}
...
...
@@ -1675,23 +1671,27 @@ void
COM_ScanDir
(
struct
stree_root
*
root
,
const
char
*
path
,
const
char
*
pfx
,
const
char
*
ext
,
qboolean
stripext
)
{
searchpath_t
*
search
;
char
fullpath
[
MAX_OSPATH
];
DIR
*
dir
;
searchpath_t
*
search
;
char
fullpath
[
MAX_OSPATH
];
struct
R
DIR
*
dir
;
for
(
search
=
com_searchpaths
;
search
;
search
=
search
->
next
)
{
if
(
search
->
pack
)
{
COM_ScanDirPak
(
root
,
search
->
pack
,
path
,
pfx
,
ext
,
stripext
);
}
else
{
snprintf
(
fullpath
,
MAX_OSPATH
,
"%s/%s"
,
search
->
filename
,
path
);
fullpath
[
MAX_OSPATH
-
1
]
=
'\0'
;
dir
=
opendir
(
fullpath
);
if
(
dir
)
{
COM_ScanDirDir
(
root
,
dir
,
pfx
,
ext
,
stripext
);
closedir
(
dir
);
}
}
}
for
(
search
=
com_searchpaths
;
search
;
search
=
search
->
next
)
{
if
(
search
->
pack
)
COM_ScanDirPak
(
root
,
search
->
pack
,
path
,
pfx
,
ext
,
stripext
);
else
{
snprintf
(
fullpath
,
MAX_OSPATH
,
"%s/%s"
,
search
->
filename
,
path
);
fullpath
[
MAX_OSPATH
-
1
]
=
'\0'
;
dir
=
retro_opendir
(
fullpath
);
if
(
dir
)
{
COM_ScanDirDir
(
root
,
dir
,
pfx
,
ext
,
stripext
);
retro_closedir
(
dir
);
}
}
}
}
/*
...
...
libretro-common/file/retro_dirent.c
0 → 100644
View file @
2a7746f2
#include <stdlib.h>
#if defined(_WIN32)
#ifdef _MSC_VER
#define setmode _setmode
#endif
#ifdef _XBOX
#include <xtl.h>
#define INVALID_FILE_ATTRIBUTES -1
#else
#include <io.h>
#include <fcntl.h>
#include <direct.h>
#include <windows.h>
#endif
#elif defined(VITA)
#include <psp2/io/fcntl.h>
#include <psp2/io/dirent.h>
#else
#if defined(PSP)
#include <pspiofilemgr.h>
#endif
#include <sys/types.h>
#include <sys/stat.h>
#include <dirent.h>
#include <unistd.h>
#endif
#ifdef __CELLOS_LV2__
#include <cell/cell_fs.h>
#endif
#include <boolean.h>
struct
RDIR
{
#if defined(_WIN32)
WIN32_FIND_DATA
entry
;
HANDLE
directory
;
#elif defined(VITA) || defined(PSP)
SceUID
directory
;
SceIoDirent
entry
;
#elif defined(__CELLOS_LV2__)
CellFsErrno
error
;
int
directory
;
CellFsDirent
entry
;
#else
DIR
*
directory
;
const
struct
dirent
*
entry
;
#endif
};
struct
RDIR
*
retro_opendir
(
const
char
*
name
)
{
char
path_buf
[
1024
];
struct
RDIR
*
rdir
=
(
struct
RDIR
*
)
calloc
(
1
,
sizeof
(
*
rdir
));
if
(
!
rdir
)
return
NULL
;
(
void
)
path_buf
;
#if defined(_WIN32)
snprintf
(
path_buf
,
sizeof
(
path_buf
),
"%s
\\
*"
,
name
);
rdir
->
directory
=
FindFirstFile
(
path_buf
,
&
rdir
->
entry
);
#elif defined(VITA) || defined(PSP)
rdir
->
directory
=
sceIoDopen
(
name
);
#elif defined(__CELLOS_LV2__)
rdir
->
error
=
cellFsOpendir
(
name
,
&
rdir
->
directory
);
#else
rdir
->
directory
=
opendir
(
name
);
rdir
->
entry
=
NULL
;
#endif
return
rdir
;
}
bool
retro_dirent_error
(
struct
RDIR
*
rdir
)
{
#if defined(_WIN32)
return
(
rdir
->
directory
==
INVALID_HANDLE_VALUE
);
#elif defined(VITA) || defined(PSP)
return
(
rdir
->
directory
<
0
);
#elif defined(__CELLOS_LV2__)
return
(
rdir
->
error
!=
CELL_FS_SUCCEEDED
);
#else
return
!
(
rdir
->
directory
);
#endif
}
int
retro_readdir
(
struct
RDIR
*
rdir
)
{
#if defined(_WIN32)
return
(
FindNextFile
(
rdir
->
directory
,
&
rdir
->
entry
)
!=
0
);
#elif defined(VITA) || defined(PSP)
return
(
sceIoDread
(
rdir
->
directory
,
&
rdir
->
entry
)
>
0
);
#elif defined(__CELLOS_LV2__)
uint64_t
nread
;
rdir
->
error
=
cellFsReaddir
(
rdir
->
directory
,
&
rdir
->
entry
,
&
nread
);
return
(
nread
!=
0
);
#else
return
((
rdir
->
entry
=
readdir
(
rdir
->
directory
))
!=
NULL
);
#endif
}
const
char
*
retro_dirent_get_name
(
struct
RDIR
*
rdir
)
{
#if defined(_WIN32)
return
rdir
->
entry
.
cFileName
;
#elif defined(VITA) || defined(PSP) || defined(__CELLOS_LV2__)
return
rdir
->
entry
.
d_name
;
#else
return
rdir
->
entry
->
d_name
;
#endif
}
/**
*
* retro_dirent_is_dir:
* @rdir : pointer to the directory entry.
* @path : path to the directory entry.
*
* Is the directory listing entry a directory?
*
* Returns: true if directory listing entry is
* a directory, false if not.
*/
bool
retro_dirent_is_dir
(
struct
RDIR
*
rdir
,
const
char
*
path
)
{
#if defined(_WIN32)
const
WIN32_FIND_DATA
*
entry
=
(
const
WIN32_FIND_DATA
*
)
rdir
->
entry
;
return
entry
->
dwFileAttributes
&
FILE_ATTRIBUTE_DIRECTORY
;
#elif defined(PSP) || defined(VITA)
const
SceIoDirent
*
entry
=
(
const
SceIoDirent
*
)
&
rdir
->
entry
;
#if defined(PSP)
return
(
entry
->
d_stat
.
st_attr
&
FIO_SO_IFDIR
)
==
FIO_SO_IFDIR
;
#elif defined(VITA)
return
PSP2_S_ISDIR
(
entry
->
d_stat
.
st_mode
);
#endif
#elif defined(__CELLOS_LV2__)
CellFsDirent
*
entry
=
(
CellFsDirent
*
)
&
rdir
->
entry
;
return
(
entry
->
d_type
==
CELL_FS_TYPE_DIRECTORY
);
#elif defined(DT_DIR)
const
struct
dirent
*
entry
=
(
const
struct
dirent
*
)
rdir
->
entry
;
if
(
entry
->
d_type
==
DT_DIR
)
return
true
;
else
if
(
entry
->
d_type
==
DT_UNKNOWN
/* This can happen on certain file systems. */
||
entry
->
d_type
==
DT_LNK
)
{
struct
stat
buf
;
if
(
stat
(
path
,
&
buf
)
<
0
)
return
false
;
return
S_ISDIR
(
buf
.
st_mode
);
}
return
false
;
#else
/* dirent struct doesn't have d_type, do it the slow way ... */
struct
stat
buf
;
if
(
stat
(
path
,
&
buf
)
<
0
)
return
false
;
return
S_ISDIR
(
buf
.
st_mode
);
#endif
}
void
retro_closedir
(
struct
RDIR
*
rdir
)
{
if
(
!
rdir
)
return
;
#if defined(_WIN32)
if
(
rdir
->
directory
!=
INVALID_HANDLE_VALUE
)
FindClose
(
rdir
->
directory
);
#elif defined(VITA) || defined(PSP)
sceIoDclose
(
rdir
->
directory
);
#elif defined(__CELLOS_LV2__)
rdir
->
error
=
cellFsClosedir
(
rdir
->
directory
);
#else
if
(
rdir
->
directory
)
closedir
(
rdir
->
directory
);
#endif
free
(
rdir
);
}
libretro-common/include/boolean.h
0 → 100644
View file @
2a7746f2
/* Copyright (C) 2010-2015 The RetroArch team
*
* ---------------------------------------------------------------------------------------
* The following license statement only applies to this file (boolean.h).
* ---------------------------------------------------------------------------------------
*
* Permission is hereby granted, free of charge,
* to any person obtaining a copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation the rights to
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software,
* and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
* INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#ifndef __LIBRETRO_SDK_BOOLEAN_H
#define __LIBRETRO_SDK_BOOLEAN_H
#ifndef __cplusplus
#if defined(_MSC_VER) && !defined(SN_TARGET_PS3)
/* Hack applied for MSVC when compiling in C89 mode as it isn't C99 compliant. */
#define bool unsigned char
#define true 1
#define false 0
#else
#include <stdbool.h>
#endif
#endif
#endif
libretro-common/include/retro_dirent.h
0 → 100644
View file @
2a7746f2
/* Copyright (C) 2010-2015 The RetroArch team
*
* ---------------------------------------------------------------------------------------
* The following license statement only applies to this file (retro_dirent.h).
* ---------------------------------------------------------------------------------------
*
* Permission is hereby granted, free of charge,
* to any person obtaining a copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation the rights to
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software,
* and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
* INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#ifndef __RETRO_DIRENT_H
#define __RETRO_DIRENT_H
#include <boolean.h>
#ifdef __cplusplus
extern
"C"
{
#endif
struct
RDIR
;
struct
RDIR
*
retro_opendir
(
const
char
*
name
);
int
retro_readdir
(
struct
RDIR
*
rdir
);
bool
retro_dirent_error
(
struct
RDIR
*
rdir
);
const
char
*
retro_dirent_get_name
(
struct
RDIR
*
rdir
);
/**
*
* retro_dirent_is_dir:
* @rdir : pointer to the directory entry.
* @path : path to the directory entry.
*
* Is the directory listing entry a directory?
*
* Returns: true if directory listing entry is
* a directory, false if not.
*/
bool
retro_dirent_is_dir
(
struct
RDIR
*
rdir
,
const
char
*
path
);
void
retro_closedir
(
struct
RDIR
*
rdir
);
#ifdef __cplusplus
}
#endif
#endif
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment