size_t os_utf8_to_wcs(const char *str, size_t len, wchar_t **pstr) { size_t in_len = len ? len : strlen(str); size_t out_len = utf8_to_wchar(str, in_len, NULL, 0, 0); wchar_t *dst = NULL; if (out_len) { dst = bmalloc((out_len+1) * sizeof(wchar_t)); utf8_to_wchar(str, in_len, dst, out_len+1, 0); dst[out_len] = 0; } *pstr = dst; return out_len; }
/* * Main BrowseInfo callback to set the initial directory and populate the edit control */ INT CALLBACK BrowseInfoCallback(HWND hDlg, UINT message, LPARAM lParam, LPARAM pData) { char dir[MAX_PATH]; wchar_t* wpath; LPITEMIDLIST pidl; switch(message) { case BFFM_INITIALIZED: pOrgBrowseWndproc = (WNDPROC)SetWindowLongPtr(hDlg, GWLP_WNDPROC, (LONG_PTR)BrowseDlgCallback); // Windows hides the full path in the edit box by default, which is bull. // Get a handle to the edit control to fix that hBrowseEdit = FindWindowExA(hDlg, NULL, "Edit", NULL); SetWindowTextU(hBrowseEdit, szFolderPath); SetDialogFocus(hDlg, hBrowseEdit); // On Windows 7, MinGW only properly selects the specified folder when using a pidl wpath = utf8_to_wchar(szFolderPath); pidl = SHSimpleIDListFromPath(wpath); safe_free(wpath); // NB: see http://connect.microsoft.com/VisualStudio/feedback/details/518103/bffm-setselection-does-not-work-with-shbrowseforfolder-on-windows-7 // for details as to why we send BFFM_SETSELECTION twice. SendMessageW(hDlg, BFFM_SETSELECTION, (WPARAM)FALSE, (LPARAM)pidl); Sleep(100); PostMessageW(hDlg, BFFM_SETSELECTION, (WPARAM)FALSE, (LPARAM)pidl); break; case BFFM_SELCHANGED: // Update the status if (SHGetPathFromIDListU((LPITEMIDLIST)lParam, dir)) { SendMessageLU(hDlg, BFFM_SETSTATUSTEXT, 0, dir); SetWindowTextU(hBrowseEdit, dir); } break; } return 0; }
/* * Open a localization file and store its file name, with special case * when dealing with the embedded loc file. */ FILE* open_loc_file(const char* filename) { FILE* fd = NULL; wchar_t *wfilename = NULL; const char* tmp_ext = ".tmp"; if (filename == NULL) return NULL; if (loc_filename != embedded_loc_filename) { safe_free(loc_filename); } if (safe_strcmp(tmp_ext, &filename[safe_strlen(filename)-4]) == 0) { loc_filename = embedded_loc_filename; } else { loc_filename = safe_strdup(filename); } wfilename = utf8_to_wchar(filename); if (wfilename == NULL) { uprintf(conversion_error, filename); goto out; } fd = _wfopen(wfilename, L"rb"); if (fd == NULL) { uprintf("localization: could not open '%s'\n", filename); } out: safe_free(wfilename); return fd; }
// eng: Finds the first ptc-file in emitters folder // rus: Поиск первого ptc-файла в папке с эмиттерами const char* MP_Platform_WIN_POSIX::GetFirstFile() { std::string ptc_path=GetPathToPTC(); #ifdef _WINDOWS ptc_path+="*.ptc"; const wchar_t* mask=utf8_to_wchar(ptc_path.c_str()); hFindFile=FindFirstFileW(mask,&fd); if (hFindFile!=INVALID_HANDLE_VALUE) { file=wchar_to_utf8(fd.cFileName); return file.c_str(); } FindClose(hFindFile); #else dir=opendir(ptc_path.c_str()); if (dir) return GetNextFile(); #endif return NULL; }
int fs_stat(char *filename, struct meterp_stat *buf) { struct _stat64i32 sbuf; wchar_t *filename_w = utf8_to_wchar(filename); if (filename_w == NULL) { return -1; } if (_wstat(filename_w, &sbuf) == -1) { return GetLastError(); } free(filename_w); buf->st_dev = sbuf.st_dev; buf->st_ino = sbuf.st_ino; buf->st_mode = sbuf.st_mode; buf->st_nlink = sbuf.st_nlink; buf->st_uid = sbuf.st_uid; buf->st_gid = sbuf.st_gid; buf->st_rdev = sbuf.st_rdev; buf->st_size = sbuf.st_size; buf->st_atime = sbuf.st_atime; buf->st_mtime = sbuf.st_mtime; buf->st_ctime = sbuf.st_ctime; return ERROR_SUCCESS; }
BOOL CreateProcessA (LPCSTR pszImageName, LPSTR pszCmdLine, LPSECURITY_ATTRIBUTES psaProcess, LPSECURITY_ATTRIBUTES psaThread, BOOL fInheritHandles, DWORD fdwCreate, PVOID pvEnvironment, LPCSTR pszCurDir, LPSTARTUPINFOA psiStartInfo, LPPROCESS_INFORMATION pProcInfo) { wchar_t *image_name = NULL; wchar_t *cmd_line = NULL; BOOL result; int err; assert (psaProcess == NULL); assert (psaThread == NULL); assert (fInheritHandles == FALSE); assert (pvEnvironment == NULL); assert (pszCurDir == NULL); /* psiStartInfo is generally not NULL. */ if (pszImageName) { image_name = utf8_to_wchar (pszImageName); if (!image_name) return 0; } if (pszCmdLine) { cmd_line = utf8_to_wchar (pszCmdLine); if (!cmd_line) { if (image_name) free (image_name); return 0; } } result = CreateProcessW (image_name, cmd_line, NULL, NULL, FALSE, fdwCreate, NULL, NULL, NULL, pProcInfo); err = GetLastError (); free (image_name); free (cmd_line); SetLastError (err); return result; }
/* * Parse a buffer (ANSI or UTF-8) and return the data for the 'n'th occurrence of 'token' * The returned string is UTF-8 and MUST be freed by the caller */ char* get_token_data_buffer(const char* token, unsigned int n, const char* buffer, size_t buffer_size) { unsigned int j, curly_count; wchar_t *wtoken = NULL, *wdata = NULL, *wbuffer = NULL, *wline = NULL; size_t i; BOOL done = FALSE; char* ret = NULL; // We're handling remote data => better safe than sorry if ((token == NULL) || (buffer == NULL) || (buffer_size <= 4) || (buffer_size > 65536)) goto out; // Ensure that our buffer is NUL terminated if (buffer[buffer_size-1] != 0) goto out; wbuffer = utf8_to_wchar(buffer); wtoken = utf8_to_wchar(token); if ((wbuffer == NULL) || (wtoken == NULL)) goto out; // Process individual lines (or multiple lines when between {}, for RTF) for (i=0,j=0,done=FALSE; (j!=n)&&(!done); ) { wline = &wbuffer[i]; for(curly_count=0;((curly_count>0)||((wbuffer[i]!=L'\n')&&(wbuffer[i]!=L'\r')))&&(wbuffer[i]!=0);i++) { if (wbuffer[i] == L'{') curly_count++; if (wbuffer[i] == L'}') curly_count--; } if (wbuffer[i]==0) { done = TRUE; } else { wbuffer[i++] = 0; } wdata = get_token_data_line(wtoken, wline); if (wdata != NULL) { j++; } } out: if (wdata != NULL) ret = wchar_to_utf8(wdata); safe_free(wbuffer); safe_free(wtoken); return ret; }
/** * @brief Конвертация строки UTF-8 в широкую строку. * @param in Входящая строка в кодировке UTF-8. * @return Широкая строка в кодировке UTF-16 или UTF-32 в зависимости от * размера типа <c><b>wchar_t</b></c>. */ inline std::wstring utf8_to_wchar( const std::string & in ) { std::wstring retvalue ; utf8_to_wchar( in , retvalue ); return retvalue ; }
/* Locking core for Windows. This version does not need a temporary file but uses the plain lock file along with record locking. We create this file here so that we later only need to do the file locking. For error reporting it is useful to keep the name of the file in the handle. */ static dotlock_t dotlock_create_w32 (dotlock_t h, const char *file_to_lock) { LOCK_all_lockfiles (); h->next = all_lockfiles; all_lockfiles = h; h->lockname = jnlib_malloc ( strlen (file_to_lock) + 6 ); if (!h->lockname) { all_lockfiles = h->next; UNLOCK_all_lockfiles (); jnlib_free (h); return NULL; } strcpy (stpcpy(h->lockname, file_to_lock), EXTSEP_S "lock"); /* If would be nice if we would use the FILE_FLAG_DELETE_ON_CLOSE along with FILE_SHARE_DELETE but that does not work due to a race condition: Despite the OPEN_ALWAYS flag CreateFile may return an error and we can't reliable create/open the lock file unless we would wait here until it works - however there are other valid reasons why a lock file can't be created and thus the process would not stop as expected but spin until Windows crashes. Our solution is to keep the lock file open; that does not harm. */ { #ifdef HAVE_W32CE_SYSTEM wchar_t *wname = utf8_to_wchar (h->lockname); if (wname) h->lockhd = CreateFile (wname, GENERIC_READ|GENERIC_WRITE, FILE_SHARE_READ|FILE_SHARE_WRITE, NULL, OPEN_ALWAYS, 0, NULL); else h->lockhd = INVALID_HANDLE_VALUE; jnlib_free (wname); #else h->lockhd = CreateFile (h->lockname, GENERIC_READ|GENERIC_WRITE, FILE_SHARE_READ|FILE_SHARE_WRITE, NULL, OPEN_ALWAYS, 0, NULL); #endif } if (h->lockhd == INVALID_HANDLE_VALUE) { all_lockfiles = h->next; UNLOCK_all_lockfiles (); my_error_2 (_("can't create `%s': %s\n"), h->lockname, w32_strerror (-1)); jnlib_free (h->lockname); jnlib_free (h); return NULL; } return h; }
/* * Parse a file (ANSI or UTF-8 or UTF-16) and return the data for the first occurrence of 'token' * The returned string is UTF-8 and MUST be freed by the caller */ char* get_token_data_file(const char* token, const char* filename) { wchar_t *wtoken = NULL, *wdata= NULL, *wfilename = NULL; wchar_t buf[1024]; FILE* fd = NULL; char *ret = NULL; if ((filename == NULL) || (token == NULL)) return NULL; if ((filename[0] == 0) || (token[0] == 0)) return NULL; wfilename = utf8_to_wchar(filename); if (wfilename == NULL) { uprintf(conversion_error, filename); goto out; } wtoken = utf8_to_wchar(token); if (wfilename == NULL) { uprintf(conversion_error, token); goto out; } fd = _wfopen(wfilename, L"r, ccs=UNICODE"); if (fd == NULL) goto out; // Process individual lines. NUL is always appended. // Ideally, we'd check that our buffer fits the line while (fgetws(buf, ARRAYSIZE(buf), fd) != NULL) { wdata = get_token_data_line(wtoken, buf); if (wdata != NULL) { ret = wchar_to_utf8(wdata); break; } } out: if (fd != NULL) fclose(fd); safe_free(wfilename); safe_free(wtoken); return ret; }
int fs_copy(const char *oldpath, const char *newpath) { int rc = ERROR_SUCCESS; wchar_t *old_w = utf8_to_wchar(oldpath); wchar_t *new_w = utf8_to_wchar(newpath); if ((old_w == NULL) || (new_w == NULL)) { rc = GetLastError(); goto out; } if (CopyFileW(old_w, new_w, 0) == 0) { rc = GetLastError(); } out: free(old_w); free(new_w); return rc; }
// ru: Удаление файла (аналог "remove") // en: Deleting of file (analogue "remove") int MP_Platform_WIN_POSIX::RemoveFile(const char* file) { #ifdef _WINDOWS return _wremove(utf8_to_wchar(file)); #else return remove(file); #endif }
size_t os_utf8_to_wcs(const char *str, size_t len, wchar_t *dst, size_t dst_size) { size_t in_len = len ? len : strlen(str); size_t out_len = dst ? len : utf8_to_wchar(str, in_len, NULL, 0, 0); if (out_len && dst) { if (!dst_size) return 0; if (out_len) { if ((out_len + 1) > dst_size) out_len = dst_size - 1; utf8_to_wchar(str, in_len, dst, out_len + 1, 0); } dst[out_len] = 0; } return out_len; }
/* A wrapper around mkdir which takes a string for the mode argument. This makes it easier to handle the mode argument which is not defined on all systems. The format of the modestring is "-rwxrwxrwx" '-' is a don't care or not set. 'r', 'w', 'x' are read allowed, write allowed, execution allowed with the first group for the user, the second for the group and the third for all others. If the string is shorter than above the missing mode characters are meant to be not set. */ int gnupg_mkdir (const char *name, const char *modestr) { #ifdef HAVE_W32CE_SYSTEM wchar_t *wname; (void)modestr; wname = utf8_to_wchar (name); if (!wname) return -1; if (!CreateDirectoryW (wname, NULL)) { xfree (wname); return -1; /* ERRNO is automagically provided by gpg-error.h. */ } xfree (wname); return 0; #elif MKDIR_TAKES_ONE_ARG (void)modestr; /* Note: In the case of W32 we better use CreateDirectory and try to set appropriate permissions. However using mkdir is easier because this sets ERRNO. */ return mkdir (name); #else mode_t mode = 0; if (modestr && *modestr) { modestr++; if (*modestr && *modestr++ == 'r') mode |= S_IRUSR; if (*modestr && *modestr++ == 'w') mode |= S_IWUSR; if (*modestr && *modestr++ == 'x') mode |= S_IXUSR; if (*modestr && *modestr++ == 'r') mode |= S_IRGRP; if (*modestr && *modestr++ == 'w') mode |= S_IWGRP; if (*modestr && *modestr++ == 'x') mode |= S_IXGRP; if (*modestr && *modestr++ == 'r') mode |= S_IROTH; if (*modestr && *modestr++ == 'w') mode |= S_IWOTH; if (*modestr && *modestr++ == 'x') mode |= S_IXOTH; } return mkdir (name, mode); #endif }
float Font::getAdvanceX(const char *text, float letterSpacing, int size) { std::vector<wchar32_t> wtext; size_t len = utf8_to_wchar(text, strlen(text), NULL, 0, 0); if (len != 0) { wtext.resize(len); utf8_to_wchar(text, strlen(text), &wtext[0], len, 0); } if (size < 0 || size > wtext.size()) size = wtext.size(); wtext.push_back(0); float x = 0; wchar32_t prev = 0; for (int i = 0; i < size; ++i) { std::map<wchar32_t, TextureGlyph>::const_iterator iter = fontInfo_.textureGlyphs.find(wtext[i]); if (iter == fontInfo_.textureGlyphs.end()) continue; const TextureGlyph &textureGlyph = iter->second; x += kerning(prev, wtext[i]) >> 6; prev = wtext[i]; x += textureGlyph.advancex >> 6; x += letterSpacing / sizescalex_; } x += kerning(prev, wtext[size]) >> 6; return x * sizescalex_; }
static void w32_try_mkdir (const char *dir) { #ifdef HAVE_W32CE_SYSTEM wchar_t *wdir = utf8_to_wchar (dir); if (wdir) { CreateDirectory (wdir, NULL); xfree (wdir); } #else CreateDirectory (dir, NULL); #endif }
/* * Create a tooltip for the control passed as first parameter * duration sets the duration in ms. Use -1 for default * message is an UTF-8 string */ BOOL CreateTooltip(HWND hControl, const char* message, int duration) { TOOLINFOW toolInfo = {0}; int i; if ( (hControl == NULL) || (message == NULL) ) { return FALSE; } // Destroy existing tooltip if any DestroyTooltip(hControl); // Find an empty slot for (i=0; i<MAX_TOOLTIPS; i++) { if (ttlist[i].hTip == NULL) break; } if (i >= MAX_TOOLTIPS) { uprintf("Maximum number of tooltips reached (%d)\n", MAX_TOOLTIPS); return FALSE; } // Create the tooltip window ttlist[i].hTip = CreateWindowExW(0, TOOLTIPS_CLASSW, NULL, WS_POPUP | TTS_NOPREFIX | TTS_ALWAYSTIP, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, hMainDialog, NULL, hMainInstance, NULL); if (ttlist[i].hTip == NULL) { return FALSE; } ttlist[i].hCtrl = hControl; // Subclass the tooltip to handle multiline ttlist[i].original_proc = (WNDPROC)SetWindowLongPtr(ttlist[i].hTip, GWLP_WNDPROC, (LONG_PTR)TooltipCallback); // Set the string to display (can be multiline) ttlist[i].wstring = utf8_to_wchar(message); // Set tooltip duration (ms) PostMessage(ttlist[i].hTip, TTM_SETDELAYTIME, (WPARAM)TTDT_AUTOPOP, (LPARAM)duration); // Associate the tooltip to the control toolInfo.cbSize = sizeof(toolInfo); toolInfo.hwnd = ttlist[i].hTip; // Set to the tooltip itself to ease up subclassing toolInfo.uFlags = TTF_IDISHWND | TTF_SUBCLASS | ((right_to_left_mode)?TTF_RTLREADING:0); toolInfo.uId = (UINT_PTR)hControl; toolInfo.lpszText = LPSTR_TEXTCALLBACKW; SendMessageW(ttlist[i].hTip, TTM_ADDTOOLW, 0, (LPARAM)&toolInfo); return TRUE; }
int fs_stat(char *filename, struct meterp_stat *buf) { wchar_t *filename_w = utf8_to_wchar(filename); if (filename_w == NULL) { return -1; } if (win32_wstat(filename_w, buf) == -1) { return GetLastError(); } free(filename_w); return ERROR_SUCCESS; }
static int MyDeleteFile (LPCSTR lpFileName) { wchar_t *filename; int result, err; filename = utf8_to_wchar (lpFileName); if (!filename) return 0; result = DeleteFileW (filename); err = GetLastError (); free (filename); SetLastError (err); return result; }
bool peinfect_infect_full_file(char *infile, PEINFECT *in, char *outfile) { bool returnVar = false; unsigned char *file_mem; PEFILE pefile; /* Open file */ FILE *fh; wchar_t *file_w = utf8_to_wchar(infile); if (_wfopen_s(&fh, file_w, L"rb") == 0) { /* Get file size and allocate buffer */ if (!fseek(fh, 0L, SEEK_END)) { size_t size = ftell(fh); size_t read_size = 0; rewind(fh); file_mem = malloc(size); if (file_mem != NULL) { /* Load file into buffer */ read_size = fread(file_mem, size, 1, fh); fclose(fh); fh = NULL; /* Process file in memory */ if (read_size == 1) { returnVar = peinfect_infect_full(file_mem, size, in, &pefile); } /* free buffer after use */ free(file_mem); /* Write file to disk*/ if (returnVar) { returnVar = pefile_write_file(&pefile, NULL, outfile); } } } /* Close file (if memory allocation has failed) */ if (fh != NULL) { fclose(fh); } } free(file_w); return returnVar; }
/* * Create a tooltip for the control passed as first parameter * duration sets the duration in ms. Use -1 for default * message is an UTF-8 string */ HWND create_tooltip(HWND hControl, char* message, int duration) { TOOLINFOW toolInfo = {0}; int i; if ( (hControl == NULL) || (message == NULL) ) { return (HWND)NULL; } // Find an empty slot for (i=0; i<MAX_TOOLTIPS; i++) { if (ttlist[i].hTip == NULL) break; } if (i == MAX_TOOLTIPS) { return (HWND)NULL; // No more space } // Create the tooltip window ttlist[i].hTip = CreateWindowExW(0, TOOLTIPS_CLASSW, NULL, WS_POPUP | TTS_NOPREFIX | TTS_ALWAYSTIP, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, hMainDialog, NULL, main_instance, NULL); if (ttlist[i].hTip == NULL) { return (HWND)NULL; } // Subclass the tooltip to handle multiline ttlist[i].original_proc = (WNDPROC)SetWindowLongPtr(ttlist[i].hTip, GWLP_WNDPROC, (LONG_PTR)tooltip_callback); // Set the string to display (can be multiline) ttlist[i].wstring = utf8_to_wchar(message); // Set tooltip duration (ms) PostMessage(ttlist[i].hTip, TTM_SETDELAYTIME, (WPARAM)TTDT_AUTOPOP, (LPARAM)duration); // Associate the tooltip to the control toolInfo.cbSize = sizeof(toolInfo); toolInfo.hwnd = ttlist[i].hTip; // Set to the tooltip itself to ease up subclassing toolInfo.uFlags = TTF_IDISHWND | TTF_SUBCLASS; toolInfo.uId = (UINT_PTR)hControl; toolInfo.lpszText = LPSTR_TEXTCALLBACKW; SendMessageW(ttlist[i].hTip, TTM_ADDTOOLW, 0, (LPARAM)&toolInfo); return ttlist[i].hTip; }
int fs_delete_file(const char *path) { int rc = ERROR_SUCCESS; wchar_t *path_w = utf8_to_wchar(path); if (path_w == NULL) { rc = GetLastError(); goto out; } if (DeleteFileW(path_w) == 0) { rc = GetLastError(); } out: free(path_w); return rc; }
/** * Open file path given in the current encoding, using desired shared access. * * @param path file path * @param mode string specifying file opening mode * @param exclusive non-zero to prohibit write access to the file * @return file descriptor on success, NULL on error */ FILE* win_fopen_ex(const char* path, const char* mode, int exclusive) { FILE* fd = 0; int i; wchar_t* wmode = utf8_to_wchar(mode); assert(wmode != NULL); /* try two code pages */ for(i = 0; i < 2; i++) { wchar_t* wpath = c2w(path, i); if(wpath == NULL) continue; fd = _wfsopen(wpath, wmode, (exclusive ? _SH_DENYWR : _SH_DENYNO)); free(wpath); if(fd || errno != ENOENT) break; } free(wmode); return fd; }
BOOL DeleteFileA (LPCSTR lpFileName) { wchar_t *filename; BOOL result; int err; filename = utf8_to_wchar (lpFileName); if (!filename) return FALSE; result = DeleteFileW (filename); err = GetLastError (); free (filename); SetLastError (err); return result; }
int fs_delete_dir(const char *directory) { int rc = ERROR_SUCCESS; wchar_t *dir_w = utf8_to_wchar(directory); if (dir_w == NULL) { rc = GetLastError(); goto out; } if (DeleteFolderWR(dir_w) == 0) { rc = GetLastError(); } out: free(dir_w); return rc; }
int fs_mkdir(const char *directory) { int rc = ERROR_SUCCESS; wchar_t *dir_w = utf8_to_wchar(directory); if (dir_w == NULL) { rc = GetLastError(); goto out; } if (CreateDirectoryW(dir_w, NULL) == 0) { rc = GetLastError(); } out: free(dir_w); return rc; }
/* * Open the trustdb. This may only be called if it has not yet been * opened and after a successful call to tdbio_set_dbname. On return * the trustdb handle (DB_FD) is guaranteed to be open. */ static void open_db () { TRUSTREC rec; assert( db_fd == -1 ); #ifdef HAVE_W32CE_SYSTEM { DWORD prevrc = 0; wchar_t *wname = utf8_to_wchar (db_name); if (wname) { db_fd = (int)CreateFile (wname, GENERIC_READ|GENERIC_WRITE, FILE_SHARE_READ|FILE_SHARE_WRITE, NULL, OPEN_EXISTING, 0, NULL); xfree (wname); } if (db_fd == -1) log_fatal ("can't open '%s': %d, %d\n", db_name, (int)prevrc, (int)GetLastError ()); } #else /*!HAVE_W32CE_SYSTEM*/ db_fd = open (db_name, O_RDWR | MY_O_BINARY ); if (db_fd == -1 && (errno == EACCES #ifdef EROFS || errno == EROFS #endif ) ) { /* Take care of read-only trustdbs. */ db_fd = open (db_name, O_RDONLY | MY_O_BINARY ); if (db_fd != -1 && !opt.quiet) log_info (_("Note: trustdb not writable\n")); } if ( db_fd == -1 ) log_fatal( _("can't open '%s': %s\n"), db_name, strerror(errno) ); #endif /*!HAVE_W32CE_SYSTEM*/ register_secured_file (db_name); /* Read the version record. */ if (tdbio_read_record (0, &rec, RECTYPE_VER ) ) log_fatal( _("%s: invalid trustdb\n"), db_name ); }
/* Call SetDlgItemTextW with an UTF8 string. */ static void set_dlg_item_text (HWND dlg, int item, const char *string) { if (!string || !*string) SetDlgItemTextW (dlg, item, L""); else { wchar_t *wbuf; wbuf = utf8_to_wchar (string); if (!wbuf) SetDlgItemTextW (dlg, item, L"[out of core]"); else { SetDlgItemTextW (dlg, item, wbuf); free (wbuf); } } }
char * fs_expand_path(const char *regular) { wchar_t expanded_path[FS_MAX_PATH]; wchar_t *regular_w; regular_w = utf8_to_wchar(regular); if (regular_w == NULL) { return NULL; } if (ExpandEnvironmentStringsW(regular_w, expanded_path, FS_MAX_PATH) == 0) { free(regular_w); return NULL; } free(regular_w); return wchar_to_utf8(expanded_path); }
/* Replacement for the access function. Note that we can't use fopen here because wince might now allow to have a shared read for an executable; it is better to to read the file attributes. Limitation: Only F_OK is supported. */ int _gpgme_wince_access (const char *fname, int mode) { DWORD attr; wchar_t *wfname; (void)mode; wfname = utf8_to_wchar (fname); if (!wfname) return -1; attr = GetFileAttributes (wfname); free (wfname); if (attr == (DWORD)(-1)) { gpg_err_set_errno (ENOENT); return -1; } return 0; }