Commit f2968ae9883dbc866c7ee463457d3b4978115646

Authored by Perry Werneck
1 parent 1ae93975
Exists in master and in 2 other branches develop, macos

Restoring detection of MAC datadir.

Showing 1 changed file with 39 additions and 26 deletions   Show diff stats
src/core/macos/util.c
  1 +/* SPDX-License-Identifier: LGPL-3.0-or-later */
  2 +
1 3 /*
2   - * "Software pw3270, desenvolvido com base nos códigos fontes do WC3270 e X3270
3   - * (Paul Mattes Paul.Mattes@usa.net), de emulação de terminal 3270 para acesso a
4   - * aplicativos mainframe. Registro no INPI sob o nome G3270. Registro no INPI sob
5   - * o nome G3270.
6   - *
7   - * Copyright (C) <2008> <Banco do Brasil S.A.>
8   - *
9   - * Este programa é software livre. Você pode redistribuí-lo e/ou modificá-lo sob
10   - * os termos da GPL v.2 - Licença Pública Geral GNU, conforme publicado pela
11   - * Free Software Foundation.
12   - *
13   - * Este programa é distribuído na expectativa de ser útil, mas SEM QUALQUER
14   - * GARANTIA; sem mesmo a garantia implícita de COMERCIALIZAÇÃO ou de ADEQUAÇÃO
15   - * A QUALQUER PROPÓSITO EM PARTICULAR. Consulte a Licença Pública Geral GNU para
16   - * obter mais detalhes.
17   - *
18   - * Você deve ter recebido uma cópia da Licença Pública Geral GNU junto com este
19   - * programa; se não, escreva para a Free Software Foundation, Inc., 51 Franklin
20   - * St, Fifth Floor, Boston, MA 02110-1301 USA
21   - *
22   - * Este programa está nomeado como - e possui - linhas de código.
  4 + * Copyright (C) 2008 Banco do Brasil S.A.
23 5 *
24   - * Contatos:
  6 + * This program is free software: you can redistribute it and/or modify
  7 + * it under the terms of the GNU Lesser General Public License as published
  8 + * by the Free Software Foundation, either version 3 of the License, or
  9 + * (at your option) any later version.
25 10 *
26   - * perry.werneck@gmail.com (Alexandre Perry de Souza Werneck)
27   - * erico.mendonca@gmail.com (Erico Mascarenhas Mendonça)
  11 + * This program is distributed in the hope that it will be useful,
  12 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14 + * GNU General Public License for more details.
28 15 *
  16 + * You should have received a copy of the GNU Lesser General Public License
  17 + * along with this program. If not, see <https://www.gnu.org/licenses/>.
29 18 */
30 19  
31 20 /**
32   - * @brief Linux Utility functions.
  21 + * @brief Mac Utility functions.
33 22 */
34 23  
35 24  
36 25 #include <config.h>
37 26 #include <stdarg.h>
38 27 #include <internals.h>
  28 +#include <unistd.h>
  29 +#include <CoreFoundation/CFBundle.h>
  30 +#include <CoreFoundation/CFURL.h>
  31 +#include <sys/syslimits.h>
39 32 #include <lib3270/os.h>
40 33  
41 34 static char * concat(char *path, const char *name, size_t *length) {
... ... @@ -71,14 +64,34 @@ static char * build_filename(const char *root, const char *str, va_list args) {
71 64 }
72 65  
73 66 char * lib3270_build_data_filename(const char *str, ...) {
  67 +
74 68 va_list args;
75 69 va_start (args, str);
76 70  
77   - char *filename = build_filename(LIB3270_STRINGIZE_VALUE_OF(DATADIR), str, args);
  71 + char *filename;
  72 + CFBundleRef mainBundle = CFBundleGetMainBundle();
  73 + if (mainBundle) {
  74 + CFURLRef url = CFBundleCopyBundleURL(mainBundle);
  75 + if (url) {
  76 + size_t szPath = PATH_MAX;
  77 + char *path = (char *) lib3270_malloc(szPath);
  78 + CFURLGetFileSystemRepresentation(url, true, path, szPath);
  79 + CFRelease(url);
  80 + path = concat(path, "Contents/Resources", &szPath);
  81 + filename = build_filename(path, str, args);
  82 + lib3270_free(path);
  83 + } else {
  84 + filename = build_filename(LIB3270_STRINGIZE_VALUE_OF(DATADIR), str, args);
  85 + }
  86 + } else {
  87 + filename = build_filename(LIB3270_STRINGIZE_VALUE_OF(DATADIR), str, args);
  88 + }
78 89  
79 90 va_end (args);
80 91  
81 92 return filename;
  93 +
  94 + return filename;
82 95 }
83 96  
84 97 char * lib3270_build_config_filename(const char *str, ...) {
... ...