Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
V
vlc-2-2
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Redmine
Redmine
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Metrics
Environments
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
videolan
vlc-2-2
Commits
ee0b9164
Commit
ee0b9164
authored
Jan 27, 2014
by
Rémi Denis-Courmont
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
vlc_readdir: remove string duplication, simplify
parent
7625fc4b
Changes
13
Show whitespace changes
Inline
Side-by-side
Showing
13 changed files
with
54 additions
and
78 deletions
+54
-78
include/vlc_fs.h
include/vlc_fs.h
+17
-3
modules/access/dvb/scan.c
modules/access/dvb/scan.c
+2
-5
modules/demux/mkv/mkv.cpp
modules/demux/mkv/mkv.cpp
+1
-3
modules/gui/ncurses.c
modules/gui/ncurses.c
+5
-8
modules/gui/skins2/src/theme_loader.cpp
modules/gui/skins2/src/theme_loader.cpp
+2
-7
modules/gui/skins2/src/theme_repository.cpp
modules/gui/skins2/src/theme_repository.cpp
+2
-5
modules/lua/libs/net.c
modules/lua/libs/net.c
+1
-2
src/input/subtitles.c
src/input/subtitles.c
+1
-8
src/modules/bank.c
src/modules/bank.c
+2
-3
src/playlist/art.c
src/playlist/art.c
+1
-2
src/posix/filesystem.c
src/posix/filesystem.c
+3
-2
src/text/filesystem.c
src/text/filesystem.c
+4
-8
src/win32/filesystem.c
src/win32/filesystem.c
+13
-22
No files found.
include/vlc_fs.h
View file @
ee0b9164
...
...
@@ -46,11 +46,25 @@ VLC_API int vlc_rename( const char *oldpath, const char *newpath );
VLC_API
char
*
vlc_getcwd
(
void
)
VLC_USED
;
#if defined( _WIN32 )
typedef
struct
vlc_DIR
{
_WDIR
*
wdir
;
/* MUST be first, see <vlc_fs.h> */
char
*
entry
;
union
{
DWORD
drives
;
bool
insert_dot_dot
;
}
u
;
}
vlc_DIR
;
static
inline
int
vlc_closedir
(
DIR
*
dir
)
{
_WDIR
*
wdir
=
*
(
_WDIR
**
)
dir
;
free
(
dir
);
return
wdir
?
_wclosedir
(
wdir
)
:
0
;
vlc_DIR
*
vdir
=
(
vlc_DIR
*
)
dir
;
_WDIR
*
wdir
=
vdir
->
wdir
;
free
(
vdir
->
entry
);
free
(
vdir
);
return
(
wdir
!=
NULL
)
?
_wclosedir
(
wdir
)
:
0
;
}
# undef closedir
# define closedir vlc_closedir
...
...
modules/access/dvb/scan.c
View file @
ee0b9164
...
...
@@ -271,20 +271,17 @@ static int ScanDvbSNextFast( scan_t *p_scan, scan_configuration_t *p_cfg, double
/* find the requested file in the directory */
for
(
;
;
)
{
c
har
*
psz_filename
;
c
onst
char
*
psz_filename
=
vlc_readdir
(
p_dir
)
;
if
(
!
(
psz_filename
=
vlc_readdir
(
p_dir
)
)
)
if
(
psz_filename
==
NULL
)
break
;
if
(
!
strncmp
(
p_scan
->
parameter
.
sat_info
.
psz_name
,
psz_filename
,
20
)
)
{
if
(
asprintf
(
&
p_scan
->
parameter
.
sat_info
.
psz_path
,
"%s"
DIR_SEP
"%s"
,
psz_dir
,
psz_filename
)
==
-
1
)
p_scan
->
parameter
.
sat_info
.
psz_path
=
NULL
;
free
(
psz_filename
);
break
;
}
free
(
psz_filename
);
}
closedir
(
p_dir
);
...
...
modules/demux/mkv/mkv.cpp
View file @
ee0b9164
...
...
@@ -166,7 +166,7 @@ static int Open( vlc_object_t * p_this )
if
(
p_src_dir
!=
NULL
)
{
char
*
psz_file
;
c
onst
c
har
*
psz_file
;
while
((
psz_file
=
vlc_readdir
(
p_src_dir
))
!=
NULL
)
{
if
(
strlen
(
psz_file
)
>
4
)
...
...
@@ -179,7 +179,6 @@ static int Open( vlc_object_t * p_this )
if
(
!
s_filename
.
compare
(
p_demux
->
psz_file
))
#endif
{
free
(
psz_file
);
continue
;
// don't reuse the original opened file
}
...
...
@@ -229,7 +228,6 @@ static int Open( vlc_object_t * p_this )
}
}
}
free
(
psz_file
);
}
closedir
(
p_src_dir
);
}
...
...
modules/gui/ncurses.c
View file @
ee0b9164
...
...
@@ -287,23 +287,20 @@ static void ReadDir(intf_thread_t *intf)
DirsDestroy
(
sys
);
char
*
entry
;
c
onst
c
har
*
entry
;
while
((
entry
=
vlc_readdir
(
current_dir
)))
{
if
(
!
sys
->
show_hidden_files
&&
*
entry
==
'.'
&&
strcmp
(
entry
,
".."
))
goto
next
;
continue
;
struct
dir_entry_t
*
dir_entry
=
malloc
(
sizeof
*
dir_entry
);
if
(
!
dir_entry
)
goto
next
;
if
(
unlikely
(
dir_entry
==
NULL
)
)
continue
;
dir_entry
->
file
=
IsFile
(
sys
->
current_dir
,
entry
);
dir_entry
->
path
=
entry
;
dir_entry
->
path
=
xstrdup
(
entry
)
;
INSERT_ELEM
(
sys
->
dir_entries
,
sys
->
n_dir_entries
,
sys
->
n_dir_entries
,
dir_entry
);
continue
;
next:
free
(
entry
);
}
qsort
(
sys
->
dir_entries
,
sys
->
n_dir_entries
,
...
...
modules/gui/skins2/src/theme_loader.cpp
View file @
ee0b9164
...
...
@@ -392,11 +392,10 @@ bool ThemeLoader::findFile( const string &rootDir, const string &rFileName,
// Path separator
const
string
&
sep
=
OSFactory
::
instance
(
getIntf
()
)
->
getDirSeparator
();
DIR
*
pCurrDir
;
char
*
pszDirContent
;
const
char
*
pszDirContent
;
// Open the dir
pCurrDir
=
vlc_opendir
(
rootDir
.
c_str
()
);
DIR
*
pCurrDir
=
vlc_opendir
(
rootDir
.
c_str
()
);
if
(
pCurrDir
==
NULL
)
{
...
...
@@ -428,7 +427,6 @@ bool ThemeLoader::findFile( const string &rootDir, const string &rFileName,
// Can we find the file in this subdirectory?
if
(
findFile
(
newURI
,
rFileName
,
themeFilePath
)
)
{
free
(
pszDirContent
);
closedir
(
pCurrDir
);
return
true
;
}
...
...
@@ -439,14 +437,11 @@ bool ThemeLoader::findFile( const string &rootDir, const string &rFileName,
if
(
rFileName
==
string
(
pszDirContent
)
)
{
themeFilePath
=
newURI
;
free
(
pszDirContent
);
closedir
(
pCurrDir
);
return
true
;
}
}
}
free
(
pszDirContent
);
}
closedir
(
pCurrDir
);
...
...
modules/gui/skins2/src/theme_repository.cpp
View file @
ee0b9164
...
...
@@ -136,15 +136,14 @@ ThemeRepository::~ThemeRepository()
void
ThemeRepository
::
parseDirectory
(
const
string
&
rDir_locale
)
{
DIR
*
pDir
;
char
*
pszDirContent
;
const
char
*
pszDirContent
;
// Path separator
const
string
&
sep
=
OSFactory
::
instance
(
getIntf
()
)
->
getDirSeparator
();
// Open the dir
// FIXME: parseDirectory should be invoked with UTF-8 input instead!!
string
rDir
=
sFromLocale
(
rDir_locale
);
pDir
=
vlc_opendir
(
rDir
.
c_str
()
);
DIR
*
pDir
=
vlc_opendir
(
rDir
.
c_str
()
);
if
(
pDir
==
NULL
)
{
...
...
@@ -174,8 +173,6 @@ void ThemeRepository::parseDirectory( const string &rDir_locale )
msg_Dbg
(
getIntf
(),
"found skin %s"
,
path
.
c_str
()
);
}
free
(
pszDirContent
);
}
closedir
(
pDir
);
...
...
modules/lua/libs/net.c
View file @
ee0b9164
...
...
@@ -477,12 +477,11 @@ static int vlclua_opendir( lua_State *L )
lua_newtable
(
L
);
for
(
;;
)
{
char
*
psz_filename
=
vlc_readdir
(
p_dir
);
c
onst
c
har
*
psz_filename
=
vlc_readdir
(
p_dir
);
if
(
!
psz_filename
)
break
;
i
++
;
lua_pushstring
(
L
,
psz_filename
);
lua_rawseti
(
L
,
-
2
,
i
);
free
(
psz_filename
);
}
closedir
(
p_dir
);
return
1
;
...
...
src/input/subtitles.c
View file @
ee0b9164
...
...
@@ -312,14 +312,11 @@ char **subtitles_Detect( input_thread_t *p_this, char *psz_path,
msg_Dbg
(
p_this
,
"looking for a subtitle file in %s"
,
psz_dir
);
char
*
psz_name
;
c
onst
c
har
*
psz_name
;
while
(
(
psz_name
=
vlc_readdir
(
dir
))
&&
i_sub_count
<
MAX_SUBTITLE_FILES
)
{
if
(
psz_name
[
0
]
==
'.'
||
!
subtitles_Filter
(
psz_name
)
)
{
free
(
psz_name
);
continue
;
}
char
tmp_fname_noext
[
strlen
(
psz_name
)
+
1
];
char
tmp_fname_trim
[
strlen
(
psz_name
)
+
1
];
...
...
@@ -365,10 +362,7 @@ char **subtitles_Detect( input_thread_t *p_this, char *psz_path,
sprintf
(
psz_path
,
"%s"
DIR_SEP
"%s"
,
psz_dir
,
psz_name
);
if
(
!
strcmp
(
psz_path
,
psz_fname
)
)
{
free
(
psz_name
);
continue
;
}
if
(
!
vlc_stat
(
psz_path
,
&
st
)
&&
S_ISREG
(
st
.
st_mode
)
&&
result
)
{
...
...
@@ -386,7 +380,6 @@ char **subtitles_Detect( input_thread_t *p_this, char *psz_path,
psz_path
,
i_prio
);
}
}
free
(
psz_name
);
}
closedir
(
dir
);
}
...
...
src/modules/bank.c
View file @
ee0b9164
...
...
@@ -444,7 +444,7 @@ static void AllocatePluginDir (module_bank_t *bank, unsigned maxdepth,
/* Skip ".", ".." */
if
(
!
strcmp
(
file
,
"."
)
||
!
strcmp
(
file
,
".."
))
goto
skip
;
continue
;
/* Compute path relative to plug-in base directory */
if
(
reldir
!=
NULL
)
...
...
@@ -455,7 +455,7 @@ static void AllocatePluginDir (module_bank_t *bank, unsigned maxdepth,
else
relpath
=
strdup
(
file
);
if
(
unlikely
(
relpath
==
NULL
))
goto
skip
;
continue
;
/* Compute absolute path */
if
(
asprintf
(
&
abspath
,
"%s"
DIR_SEP
"%s"
,
bank
->
base
,
relpath
)
==
-
1
)
...
...
@@ -493,7 +493,6 @@ static void AllocatePluginDir (module_bank_t *bank, unsigned maxdepth,
skip:
free
(
relpath
);
free
(
abspath
);
free
(
file
);
}
closedir
(
dh
);
}
...
...
src/playlist/art.c
View file @
ee0b9164
...
...
@@ -173,7 +173,7 @@ int playlist_FindArtInCache( input_item_t *p_item )
}
bool
b_found
=
false
;
char
*
psz_filename
;
c
onst
c
har
*
psz_filename
;
while
(
!
b_found
&&
(
psz_filename
=
vlc_readdir
(
p_dir
))
)
{
if
(
!
strncmp
(
psz_filename
,
"art"
,
3
)
)
...
...
@@ -193,7 +193,6 @@ int playlist_FindArtInCache( input_item_t *p_item )
b_found
=
true
;
}
free
(
psz_filename
);
}
/* */
...
...
src/posix/filesystem.c
View file @
ee0b9164
...
...
@@ -145,14 +145,15 @@ DIR *vlc_opendir (const char *dirname)
* @param dir directory handle as returned by vlc_opendir()
* (must not be used by another thread concurrently)
*
* @return a UTF-8 string of the directory entry. Use free() to release it.
* @return a UTF-8 string of the directory entry. The string is valid until
* the next call to vlc_readdir() or closedir() on the handle.
* If there are no more entries in the directory, NULL is returned.
* If an error occurs, errno is set and NULL is returned.
*/
char
*
vlc_readdir
(
DIR
*
dir
)
{
struct
dirent
*
ent
=
readdir
(
dir
);
return
(
ent
!=
NULL
)
?
strdup
(
ent
->
d_name
)
:
NULL
;
return
(
ent
!=
NULL
)
?
ent
->
d_name
:
NULL
;
}
/**
...
...
src/text/filesystem.c
View file @
ee0b9164
...
...
@@ -127,7 +127,7 @@ int vlc_loaddir( DIR *dir, char ***namelist,
for
(
unsigned
size
=
0
;;)
{
errno
=
0
;
char
*
entry
=
vlc_readdir
(
dir
);
c
onst
c
har
*
entry
=
vlc_readdir
(
dir
);
if
(
entry
==
NULL
)
{
if
(
errno
)
...
...
@@ -136,10 +136,7 @@ int vlc_loaddir( DIR *dir, char ***namelist,
}
if
(
!
select
(
entry
))
{
free
(
entry
);
continue
;
}
if
(
num
>=
size
)
{
...
...
@@ -147,14 +144,13 @@ int vlc_loaddir( DIR *dir, char ***namelist,
char
**
newtab
=
realloc
(
tab
,
sizeof
(
*
tab
)
*
(
size
));
if
(
unlikely
(
newtab
==
NULL
))
{
free
(
entry
);
goto
error
;
}
tab
=
newtab
;
}
tab
[
num
++
]
=
entry
;
tab
[
num
]
=
strdup
(
entry
);
if
(
likely
(
tab
[
num
]
!=
NULL
))
num
++
;
}
if
(
compar
!=
NULL
)
...
...
src/win32/filesystem.c
View file @
ee0b9164
...
...
@@ -129,17 +129,6 @@ char *vlc_getcwd (void)
/* Under Windows, these wrappers return the list of drive letters
* when called with an empty argument or just '\'. */
typedef
struct
vlc_DIR
{
_WDIR
*
wdir
;
/* MUST be first, see <vlc_fs.h> */
union
{
DWORD
drives
;
bool
insert_dot_dot
;
}
u
;
}
vlc_DIR
;
DIR
*
vlc_opendir
(
const
char
*
dirname
)
{
wchar_t
*
wpath
=
widen_path
(
dirname
);
...
...
@@ -175,6 +164,7 @@ DIR *vlc_opendir (const char *dirname)
return
NULL
;
}
p_dir
->
wdir
=
wdir
;
p_dir
->
entry
=
NULL
;
return
(
void
*
)
p_dir
;
}
...
...
@@ -182,6 +172,8 @@ char *vlc_readdir (DIR *dir)
{
vlc_DIR
*
p_dir
=
(
vlc_DIR
*
)
dir
;
free
(
p_dir
->
entry
);
#if !VLC_WINSTORE_APP
/* Drive letters mode */
if
(
p_dir
->
wdir
==
NULL
)
...
...
@@ -196,24 +188,23 @@ char *vlc_readdir (DIR *dir)
p_dir
->
u
.
drives
&=
~
(
1UL
<<
i
);
assert
(
i
<
26
);
char
*
ret
;
if
(
asprintf
(
&
ret
,
"%c:
\\
"
,
'A'
+
i
)
==
-
1
)
return
NULL
;
return
ret
;
if
(
asprintf
(
&
p_dir
->
entry
,
"%c:
\\
"
,
'A'
+
i
)
==
-
1
)
p_dir
->
entry
=
NULL
;
}
else
#endif
if
(
p_dir
->
u
.
insert_dot_dot
)
{
/* Adds "..", gruik! */
p_dir
->
u
.
insert_dot_dot
=
false
;
return
strdup
(
".."
);
p_dir
->
entry
=
strdup
(
".."
);
}
else
{
struct
_wdirent
*
ent
=
_wreaddir
(
p_dir
->
wdir
);
if
(
ent
==
NULL
)
return
NULL
;
return
FromWide
(
ent
->
d_name
)
;
p_dir
->
entry
=
(
ent
!=
NULL
)
?
FromWide
(
ent
->
d_name
)
:
NULL
;
}
return
p_dir
->
entry
;
}
int
vlc_stat
(
const
char
*
filename
,
struct
stat
*
buf
)
...
...
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