/** * @brief Convert a Windows style path to a file name into an Unix style one. * * @param filename pointer to the file path to be converted * * @return pointer to the converted file path */ static char *unix_name (char *filename) { static char *unix_filename; LPSTR (*CDECL wine_get_unix_file_name_ptr)(LPCWSTR); int wchar_conv; if (*filename && (filename[1] == ':')) { wine_get_unix_file_name_ptr = (void *) GetProcAddress(GetModuleHandleA("KERNEL32"), "wine_get_unix_file_name"); wchar_conv = MultiByteToWideChar(CP_UNIXCP, 0, filename, -1, NULL, 0); if (wine_get_unix_file_name_ptr && wchar_conv) { WCHAR *ntpath; char *unix_name; ntpath = HeapAlloc(GetProcessHeap(), 0, sizeof(*ntpath) * (wchar_conv + 1)); MultiByteToWideChar(CP_UNIXCP, 0, filename, -1, ntpath, wchar_conv); unix_name = wine_get_unix_file_name_ptr(ntpath); setdup(&unix_filename, unix_name); filename = unix_filename; HeapFree(GetProcessHeap(), 0, unix_name); HeapFree(GetProcessHeap(), 0, ntpath); } } return filename; }
static IUri *convert_file_uri(IUri *uri) { wine_get_unix_file_name_t wine_get_unix_file_name_ptr; IUriBuilder *uri_builder; struct stat dummy; WCHAR *new_path; char *unixpath; BSTR filename; IUri *new_uri; HRESULT hres; /* check if the argument is a local file */ wine_get_unix_file_name_ptr = (wine_get_unix_file_name_t) GetProcAddress( GetModuleHandleA( "KERNEL32" ), "wine_get_unix_file_name" ); if(!wine_get_unix_file_name_ptr) return NULL; hres = IUri_GetPath(uri, &filename); if(FAILED(hres)) return NULL; unixpath = wine_get_unix_file_name_ptr(filename); SysFreeString(filename); if(unixpath && stat(unixpath, &dummy) >= 0) { int len; len = MultiByteToWideChar(CP_UNIXCP, 0, unixpath, -1, NULL, 0); new_path = HeapAlloc(GetProcessHeap(), 0, len*sizeof(WCHAR)); if(new_path) MultiByteToWideChar(CP_UNIXCP, 0, unixpath, -1, new_path, len); HeapFree(GetProcessHeap(), 0, unixpath); }else { WINE_WARN("File %s does not exist\n", wine_dbgstr_a(unixpath)); HeapFree(GetProcessHeap(), 0, unixpath); new_path = NULL; } hres = CreateIUriBuilder(uri, 0, 0, &uri_builder); if(SUCCEEDED(hres) && new_path) hres = IUriBuilder_SetPath(uri_builder, new_path); HeapFree(GetProcessHeap(), 0, new_path); if(FAILED(hres)) return NULL; hres = IUriBuilder_CreateUri(uri_builder, 0, 0, 0, &new_uri); IUriBuilder_Release(uri_builder); if(FAILED(hres)) return NULL; return new_uri; }
static char * maybe_convert_arg (char *arg) { if (wine_get_unix_file_name_ptr && (strchr (arg, '\\') || (arg[0] && arg[1] == ':'))) { int len; WCHAR *win_name_wide; char *unix_name, *ret; len = strlen (arg); win_name_wide = malloc (sizeof (WCHAR) * (len + 1)); MultiByteToWideChar(CP_ACP, 0, arg, -1, win_name_wide, len + 1); unix_name = wine_get_unix_file_name_ptr (win_name_wide); ret = strdup (unix_name); free (win_name_wide); HeapFree (GetProcessHeap(), 0, unix_name); return ret; } else return arg; }
static WCHAR *convert_file_uri(IUri *uri) { wine_get_unix_file_name_t wine_get_unix_file_name_ptr; struct stat dummy; WCHAR *new_path; char *unixpath; BSTR filename; HRESULT hres; /* check if the argument is a local file */ wine_get_unix_file_name_ptr = (wine_get_unix_file_name_t) GetProcAddress( GetModuleHandleA( "KERNEL32" ), "wine_get_unix_file_name" ); if(!wine_get_unix_file_name_ptr) return NULL; hres = IUri_GetPath(uri, &filename); if(FAILED(hres)) return NULL; WINE_TRACE("Windows path: %s\n", wine_dbgstr_w(filename)); unixpath = wine_get_unix_file_name_ptr(filename); SysFreeString(filename); if(unixpath && stat(unixpath, &dummy) >= 0) { WINE_TRACE("Unix path: %s\n", wine_dbgstr_a(unixpath)); new_path = encode_unix_path(unixpath); HeapFree(GetProcessHeap(), 0, unixpath); }else { WINE_WARN("File %s does not exist\n", wine_dbgstr_a(unixpath)); HeapFree(GetProcessHeap(), 0, unixpath); new_path = NULL; } WINE_TRACE("New path: %s\n", wine_dbgstr_w(new_path)); return new_path; }
/* * Main function */ int wmain(int argc, WCHAR *argv[]) { LPSTR (*CDECL wine_get_unix_file_name_ptr)(LPCWSTR) = NULL; LPWSTR (*CDECL wine_get_dos_file_name_ptr)(LPCSTR) = NULL; WCHAR dos_pathW[MAX_PATH]; char path[MAX_PATH]; int outputformats; int i; outputformats = parse_options(argv); if (outputformats == 0) outputformats = UNIXFORMAT; if (outputformats & UNIXFORMAT) { wine_get_unix_file_name_ptr = (void*) GetProcAddress(GetModuleHandleA("KERNEL32"), "wine_get_unix_file_name"); if (wine_get_unix_file_name_ptr == NULL) { fprintf(stderr, "%s: cannot get the address of " "'wine_get_unix_file_name'\n", progname); exit(3); } } if (outputformats & WINDOWSFORMAT) { wine_get_dos_file_name_ptr = (void*) GetProcAddress(GetModuleHandleA("KERNEL32"), "wine_get_dos_file_name"); if (wine_get_dos_file_name_ptr == NULL) { fprintf(stderr, "%s: cannot get the address of " "'wine_get_dos_file_name'\n", progname); exit(3); } } for (i = 1; argv[i]; i++) { *path='\0'; if (outputformats & LONGFORMAT) { if (GetLongPathNameW(argv[i], dos_pathW, MAX_PATH)) WideCharToMultiByte(CP_UNIXCP, 0, dos_pathW, -1, path, MAX_PATH, NULL, NULL); printf("%s\n", path); } if (outputformats & SHORTFORMAT) { if (GetShortPathNameW(argv[i], dos_pathW, MAX_PATH)) WideCharToMultiByte(CP_UNIXCP, 0, dos_pathW, -1, path, MAX_PATH, NULL, NULL); printf("%s\n", path); } if (outputformats & UNIXFORMAT) { WCHAR *ntpath, *tail; int ntpathlen=lstrlenW(argv[i]); ntpath=HeapAlloc(GetProcessHeap(), 0, sizeof(*ntpath)*(ntpathlen+1)); lstrcpyW(ntpath, argv[i]); tail=NULL; while (1) { char *unix_name; WCHAR *slash, *c; unix_name = wine_get_unix_file_name_ptr(ntpath); if (unix_name) { if (tail) { WideCharToMultiByte(CP_UNIXCP, 0, tail+1, -1, path, MAX_PATH, NULL, NULL); printf("%s/%s\n", unix_name, path); } else { printf("%s\n", unix_name); } HeapFree( GetProcessHeap(), 0, unix_name ); break; } slash=(tail ? tail : ntpath+ntpathlen); while (slash != ntpath && *slash != '/' && *slash != '\\') slash--; if (slash == ntpath) { /* This is a complete path conversion failure. * It would typically happen if ntpath == "". */ printf("\n"); break; } c=slash+1; while (*c != '\0' && *c != '*' && *c != '?' && *c != '<' && *c != '>' && *c != '|' && *c != '"') c++; if (*c != '\0') { /* If this is not a valid NT path to start with, * then obviously we cannot convert it. */ printf("\n"); break; } if (tail) *tail='/'; tail=slash; *tail='\0'; } HeapFree(GetProcessHeap(), 0, ntpath); } if (outputformats & WINDOWSFORMAT) { WCHAR* windows_name; char* unix_name; DWORD size; size=WideCharToMultiByte(CP_UNIXCP, 0, argv[i], -1, NULL, 0, NULL, NULL); unix_name=HeapAlloc(GetProcessHeap(), 0, size); WideCharToMultiByte(CP_UNIXCP, 0, argv[i], -1, unix_name, size, NULL, NULL); if ((windows_name = wine_get_dos_file_name_ptr(unix_name))) { WideCharToMultiByte(CP_UNIXCP, 0, windows_name, -1, path, MAX_PATH, NULL, NULL); printf("%s\n", path); HeapFree( GetProcessHeap(), 0, windows_name ); } else printf( "\n" ); HeapFree( GetProcessHeap(), 0, unix_name ); } } exit(0); }