tdf#130857 qt weld: Support mail merge "Server Auth" dialog
[LibreOffice.git] / sal / osl / unx / system.cxx
blobeba4fe01c6c5c997ffde11bc618662058aed5c73
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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 .
20 #include "system.hxx"
22 #ifdef NO_PTHREAD_RTL
24 #if defined(MACOSX)
26 #include <config_features.h>
28 #include <premac.h>
29 #include <Foundation/Foundation.h>
30 #include <postmac.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
43 * etc.
45 * Just don't bother with resolving aliases. I doubt its usefulness anyway.
47 (void) path;
48 (void) buflen;
49 return 0;
50 #else
51 // Don't even try anything for files inside the app bundle. Just a
52 // waste of time.
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] == '/')
58 return 0;
60 char *unprocessedPath = path;
62 if ( *unprocessedPath == '/' )
63 unprocessedPath++;
65 int nRet = 0;
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;
78 if (cfpath)
80 CFURLRef cfurl = CFURLCreateWithFileSystemPath( nullptr, cfpath, kCFURLPOSIXPathStyle, false );
81 CFRelease( cfpath );
82 cfbookmark = CFURLCreateBookmarkDataFromFile( nullptr, cfurl, &cferror );
83 CFRelease( cfurl );
86 if ( cfbookmark == nullptr )
88 if(cferror)
90 CFRelease( cferror );
93 else
95 Boolean isStale;
96 CFURLRef cfurl = CFURLCreateByResolvingBookmarkData( nullptr, cfbookmark, kCFBookmarkResolutionWithoutUIMask,
97 nullptr, nullptr, &isStale, &cferror );
98 CFRelease( cfbookmark );
99 if ( cfurl == nullptr )
101 CFRelease( cferror );
103 else
105 cfpath = CFURLCopyFileSystemPath( cfurl, kCFURLPOSIXPathStyle );
106 CFRelease( cfurl );
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 );
128 else
130 errno = ENAMETOOLONG;
131 nRet = -1;
134 CFRelease( cfpath );
139 if ( unprocessedPath )
140 *unprocessedPath++ = '/';
143 return nRet;
144 #endif
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
159 //not found
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};
164 #endif
166 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */