From: Thorsten Engel Date: Tue, 17 May 2005 14:35:52 +0000 (+0000) Subject: rewrote Win32 unicode support to use poolmemory instead of stack X-Git-Tag: Release-7.0.0~8773 X-Git-Url: https://git.sur5r.net/?a=commitdiff_plain;h=19dfdcd9855e68165fe1f02c859a3c2a2f8c667d;p=bacula%2Fbacula rewrote Win32 unicode support to use poolmemory instead of stack git-svn-id: https://bacula.svn.sourceforge.net/svnroot/bacula/trunk@2054 91ce42f0-d328-0410-95d8-f526ca767f89 --- diff --git a/bacula/src/findlib/attribs.c b/bacula/src/findlib/attribs.c index a9c692e076..79e910e32e 100755 --- a/bacula/src/findlib/attribs.c +++ b/bacula/src/findlib/attribs.c @@ -464,16 +464,18 @@ int encode_attribsEx(JCR *jcr, char *attribsEx, FF_PKT *ff_pkt) if (p_GetFileAttributesExW) { unix_name_to_win32(&ff_pkt->sys_fname, ff_pkt->fname); - WCHAR szBuf[MAX_PATH_UNICODE]; - UTF8_2_wchar(szBuf, ff_pkt->sys_fname, MAX_PATH_UNICODE); + POOLMEM* pwszBuf = get_pool_memory (PM_FNAME); + UTF8_2_wchar(&pwszBuf, ff_pkt->sys_fname); - if (!p_GetFileAttributesExW(szBuf, GetFileExInfoStandard, - (LPVOID)&atts)) { + BOOL b=p_GetFileAttributesExW((LPCWSTR) pwszBuf, GetFileExInfoStandard, (LPVOID)&atts); + free_pool_memory(pwszBuf); + + if (!b) { win_error(jcr, "GetFileAttributesExW:", ff_pkt->sys_fname); return STREAM_UNIX_ATTRIBUTES; } } - else { + else { if (!p_GetFileAttributesExA) return STREAM_UNIX_ATTRIBUTES; @@ -602,16 +604,18 @@ static bool set_win32_attributes(JCR *jcr, ATTR *attr, BFILE *ofd) if (!(atts.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)) { if (p_SetFileAttributesW) { - WCHAR szBuf[MAX_PATH_UNICODE]; - UTF8_2_wchar(szBuf, win32_ofile, MAX_PATH_UNICODE); - - if (!SetFileAttributesW(szBuf, atts.dwFileAttributes & SET_ATTRS)) { - win_error(jcr, "SetFileAttributesW:", win32_ofile); - } + POOLMEM* pwszBuf = get_pool_memory (PM_FNAME); + UTF8_2_wchar(&pwszBuf, win32_ofile); + + BOOL b=SetFileAttributesW((LPCWSTR)pwszBuf, atts.dwFileAttributes & SET_ATTRS); + free_pool_memory(pwszBuf); + + if (!b) + win_error(jcr, "SetFileAttributesW:", win32_ofile); } else { - if (!SetFileAttributes(win32_ofile, atts.dwFileAttributes & SET_ATTRS)) { - win_error(jcr, "SetFileAttributesA:", win32_ofile); + if (!SetFileAttributes(win32_ofile, atts.dwFileAttributes & SET_ATTRS)) { + win_error(jcr, "SetFileAttributesA:", win32_ofile); } } } diff --git a/bacula/src/findlib/bfile.c b/bacula/src/findlib/bfile.c index b89d77698e..7ec967ab67 100644 --- a/bacula/src/findlib/bfile.c +++ b/bacula/src/findlib/bfile.c @@ -211,19 +211,21 @@ HANDLE bget_handle(BFILE *bfd) int bopen(BFILE *bfd, const char *fname, int flags, mode_t mode) { POOLMEM *win32_fname; - DWORD dwaccess, dwflags, dwshare; - WCHAR win32_fname_wchar[MAX_PATH_UNICODE]; + POOLMEM *win32_fname_wchar; + DWORD dwaccess, dwflags, dwshare; + /* Convert to Windows path format */ win32_fname = get_pool_memory(PM_FNAME); + win32_fname_wchar = get_pool_memory(PM_FNAME); + unix_name_to_win32(&win32_fname, (char *)fname); if (!(p_CreateFileA || p_CreateFileW)) return 0; - if (p_CreateFileW){ - UTF8_2_wchar(win32_fname_wchar, win32_fname, MAX_PATH_UNICODE); - } + if (p_CreateFileW && p_MultiByteToWideChar) + UTF8_2_wchar(&win32_fname_wchar, win32_fname); if (flags & O_CREAT) { /* Create */ if (bfd->use_backup_api) { @@ -235,8 +237,8 @@ int bopen(BFILE *bfd, const char *fname, int flags, mode_t mode) } // unicode or ansii open for create write - if (p_CreateFileW) { - bfd->fh = p_CreateFileW(win32_fname_wchar, + if (p_CreateFileW && p_MultiByteToWideChar) { + bfd->fh = p_CreateFileW((LPCWSTR)win32_fname_wchar, dwaccess, /* Requested access */ 0, /* Shared mode */ NULL, /* SecurityAttributes */ @@ -267,8 +269,8 @@ int bopen(BFILE *bfd, const char *fname, int flags, mode_t mode) } // unicode or ansii open for open existing write - if (p_CreateFileW) { - bfd->fh = p_CreateFileW(win32_fname_wchar, + if (p_CreateFileW && p_MultiByteToWideChar) { + bfd->fh = p_CreateFileW((LPCWSTR)win32_fname_wchar, dwaccess, /* Requested access */ 0, /* Shared mode */ NULL, /* SecurityAttributes */ @@ -301,8 +303,8 @@ int bopen(BFILE *bfd, const char *fname, int flags, mode_t mode) } // unicode or ansii open for open existing read - if (p_CreateFileW) { - bfd->fh = p_CreateFileW(win32_fname_wchar, + if (p_CreateFileW && p_MultiByteToWideChar) { + bfd->fh = p_CreateFileW((LPCWSTR)win32_fname_wchar, dwaccess, /* Requested access */ dwshare, /* Share modes */ NULL, /* SecurityAttributes */ @@ -331,6 +333,7 @@ int bopen(BFILE *bfd, const char *fname, int flags, mode_t mode) } bfd->errmsg = NULL; bfd->lpContext = NULL; + free_pool_memory(win32_fname_wchar); free_pool_memory(win32_fname); return bfd->mode == BF_CLOSED ? -1 : 1; } diff --git a/bacula/src/lib/winapi.h b/bacula/src/lib/winapi.h index de5ebf5507..ed3580a416 100644 --- a/bacula/src/lib/winapi.h +++ b/bacula/src/lib/winapi.h @@ -42,12 +42,15 @@ #if defined(HAVE_CYGWIN) || defined(HAVE_WIN32) +#ifndef POOLMEM +typedef char POOLMEM; +#endif + // unicode enabling of win 32 needs some defines and functions -#define MAX_PATH_UNICODE 32767 #define MAX_PATH_UTF8 MAX_PATH*3 int wchar_2_UTF8(char *pszUTF, const WCHAR *pszUCS, int cchChar = MAX_PATH_UTF8); -int UTF8_2_wchar(WCHAR *pszUCS, const char *pszUTF, int cchWideChar = MAX_PATH); +int UTF8_2_wchar(POOLMEM **pszUCS, const char *pszUTF); /* In ADVAPI32.DLL */