2 * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
3 * Copyright (C) 2007 - INRIA - Allan CORNET
5 * Copyright (C) 2012 - 2016 - Scilab Enterprises
7 * This file is hereby licensed under the terms of the GNU GPL v2.0,
8 * pursuant to article 5.3.4 of the CeCILL v.2.1.
9 * This file was originally licensed under the terms of the CeCILL v2.1,
10 * and continues to be available under such terms.
11 * For more information, see the COPYING file which you should have received
12 * along with this program.
15 /*--------------------------------------------------------------------------*/
20 #include "getlongpathname.h"
21 #include "sci_malloc.h"
22 #include "charEncoding.h"
23 #include "os_string.h"
24 /*--------------------------------------------------------------------------*/
27 #define MAX_PATH_LONG 32767
30 /*--------------------------------------------------------------------------*/
31 char *getlongpathname(const char *shortpathname, BOOL *convertok)
33 char *LongName = NULL;
34 wchar_t *wcshortpathname = to_wide_string(shortpathname);
37 wchar_t *wcLongName = getlongpathnameW(wcshortpathname, convertok);
38 FREE(wcshortpathname);
41 LongName = wide_string_to_UTF8(wcLongName);
47 LongName = os_strdup(shortpathname);
53 LongName = os_strdup(shortpathname);
58 /*--------------------------------------------------------------------------*/
59 wchar_t *getlongpathnameW(const wchar_t *wcshortpathname, BOOL *convertok)
61 wchar_t *wcLongName = NULL;
64 /* first we try to call to know path length */
65 int length = GetLongPathNameW(wcshortpathname, NULL, 0);
68 length = MAX_PATH_LONG;
71 wcLongName = (wchar_t*)MALLOC((length + 1) * sizeof(wchar_t));
75 /* second converts path */
76 if (GetLongPathNameW(wcshortpathname, wcLongName, length))
85 wcscpy(wcLongName, wcshortpathname);
97 int len = (int)wcslen(wcshortpathname) + 1;
98 wcLongName = (wchar_t*)MALLOC(len * sizeof(wchar_t));
101 wcscpy(wcLongName, wcshortpathname);
107 /*--------------------------------------------------------------------------*/