libaacs | branch: master | npzacs <npz...@gmail.com> | Wed May 6 12:48:31 2015 +0300| [aa0bbd7a0020bb3ac00a3cd1546feba66f6d8261] | committer: npzacs
Split file_posix.c > http://git.videolan.org/gitweb.cgi/libaacs.git/?a=commit;h=aa0bbd7a0020bb3ac00a3cd1546feba66f6d8261 --- Makefile.am | 5 ++- src/file/file_posix.c | 20 --------- src/file/file_win32.c | 114 +++++++++++++++++++++++++++++++++++++++++++++++++ src/file/filesystem.c | 32 ++++++++++++++ 4 files changed, 150 insertions(+), 21 deletions(-) diff --git a/Makefile.am b/Makefile.am index c624ab1..cd25143 100644 --- a/Makefile.am +++ b/Makefile.am @@ -23,7 +23,7 @@ libaacs_la_SOURCES=\ src/file/dirs.h \ src/file/file.h \ src/file/filesystem.h \ - src/file/file_posix.c \ + src/file/filesystem.c \ src/file/keydbcfg.c \ src/file/keydbcfg.h \ src/file/keydb.h \ @@ -44,15 +44,18 @@ EXTRA_libaacs_la_SOURCES=\ if HAVE_DARWIN libaacs_la_SOURCES+= \ src/file/dirs_darwin.c \ + src/file/file_posix.c \ src/file/mmc_device_darwin.c else if HAVE_WIN32 libaacs_la_SOURCES+= \ src/file/dirs_win32.c \ + src/file/file_win32.c \ src/file/mmc_device_win32.c else libaacs_la_SOURCES+= \ src/file/dirs_xdg.c \ + src/file/file_posix.c \ src/file/mmc_device_linux.c \ src/file/path.c endif diff --git a/src/file/file_posix.c b/src/file/file_posix.c index 6b5a0cd..0d48f51 100644 --- a/src/file/file_posix.c +++ b/src/file/file_posix.c @@ -21,11 +21,6 @@ #include "config.h" #endif -#if defined(__MINGW32__) -/* ftello64() and fseeko64() prototypes from stdio.h */ -# undef __STRICT_ANSI__ -#endif - #include "file.h" #include "util/macro.h" #include "util/logging.h" @@ -47,20 +42,12 @@ static void file_close_linux(AACS_FILE_H *file) static int64_t file_seek_linux(AACS_FILE_H *file, int64_t offset, int32_t origin) { -#if defined(__MINGW32__) - return fseeko64((FILE *)file->internal, offset, origin); -#else return fseeko((FILE *)file->internal, offset, origin); -#endif } static int64_t file_tell_linux(AACS_FILE_H *file) { -#if defined(__MINGW32__) - return ftello64((FILE *)file->internal); -#else return ftello((FILE *)file->internal); -#endif } static int64_t file_read_linux(AACS_FILE_H *file, uint8_t *buf, int64_t size) @@ -98,10 +85,3 @@ static AACS_FILE_H *file_open_linux(const char* filename, const char *mode) } AACS_FILE_H* (*file_open)(const char* filename, const char *mode) = file_open_linux; - -AACS_FILE_OPEN aacs_register_file(AACS_FILE_OPEN p) -{ - AACS_FILE_OPEN old = file_open; - file_open = p; - return old; -} diff --git a/src/file/file_win32.c b/src/file/file_win32.c new file mode 100644 index 0000000..c8d60ab --- /dev/null +++ b/src/file/file_win32.c @@ -0,0 +1,114 @@ +/* + * This file is part of libaacs + * Copyright (C) 2009-2010 Obliter0n + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library. If not, see + * <http://www.gnu.org/licenses/>. + */ + +#if HAVE_CONFIG_H +#include "config.h" +#endif + +#if defined(__MINGW32__) +/* ftello64() and fseeko64() prototypes from stdio.h */ +# undef __STRICT_ANSI__ +#endif + +#include "file.h" +#include "util/macro.h" +#include "util/logging.h" + +#include <stdio.h> +#include <stdlib.h> +#include <inttypes.h> + +#include <windows.h> + +static void _file_close(AACS_FILE_H *file) +{ + if (file) { + fclose((FILE *)file->internal); + + BD_DEBUG(DBG_FILE, "Closed WIN32 file (%p)\n", (void*)file); + + X_FREE(file); + } +} + +static int64_t _file_seek(AACS_FILE_H *file, int64_t offset, int32_t origin) +{ +#if defined(__MINGW32__) + return fseeko64((FILE *)file->internal, offset, origin); +#else + return _fseeki64((FILE *)file->internal, offset, origin); +#endif +} + +static int64_t _file_tell(AACS_FILE_H *file) +{ +#if defined(__MINGW32__) + return ftello64((FILE *)file->internal); +#else + return _ftelli64((FILE *)file->internal); +#endif +} + +static int64_t _file_read(AACS_FILE_H *file, uint8_t *buf, int64_t size) +{ + if (size > 0 && size < BD_MAX_SSIZE) { + return (int64_t)fread(buf, 1, (size_t)size, (FILE *)file->internal); + } + + BD_DEBUG(DBG_FILE | DBG_CRIT, "Ignoring invalid read of size %"PRId64" (%p)\n", size, (void*)file); + return 0; +} + +static AACS_FILE_H *_file_open(const char* filename, const char *mode) +{ + AACS_FILE_H *file; + FILE *fp; + wchar_t wfilename[MAX_PATH], wmode[8]; + + if (!MultiByteToWideChar(CP_UTF8, MB_ERR_INVALID_CHARS, filename, -1, wfilename, MAX_PATH) || + !MultiByteToWideChar(CP_UTF8, MB_ERR_INVALID_CHARS, mode, -1, wmode, 8)) { + + BD_DEBUG(DBG_FILE, "Error opening file %s\n", filename); + return NULL; + } + + fp = _wfopen(wfilename, wmode); + if (!fp) { + BD_DEBUG(DBG_FILE, "Error opening file %s\n", filename); + return NULL; + } + + file = calloc(1, sizeof(AACS_FILE_H)); + if (!file) { + BD_DEBUG(DBG_FILE | DBG_CRIT, "Error opening file %s (out of memory)\n", filename); + fclose(fp); + return NULL; + } + + file->internal = fp; + file->close = _file_close; + file->seek = _file_seek; + file->read = _file_read; + file->tell = _file_tell; + + BD_DEBUG(DBG_FILE, "Opened WIN32 file %s (%p)\n", filename, (void*)file); + return file; +} + +AACS_FILE_H* (*file_open)(const char* filename, const char *mode) = _file_open; diff --git a/src/file/filesystem.c b/src/file/filesystem.c new file mode 100644 index 0000000..434c5e6 --- /dev/null +++ b/src/file/filesystem.c @@ -0,0 +1,32 @@ +/* + * This file is part of libaacs + * Copyright (C) 2009-2010 Obliter0n + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library. If not, see + * <http://www.gnu.org/licenses/>. + */ + +#if HAVE_CONFIG_H +#include "config.h" +#endif + +#include "file.h" + + +AACS_FILE_OPEN aacs_register_file(AACS_FILE_OPEN p) +{ + AACS_FILE_OPEN old = file_open; + file_open = p; + return old; +} _______________________________________________ libaacs-devel mailing list libaacs-devel@videolan.org https://mailman.videolan.org/listinfo/libaacs-devel