libaacs | branch: master | Konstantin Pavlov <[email protected]> | Fri Aug 17 12:40:18 2012 +0400| [584f6c090a6a8eadcbbbf1074536036df693b425] | committer: Ano Nymous
Use proper paths to search for keydb and friends on Darwin. > http://git.videolan.org/gitweb.cgi/libaacs.git/?a=commit;h=584f6c090a6a8eadcbbbf1074536036df693b425 --- configure.ac | 2 ++ src/Makefile.am | 6 ++++ src/file/darwin.c | 95 +++++++++++++++++++++++++++++++++++++++++++++++++++ src/file/darwin.h | 29 ++++++++++++++++ src/file/keydbcfg.c | 17 +++++---- 5 files changed, 143 insertions(+), 6 deletions(-) diff --git a/configure.ac b/configure.ac index ab1e622..a32f403 100644 --- a/configure.ac +++ b/configure.ac @@ -46,6 +46,7 @@ case "${host_os}" in esac ;; *darwin*) + SYS=darwin AC_DEFINE([USE_IOKIT], 1, [Use IOKit for MMC access]) LDFLAGS="${LDFLAGS} -lobjc -Wl,-framework,IOKit,-framework,Cocoa,-framework,DiskArbitration" SET_FEATURES="${SET_FEATURES} -D_DARWIN_C_SOURCE" @@ -56,6 +57,7 @@ case "${host_os}" in esac AM_CONDITIONAL(HAVE_WIN32, test "${SYS}" = "mingw32") +AM_CONDITIONAL(HAVE_DARWIN, test "${SYS}" = "darwin") # messages library_not_found="Could not find required library!" diff --git a/src/Makefile.am b/src/Makefile.am index 471bb8b..9b6e782 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -40,6 +40,11 @@ libaacs_la_SOURCES=\ EXTRA_libaacs_la_SOURCES=\ libaacs/ec.c +if HAVE_DARWIN +libaacs_la_SOURCES+= \ + file/darwin.c \ + file/darwin.h +else if HAVE_WIN32 libaacs_la_SOURCES+= \ file/win32.c \ @@ -49,6 +54,7 @@ libaacs_la_SOURCES+= \ file/xdg.c \ file/xdg.h endif +endif libaacs_ladir= $(includedir)/libaacs libaacs_la_HEADERS= libaacs/aacs.h file/filesystem.h libaacs/aacs-version.h diff --git a/src/file/darwin.c b/src/file/darwin.c new file mode 100644 index 0000000..ed0fd7d --- /dev/null +++ b/src/file/darwin.c @@ -0,0 +1,95 @@ +/* + * This file is part of libaacs + * Copyright (C) 2012 Konstantin Pavlov + * + * 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/>. + */ + +#include "darwin.h" + +#include <CoreFoundation/CoreFoundation.h> + +#include <stdio.h> +#include <stdlib.h> +#include <string.h> + +#include "util/strutl.h" +#include "util/logging.h" + +#define USER_CFG_DIR "Library/Preferences" +#define USER_CACHE_DIR "Library/Caches" +#define SYSTEM_CFG_DIR "/Library/Preferences" + + +const char *darwin_get_config_home(void) +{ + static char *dir = NULL; + static int init_done = 0; + + if (!init_done) { + init_done = 1; + + const char *user_home = getenv("HOME"); + if (user_home && *user_home) { + return dir = str_printf("%s/%s", user_home, USER_CFG_DIR); + } + + DEBUG(DBG_FILE, "Can't find user home directory ($HOME) !\n"); + } + + return dir; +} + +const char *darwin_get_cache_home(void) +{ + static char *dir = NULL; + static int init_done = 0; + + if (!init_done) { + init_done = 1; + + const char *user_home = getenv("HOME"); + if (user_home && *user_home) { + return dir = str_printf("%s/%s", user_home, USER_CACHE_DIR); + } + + DEBUG(DBG_FILE, "Can't find user home directory ($HOME) !\n"); + } + + return dir; +} + +const char *darwin_get_config_system(const char *dir) +{ + static char *dirs = NULL; // "dir1\0dir2\0...\0dirN\0\0" + + if (!dirs) { + dirs = str_printf("%s%c%c", SYSTEM_CFG_DIR, 0, 0); + } + + if (!dir) { + // first call + dir = dirs; + } else { + // next call + dir += strlen(dir) + 1; + if (!*dir) { + // end of list + dir = NULL; + } + } + + return dir; +} diff --git a/src/file/darwin.h b/src/file/darwin.h new file mode 100644 index 0000000..87384e7 --- /dev/null +++ b/src/file/darwin.h @@ -0,0 +1,29 @@ +/* + * This file is part of libaacs + * Copyright (C) 2012 Konstantin Pavlov + * + * 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/>. + */ + +#ifndef AACS_DARWIN_H +#define AACS_DARWIN_H + +#include <util/attributes.h> + +AACS_PRIVATE const char *darwin_get_config_home(void); +AACS_PRIVATE const char *darwin_get_config_system(const char *dir); +AACS_PRIVATE const char *darwin_get_cache_home(void); + +#endif diff --git a/src/file/keydbcfg.c b/src/file/keydbcfg.c index bd40040..b31950d 100644 --- a/src/file/keydbcfg.c +++ b/src/file/keydbcfg.c @@ -19,16 +19,21 @@ #include "keydbcfg.h" -#ifndef _WIN32 -# include "xdg.h" -# define get_config_home xdg_get_config_home -# define get_cache_home xdg_get_cache_home -# define get_config_system xdg_get_config_system -#else +#if defined(__APPLE__) +# include "darwin.h" +# define get_config_home darwin_get_config_home +# define get_cache_home darwin_get_cache_home +# define get_config_system darwin_get_config_system +#elif defined(_WIN32) # include "win32.h" # define get_config_home win32_get_config_home # define get_cache_home win32_get_config_home # define get_config_system win32_get_config_system +#else +# include "xdg.h" +# define get_config_home xdg_get_config_home +# define get_cache_home xdg_get_cache_home +# define get_config_system xdg_get_config_system #endif #include "util/strutl.h" _______________________________________________ libaacs-devel mailing list [email protected] http://mailman.videolan.org/listinfo/libaacs-devel
