1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
26 #include <config_features.h>
29 #include <Foundation/Foundation.h>
33 * Add support for resolving Mac native alias files (not the same as unix alias files)
34 * (what are "unix alias files"?)
35 * returns 0 on success.
37 int macxp_resolveAlias(char *path
, int buflen
)
39 #if HAVE_FEATURE_MACOSX_SANDBOX
40 /* Avoid unnecessary messages in the system.log:
42 * soffice(57342) deny file-read-data /Users/tml/Documents/b.odt/..namedfork/rsrc
45 * Just don't bother with resolving aliases. I doubt its usefulness anyway.
51 // Don't even try anything for files inside the app bundle. Just a
54 static const char * const appBundle
= [[[NSBundle mainBundle
] bundlePath
] UTF8String
];
56 const size_t appBundleLen
= strlen(appBundle
);
57 if (strncmp(path
, appBundle
, appBundleLen
) == 0 && path
[appBundleLen
] == '/')
60 char *unprocessedPath
= path
;
62 if ( *unprocessedPath
== '/' )
66 while ( !nRet
&& unprocessedPath
&& *unprocessedPath
)
68 unprocessedPath
= strchr( unprocessedPath
, '/' );
69 if ( unprocessedPath
)
70 *unprocessedPath
= '\0';
72 // tdf#155710 handle conversion failures due to non-UTF8 strings
73 // Windows and Linux paths can be passed as parameters to this function
74 // and those paths may not always be UTF8 encoded like macOS paths.
75 CFStringRef cfpath
= CFStringCreateWithCString( nullptr, path
, kCFStringEncodingUTF8
);
76 CFErrorRef cferror
= nullptr;
77 CFDataRef cfbookmark
= nullptr;
80 CFURLRef cfurl
= CFURLCreateWithFileSystemPath( nullptr, cfpath
, kCFURLPOSIXPathStyle
, false );
82 cfbookmark
= CFURLCreateBookmarkDataFromFile( nullptr, cfurl
, &cferror
);
86 if ( cfbookmark
== nullptr )
96 CFURLRef cfurl
= CFURLCreateByResolvingBookmarkData( nullptr, cfbookmark
, kCFBookmarkResolutionWithoutUIMask
,
97 nullptr, nullptr, &isStale
, &cferror
);
98 CFRelease( cfbookmark
);
99 if ( cfurl
== nullptr )
101 CFRelease( cferror
);
105 cfpath
= CFURLCopyFileSystemPath( cfurl
, kCFURLPOSIXPathStyle
);
107 if ( cfpath
!= nullptr )
109 char tmpPath
[ PATH_MAX
];
110 if ( CFStringGetCString( cfpath
, tmpPath
, PATH_MAX
, kCFStringEncodingUTF8
) )
112 int nLen
= strlen( tmpPath
) + ( unprocessedPath
? strlen( unprocessedPath
+ 1 ) + 1 : 0 );
113 if ( nLen
< buflen
&& nLen
< PATH_MAX
)
115 if ( unprocessedPath
)
117 int nTmpPathLen
= strlen( tmpPath
);
118 strcat( tmpPath
, "/" );
119 strcat( tmpPath
, unprocessedPath
+ 1 );
120 strcpy( path
, tmpPath
);
121 unprocessedPath
= path
+ nTmpPathLen
;
123 else if ( !unprocessedPath
)
125 strcpy( path
, tmpPath
);
130 errno
= ENAMETOOLONG
;
139 if ( unprocessedPath
)
140 *unprocessedPath
++ = '/';
147 #endif /* defined MACOSX */
149 #endif /* NO_PTHREAD_RTL */
151 //might be useful on other platforms, but doesn't compiler under MACOSX anyway
152 #if defined(__GNUC__) && defined(LINUX)
153 //force the __data_start symbol to exist in any executables that link against
154 //libuno_sal so that dlopening of the libgcj provided libjvm.so on some
155 //platforms where it needs that symbol will succeed. e.g. Debian mips/lenny
156 //with gcc 4.3. With this in place the smoketest succeeds with libgcj provided
157 //java. Quite possibly also required/helpful for s390x and maybe some
158 //others. Without it the dlopen of libjvm.so will fail with __data_start
160 extern int __data_start
[] __attribute__((weak
));
161 extern int data_start
[] __attribute__((weak
));
162 extern int _end
[] __attribute__((weak
));
163 static void *dummy
[] __attribute__((used
)) = {__data_start
, data_start
, _end
};
166 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */