Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
Jean-Baptiste Kempf
libaacs
Commits
946811b6
Commit
946811b6
authored
Feb 22, 2016
by
npzacs
Browse files
Merge file_mkdirs() from libbluray
parent
aaec3fbb
Changes
4
Hide whitespace changes
Inline
Side-by-side
src/file/file.c
View file @
946811b6
...
...
@@ -23,7 +23,12 @@
#include
"file.h"
#include
"util/logging.h"
#include
"util/macro.h"
#include
"util/strutl.h"
#include
<stdio.h>
// SEEK_*
#include
<string.h>
// strchr
int64_t
file_size
(
AACS_FILE_H
*
fp
)
...
...
@@ -39,3 +44,50 @@ int64_t file_size(AACS_FILE_H *fp)
return
length
;
}
int
file_mkdirs
(
const
char
*
path
)
{
int
result
=
0
;
char
*
dir
=
str_dup
(
path
);
char
*
end
=
dir
;
char
*
p
;
if
(
!
dir
)
{
return
-
1
;
}
/* strip file name */
if
(
!
(
end
=
strrchr
(
end
,
DIR_SEP_CHAR
)))
{
X_FREE
(
dir
);
return
-
1
;
}
*
end
=
0
;
/* tokenize, stop to first existing dir */
while
((
p
=
strrchr
(
dir
,
DIR_SEP_CHAR
)))
{
if
(
!
file_path_exists
(
dir
))
{
break
;
}
*
p
=
0
;
}
/* create missing dirs */
p
=
dir
;
while
(
p
<
end
)
{
/* concatenate next non-existing dir */
while
(
*
p
)
p
++
;
if
(
p
>=
end
)
break
;
*
p
=
DIR_SEP_CHAR
;
result
=
file_mkdir
(
dir
);
if
(
result
<
0
)
{
BD_DEBUG
(
DBG_FILE
|
DBG_CRIT
,
"Error creating directory %s
\n
"
,
dir
);
break
;
}
BD_DEBUG
(
DBG_FILE
,
" created directory %s
\n
"
,
dir
);
}
X_FREE
(
dir
);
return
result
;
}
src/file/file.h
View file @
946811b6
...
...
@@ -51,6 +51,8 @@ BD_PRIVATE extern AACS_FILE_H *(*file_open)(const char* filename, const char *mo
*/
BD_PRIVATE
int
file_unlink
(
const
char
*
file
);
BD_PRIVATE
int
file_path_exists
(
const
char
*
path
);
BD_PRIVATE
int
file_mkdir
(
const
char
*
dir
);
BD_PRIVATE
int
file_mkdirs
(
const
char
*
path
);
#endif
/* FILE_H_ */
src/file/file_posix.c
View file @
946811b6
...
...
@@ -139,6 +139,12 @@ int file_unlink(const char *file)
return
remove
(
file
);
}
int
file_path_exists
(
const
char
*
path
)
{
struct
stat
s
;
return
stat
(
path
,
&
s
);
}
int
file_mkdir
(
const
char
*
dir
)
{
return
mkdir
(
dir
,
S_IRWXU
);
...
...
src/file/file_win32.c
View file @
946811b6
...
...
@@ -121,6 +121,19 @@ int file_unlink(const char *file)
return
_wremove
(
wfile
);
}
int
file_path_exists
(
const
char
*
path
)
{
wchar_t
wpath
[
MAX_PATH
];
MultiByteToWideChar
(
CP_UTF8
,
0
,
path
,
-
1
,
wpath
,
MAX_PATH
);
DWORD
dwAttrib
=
GetFileAttributesW
(
wpath
);
if
(
dwAttrib
!=
INVALID_FILE_ATTRIBUTES
)
{
return
0
;
}
return
-
1
;
}
int
file_mkdir
(
const
char
*
dir
)
{
wchar_t
wdir
[
MAX_PATH
];
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new 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