]> git.sur5r.net Git - bacula/bacula/commitdiff
rewrote Win32 unicode support to use poolmemory instead of stack
authorThorsten Engel <thorsten.engel@matrix-computer.com>
Tue, 17 May 2005 14:35:52 +0000 (14:35 +0000)
committerThorsten Engel <thorsten.engel@matrix-computer.com>
Tue, 17 May 2005 14:35:52 +0000 (14:35 +0000)
git-svn-id: https://bacula.svn.sourceforge.net/svnroot/bacula/trunk@2054 91ce42f0-d328-0410-95d8-f526ca767f89

bacula/src/findlib/attribs.c
bacula/src/findlib/bfile.c
bacula/src/lib/winapi.h

index a9c692e0768b87f5033eb074e4d737a7bdf2acdd..79e910e32e2b8213ca73a4e6bcf6740c74094016 100755 (executable)
@@ -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);
         }
       }
    }
index b89d77698ee5dce59d6d47c9efa8035507f9a7ed..7ec967ab671447932f02ab4063654ceac45d3c51 100644 (file)
@@ -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;
 }
index de5ebf55078cff235fb30469dc38a77c547e24e7..ed3580a416484b8153ef4ecee13ef2a0e485b233 100644 (file)
 
 #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 */