1 diff --git sal/osl/unx/file_url.cxx sal/osl/unx/file_url.cxx
2 index 1bf4c60..a35c9d8 100644
3 --- sal/osl/unx/file_url.cxx
4 +++ sal/osl/unx/file_url.cxx
5 @@ -446,250 +446,38 @@ oslFileError osl_getSystemPathFromFileURL_Ex(
9 -namespace /* private */
10 +/******************************************************
11 + * Resolve the paths if they exist. The resulting
12 + * path must not exceed PATH_MAX else
13 + * osl_File_E_NAMETOOLONG is the result
14 + ******************************************************/
16 +static oslFileError osl_getAbsoluteFileURL_impl_(const rtl::OUString& unresolved, rtl::OUString& resolved)
18 + char unresolved_path[PATH_MAX];
19 + char resolved_path[PATH_MAX];
21 - /******************************************************
22 - * Helper function, return a pinter to the final '\0'
24 - ******************************************************/
26 - sal_Unicode* ustrtoend(sal_Unicode* pStr)
28 - return (pStr + rtl_ustr_getLength(pStr));
31 - /*********************************************
32 + if (!UnicodeToText(unresolved_path, sizeof(unresolved_path), unresolved.getStr(), unresolved.getLength()))
33 + return oslTranslateFileError(OSL_FET_ERROR, ENAMETOOLONG);
35 - ********************************************/
36 + if (realpath(unresolved_path, resolved_path))
38 + sal_Unicode path[PATH_MAX];
39 + if (!TextToUnicode(resolved_path, strlen(resolved_path), path, PATH_MAX))
40 + return oslTranslateFileError(OSL_FET_ERROR, ENAMETOOLONG);
41 + resolved = rtl::OUString(path, rtl_ustr_getLength(path));
42 + return osl_File_E_None;
45 - sal_Unicode* ustrchrcat(const sal_Unicode chr, sal_Unicode* d)
48 - sal_Unicode* p = ustrtoend(d);
52 + if (EACCES != errno && ENOTDIR != errno && ENOENT != errno)
53 + return oslTranslateFileError(OSL_FET_ERROR, errno);
56 - /******************************************************
58 - ******************************************************/
60 - bool _islastchr(sal_Unicode* pStr, sal_Unicode Chr)
62 - sal_Unicode* p = ustrtoend(pStr);
68 - /******************************************************
69 - * Remove the last part of a path, a path that has
70 - * only a '/' or no '/' at all will be returned
72 - ******************************************************/
74 - sal_Unicode* _rmlastpathtoken(sal_Unicode* aPath)
76 - /* we always may skip -2 because we
77 - may at least stand on a '/' but
78 - either there is no other character
79 - before this '/' or it's another
80 - character than the '/'
82 - sal_Unicode* p = ustrtoend(aPath) - 2;
84 - // move back to the next path separator
85 - // or to the start of the string
86 - while ((p > aPath) && (*p != UNICHAR_SLASH))
91 - if (UNICHAR_SLASH == *p)
105 - /******************************************************
107 - ******************************************************/
109 - oslFileError _osl_resolvepath(
110 - /*inout*/ sal_Unicode* path,
111 - /*inout*/ sal_Unicode* current_pos,
112 - /*inout*/ bool* failed)
114 - oslFileError ferr = osl_File_E_None;
118 - char unresolved_path[PATH_MAX];
119 - if (!UnicodeToText(unresolved_path, sizeof(unresolved_path), path, rtl_ustr_getLength(path)))
120 - return oslTranslateFileError(OSL_FET_ERROR, ENAMETOOLONG);
122 - char resolved_path[PATH_MAX];
123 - if (realpath(unresolved_path, resolved_path))
125 - if (!TextToUnicode(resolved_path, strlen(resolved_path), path, PATH_MAX))
126 - return oslTranslateFileError(OSL_FET_ERROR, ENAMETOOLONG);
128 - current_pos = ustrtoend(path) - 1;
132 - if (EACCES == errno || ENOTDIR == errno || ENOENT == errno)
135 - ferr = oslTranslateFileError(OSL_FET_ERROR, errno);
142 - /******************************************************
143 - * Works even with non existing paths. The resulting
144 - * path must not exceed PATH_MAX else
145 - * osl_File_E_NAMETOOLONG is the result
146 - ******************************************************/
148 - oslFileError osl_getAbsoluteFileURL_impl_(const rtl::OUString& unresolved_path, rtl::OUString& resolved_path)
150 - // the given unresolved path must not exceed PATH_MAX
151 - if (unresolved_path.getLength() >= (PATH_MAX - 2))
152 - return oslTranslateFileError(OSL_FET_ERROR, ENAMETOOLONG);
154 - sal_Unicode path_resolved_so_far[PATH_MAX];
155 - const sal_Unicode* punresolved = unresolved_path.getStr();
156 - sal_Unicode* presolvedsf = path_resolved_so_far;
158 - // reserve space for leading '/' and trailing '\0'
159 - // do not exceed this limit
160 - sal_Unicode* sentinel = path_resolved_so_far + PATH_MAX - 2;
162 - // if realpath fails with error ENOTDIR, EACCES or ENOENT
163 - // we will not call it again, because _osl_realpath should also
164 - // work with non existing directories etc.
165 - bool realpath_failed = false;
168 - path_resolved_so_far[0] = '\0';
170 - while (*punresolved != '\0')
172 - // ignore '/.' , skip one part back when '/..'
174 - if ((UNICHAR_DOT == *punresolved) && (UNICHAR_SLASH == *presolvedsf))
176 - if ('\0' == *(punresolved + 1))
181 - else if (UNICHAR_SLASH == *(punresolved + 1))
186 - else if ((UNICHAR_DOT == *(punresolved + 1)) && ('\0' == *(punresolved + 2) || (UNICHAR_SLASH == *(punresolved + 2))))
188 - _rmlastpathtoken(path_resolved_so_far);
190 - presolvedsf = ustrtoend(path_resolved_so_far) - 1;
192 - if (UNICHAR_SLASH == *(punresolved + 2))
199 - else // a file or directory name may start with '.'
201 - if ((presolvedsf = ustrtoend(path_resolved_so_far)) > sentinel)
202 - return oslTranslateFileError(OSL_FET_ERROR, ENAMETOOLONG);
204 - ustrchrcat(*punresolved++, path_resolved_so_far);
206 - if ('\0' == *punresolved && !realpath_failed)
208 - ferr = _osl_resolvepath(
209 - path_resolved_so_far,
213 - if (osl_File_E_None != ferr)
218 - else if (UNICHAR_SLASH == *punresolved)
220 - if ((presolvedsf = ustrtoend(path_resolved_so_far)) > sentinel)
221 - return oslTranslateFileError(OSL_FET_ERROR, ENAMETOOLONG);
223 - ustrchrcat(*punresolved++, path_resolved_so_far);
225 - if (!realpath_failed)
227 - ferr = _osl_resolvepath(
228 - path_resolved_so_far,
232 - if (osl_File_E_None != ferr)
235 - if (!_islastchr(path_resolved_so_far, UNICHAR_SLASH))
237 - if ((presolvedsf = ustrtoend(path_resolved_so_far)) > sentinel)
238 - return oslTranslateFileError(OSL_FET_ERROR, ENAMETOOLONG);
240 - ustrchrcat(UNICHAR_SLASH, path_resolved_so_far);
244 - else // any other character
246 - if ((presolvedsf = ustrtoend(path_resolved_so_far)) > sentinel)
247 - return oslTranslateFileError(OSL_FET_ERROR, ENAMETOOLONG);
249 - ustrchrcat(*punresolved++, path_resolved_so_far);
251 - if ('\0' == *punresolved && !realpath_failed)
253 - ferr = _osl_resolvepath(
254 - path_resolved_so_far,
258 - if (osl_File_E_None != ferr)
264 - sal_Int32 len = rtl_ustr_getLength(path_resolved_so_far);
266 - OSL_ASSERT(len < PATH_MAX);
268 - resolved_path = rtl::OUString(path_resolved_so_far, len);
270 - return osl_File_E_None;
273 -} // end namespace private
275 + // the 'unresolved' does not exist, let's just copy it to 'resolved'
276 + resolved = unresolved;
277 + return osl_File_E_None;
280 /******************************************************
281 * osl_getAbsoluteFileURL