1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167 | /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*
* This file is part of the LibreOffice project.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*
* This file incorporates work covered by the following license notice:
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed
* with this work for additional information regarding copyright
* ownership. The ASF licenses this file to you under the Apache
* License, Version 2.0 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.apache.org/licenses/LICENSE-2.0 .
*/
#include <unistd.h>
#include <string.h>
#include <config_features.h>
#include "system.hxx"
#ifdef NO_PTHREAD_RTL
#if defined(MACOSX)
#include <premac.h>
#include <Foundation/Foundation.h>
#include <postmac.h>
/*
* Add support for resolving Mac native alias files (not the same as unix alias files)
* (what are "unix alias files"?)
* returns 0 on success.
*/
int macxp_resolveAlias(char *path, int buflen)
{
#if HAVE_FEATURE_MACOSX_SANDBOX
/* Avoid unnecessary messages in the system.log:
*
* soffice(57342) deny file-read-data /Users/tml/Documents/b.odt/..namedfork/rsrc
* etc.
*
* Just don't bother with resolving aliases. I doubt its usefulness anyway.
*/
(void) path;
(void) buflen;
return 0;
#else
CFStringRef cfpath;
CFURLRef cfurl;
CFErrorRef cferror;
CFDataRef cfbookmark;
// Don't even try anything for files inside the app bundle. Just a
// waste of time.
static const char * const appBundle = [[[NSBundle mainBundle] bundlePath] UTF8String];
const size_t appBundleLen = strlen(appBundle);
if (strncmp(path, appBundle, appBundleLen) == 0 && path[appBundleLen] == '/')
return 0;
char *unprocessedPath = path;
if ( *unprocessedPath == '/' )
unprocessedPath++;
int nRet = 0;
while ( !nRet && unprocessedPath && *unprocessedPath )
{
unprocessedPath = strchr( unprocessedPath, '/' );
if ( unprocessedPath )
*unprocessedPath = '\0';
cfpath = CFStringCreateWithCString( nullptr, path, kCFStringEncodingUTF8 );
cfurl = CFURLCreateWithFileSystemPath( nullptr, cfpath, kCFURLPOSIXPathStyle, false );
CFRelease( cfpath );
cferror = nullptr;
cfbookmark = CFURLCreateBookmarkDataFromFile( nullptr, cfurl, &cferror );
CFRelease( cfurl );
if ( cfbookmark == nullptr )
{
if(cferror)
{
CFRelease( cferror );
}
}
else
{
Boolean isStale;
cfurl = CFURLCreateByResolvingBookmarkData( nullptr, cfbookmark, kCFBookmarkResolutionWithoutUIMask,
nullptr, nullptr, &isStale, &cferror );
CFRelease( cfbookmark );
if ( cfurl == nullptr )
{
CFRelease( cferror );
}
else
{
cfpath = CFURLCopyFileSystemPath( cfurl, kCFURLPOSIXPathStyle );
CFRelease( cfurl );
if ( cfpath != nullptr )
{
char tmpPath[ PATH_MAX ];
if ( CFStringGetCString( cfpath, tmpPath, PATH_MAX, kCFStringEncodingUTF8 ) )
{
int nLen = strlen( tmpPath ) + ( unprocessedPath ? strlen( unprocessedPath + 1 ) + 1 : 0 );
if ( nLen < buflen && nLen < PATH_MAX )
{
if ( unprocessedPath )<--- Assuming that condition 'unprocessedPath' is not redundant
{
int nTmpPathLen = strlen( tmpPath );
strcat( tmpPath, "/" );
strcat( tmpPath, unprocessedPath + 1 );
strcpy( path, tmpPath);
unprocessedPath = path + nTmpPathLen;
}
else if ( !unprocessedPath )<--- Condition '!unprocessedPath' is always true
{
strcpy( path, tmpPath );
}
}
else
{
errno = ENAMETOOLONG;
nRet = -1;
}
}
CFRelease( cfpath );
}
}
}
if ( unprocessedPath )
*unprocessedPath++ = '/';
}
return nRet;
#endif
}
#endif /* defined MACOSX */
#endif /* NO_PTHREAD_RTL */
//might be useful on other platforms, but doesn't compiler under MACOSX anyway
#if defined(__GNUC__) && defined(LINUX)
//force the __data_start symbol to exist in any executables that link against
//libuno_sal so that dlopening of the libgcj provided libjvm.so on some
//platforms where it needs that symbol will succeed. e.g. Debian mips/lenny
//with gcc 4.3. With this in place the smoketest succeeds with libgcj provided
//java. Quite possibly also required/helpful for s390x/s390 and maybe some
//others. Without it the dlopen of libjvm.so will fail with __data_start
//not found
extern int __data_start[] __attribute__((weak));
extern int data_start[] __attribute__((weak));
extern int _end[] __attribute__((weak));
static void *dummy[] __attribute__((used)) = {__data_start, data_start, _end};
#endif
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|