Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
V
vlc
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
Commits
e923b2b8
Commit
e923b2b8
authored
Oct 23, 2008
by
Rémi Denis-Courmont
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Code factorization
parent
7477f3c3
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
29 additions
and
93 deletions
+29
-93
src/text/filesystem.c
src/text/filesystem.c
+29
-93
No files found.
src/text/filesystem.c
View file @
e923b2b8
...
@@ -51,6 +51,7 @@
...
@@ -51,6 +51,7 @@
#endif
#endif
#ifdef WIN32
#ifdef WIN32
# include <io.h>
# include <io.h>
# include <direct.h>
#else
#else
# include <unistd.h>
# include <unistd.h>
#endif
#endif
...
@@ -59,19 +60,21 @@
...
@@ -59,19 +60,21 @@
# define lstat( a, b ) stat(a, b)
# define lstat( a, b ) stat(a, b)
#endif
#endif
#ifdef __APPLE__
#ifdef WIN32
/* Define this if the OS always use UTF-8 internally */
static
int
convert_path
(
const
char
*
restrict
path
,
wchar_t
*
restrict
wpath
)
# define ASSUME_UTF8 1
{
#endif
if
(
!
MultiByteToWideChar
(
CP_UTF8
,
0
,
path
,
-
1
,
wpath
,
MAX_PATH
))
{
#if defined (ASSUME_UTF8)
errno
=
ENOENT
;
/* Cool */
return
-
1
;
#elif defined (WIN32) || defined (UNDER_CE)
}
# define USE_MB2MB 1
wpath
[
MAX_PATH
]
=
L'\0'
;
#elif defined (HAVE_ICONV)
return
0
;
# define USE_ICONV 1
}
#else
# define CONVERT_PATH(path, wpath, err) \
# error No UTF8 charset conversion implemented on this platform!
wchar_t wpath[MAX_PATH+1]; \
if (convert_path (path, wpath)) \
return (err)
#endif
#endif
/**
/**
...
@@ -88,20 +91,11 @@ int utf8_open (const char *filename, int flags, mode_t mode)
...
@@ -88,20 +91,11 @@ int utf8_open (const char *filename, int flags, mode_t mode)
/*_open translates to wchar internally on WinCE*/
/*_open translates to wchar internally on WinCE*/
return
_open
(
filename
,
flags
,
mode
);
return
_open
(
filename
,
flags
,
mode
);
#elif defined (WIN32)
#elif defined (WIN32)
/* for Windows NT and above */
wchar_t
wpath
[
MAX_PATH
+
1
];
if
(
!
MultiByteToWideChar
(
CP_UTF8
,
0
,
filename
,
-
1
,
wpath
,
MAX_PATH
))
{
errno
=
ENOENT
;
return
-
1
;
}
wpath
[
MAX_PATH
]
=
L'\0'
;
/*
/*
* open() cannot open files with non-“ANSI” characters on Windows.
* open() cannot open files with non-“ANSI” characters on Windows.
* We use _wopen() instead. Same thing for mkdir() and stat().
* We use _wopen() instead. Same thing for mkdir() and stat().
*/
*/
CONVERT_PATH
(
filename
,
wpath
,
-
1
);
return
_wopen
(
wpath
,
flags
,
mode
);
return
_wopen
(
wpath
,
flags
,
mode
);
#endif
#endif
...
@@ -188,43 +182,10 @@ FILE *utf8_fopen (const char *filename, const char *mode)
...
@@ -188,43 +182,10 @@ FILE *utf8_fopen (const char *filename, const char *mode)
int
utf8_mkdir
(
const
char
*
dirname
,
mode_t
mode
)
int
utf8_mkdir
(
const
char
*
dirname
,
mode_t
mode
)
{
{
#if defined (UNDER_CE) || defined (WIN32)
#if defined (UNDER_CE) || defined (WIN32)
VLC_UNUSED
(
mode
);
(
void
)
mode
;
CONVERT_PATH
(
dirname
,
wpath
,
-
1
);
wchar_t
wname
[
MAX_PATH
+
1
];
return
_wmkdir
(
wpath
);
char
mod
[
MAX_PATH
+
1
];
int
i
;
/* Convert '/' into '\' */
for
(
i
=
0
;
*
dirname
;
i
++
)
{
if
(
i
==
MAX_PATH
)
return
-
1
;
/* overflow */
if
(
*
dirname
==
'/'
)
mod
[
i
]
=
'\\'
;
else
mod
[
i
]
=
*
dirname
;
dirname
++
;
}
mod
[
i
]
=
0
;
if
(
MultiByteToWideChar
(
CP_UTF8
,
0
,
mod
,
-
1
,
wname
,
MAX_PATH
)
==
0
)
{
errno
=
ENOENT
;
return
-
1
;
}
wname
[
MAX_PATH
]
=
L'\0'
;
if
(
CreateDirectoryW
(
wname
,
NULL
)
==
0
)
{
if
(
GetLastError
(
)
==
ERROR_ALREADY_EXISTS
)
errno
=
EEXIST
;
else
errno
=
ENOENT
;
return
-
1
;
}
return
0
;
#else
#else
char
*
locname
=
ToLocale
(
dirname
);
char
*
locname
=
ToLocale
(
dirname
);
int
res
;
int
res
;
...
@@ -251,13 +212,9 @@ int utf8_mkdir( const char *dirname, mode_t mode )
...
@@ -251,13 +212,9 @@ int utf8_mkdir( const char *dirname, mode_t mode )
DIR
*
utf8_opendir
(
const
char
*
dirname
)
DIR
*
utf8_opendir
(
const
char
*
dirname
)
{
{
#ifdef WIN32
#ifdef WIN32
wchar_t
wname
[
MAX_PATH
+
1
];
CONVERT_PATH
(
dirname
,
wpath
,
NULL
);
return
(
DIR
*
)
vlc_wopendir
(
wpath
);
if
(
MultiByteToWideChar
(
CP_UTF8
,
0
,
dirname
,
-
1
,
wname
,
MAX_PATH
))
{
wname
[
MAX_PATH
]
=
L'\0'
;
return
(
DIR
*
)
vlc_wopendir
(
wname
);
}
#else
#else
const
char
*
local_name
=
ToLocale
(
dirname
);
const
char
*
local_name
=
ToLocale
(
dirname
);
...
@@ -399,17 +356,8 @@ static int utf8_statEx( const char *filename, struct stat *buf,
...
@@ -399,17 +356,8 @@ static int utf8_statEx( const char *filename, struct stat *buf,
/*_stat translates to wchar internally on WinCE*/
/*_stat translates to wchar internally on WinCE*/
return
_stat
(
filename
,
buf
);
return
_stat
(
filename
,
buf
);
#elif defined (WIN32)
#elif defined (WIN32)
/* for Windows NT and above */
CONVERT_PATH
(
filename
,
wpath
,
-
1
);
wchar_t
wpath
[
MAX_PATH
+
1
];
return
_wstati64
(
wpath
,
buf
);
if
(
!
MultiByteToWideChar
(
CP_UTF8
,
0
,
filename
,
-
1
,
wpath
,
MAX_PATH
)
)
{
errno
=
ENOENT
;
return
-
1
;
}
wpath
[
MAX_PATH
]
=
L'\0'
;
return
_wstati64
(
wpath
,
buf
);
#endif
#endif
#ifdef HAVE_SYS_STAT_H
#ifdef HAVE_SYS_STAT_H
...
@@ -462,21 +410,9 @@ int utf8_unlink( const char *filename )
...
@@ -462,21 +410,9 @@ int utf8_unlink( const char *filename )
/*_open translates to wchar internally on WinCE*/
/*_open translates to wchar internally on WinCE*/
return
_unlink
(
filename
);
return
_unlink
(
filename
);
#elif defined (WIN32)
#elif defined (WIN32)
/* for Windows NT and above */
CONVERT_PATH
(
filename
,
wpath
,
-
1
);
wchar_t
wpath
[
MAX_PATH
+
1
]
;
return
_wunlink
(
wpath
)
;
if
(
!
MultiByteToWideChar
(
CP_UTF8
,
0
,
filename
,
-
1
,
wpath
,
MAX_PATH
)
)
{
errno
=
ENOENT
;
return
-
1
;
}
wpath
[
MAX_PATH
]
=
L'\0'
;
/*
* unlink() cannot open files with non-“ANSI” characters on Windows.
* We use _wunlink() instead.
*/
return
_wunlink
(
wpath
);
#endif
#endif
const
char
*
local_name
=
ToLocale
(
filename
);
const
char
*
local_name
=
ToLocale
(
filename
);
...
...
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