r23779: Change from v2 or later to v3 or later.
[ira/wip.git] / source3 / lib / charcnv.c
index 3d02988a97945da53c73816c4cb1ac5448da6349..226a105d48b486d22786efad3dbf5e2177a0e27d 100644 (file)
@@ -8,7 +8,7 @@
    
    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
-   the Free Software Foundation; either version 2 of the License, or
+   the Free Software Foundation; either version 3 of the License, or
    (at your option) any later version.
    
    This program is distributed in the hope that it will be useful,
@@ -168,7 +168,7 @@ void init_iconv(void)
                                conv_handles[c1][c2] = smb_iconv_open(n2,n1);
                                if (!conv_handles[c1][c2]) {
                                        DEBUG(0,("init_iconv: Conversion from %s to %s failed", n1, n2));
-                                       smb_panic("init_iconv: conv_handle initialization failed.");
+                                       smb_panic("init_iconv: conv_handle initialization failed");
                                }
                        }
                }
@@ -972,13 +972,18 @@ size_t pull_ascii(char *dest, const void *src, size_t dest_len, size_t src_len,
 
        ret = convert_string(CH_DOS, CH_UNIX, src, src_len, dest, dest_len, True);
        if (ret == (size_t)-1) {
+               ret = 0;
                dest_len = 0;
        }
 
-       if (dest_len)
-               dest[MIN(ret, dest_len-1)] = 0;
-       else 
+       if (dest_len && ret) {
+               /* Did we already process the terminating zero ? */
+               if (dest[MIN(ret-1, dest_len-1)] != 0) {
+                       dest[MIN(ret, dest_len-1)] = 0;
+               }
+       } else  {
                dest[0] = 0;
+       }
 
        return src_len;
 }
@@ -1219,10 +1224,14 @@ size_t pull_ucs2(const void *base_ptr, char *dest, const void *src, size_t dest_
        if (src_len == (size_t)-1)
                src_len = ret*2;
                
-       if (dest_len)
-               dest[MIN(ret, dest_len-1)] = 0;
-       else 
+       if (dest_len && ret) {
+               /* Did we already process the terminating zero ? */
+               if (dest[MIN(ret-1, dest_len-1)] != 0) {
+                       dest[MIN(ret, dest_len-1)] = 0;
+               }
+       } else {
                dest[0] = 0;
+       }
 
        return src_len;
 }
@@ -1367,16 +1376,24 @@ size_t push_string_fn(const char *function, unsigned int line, const void *base_
  The resulting string in "dest" is always null terminated.
 **/
 
-size_t pull_string_fn(const char *function, unsigned int line, const void *base_ptr, char *dest, const void *src, size_t dest_len, size_t src_len, int flags)
+size_t pull_string_fn(const char *function, unsigned int line,
+                     const void *base_ptr, uint16 smb_flags2, char *dest,
+                     const void *src, size_t dest_len, size_t src_len,
+                     int flags)
 {
 #ifdef DEVELOPER
        if (dest_len != (size_t)-1)
                clobber_region(function, line, dest, dest_len);
 #endif
 
+       if ((base_ptr == NULL) && ((flags & (STR_ASCII|STR_UNICODE)) == 0)) {
+               smb_panic("No base ptr to get flg2 and neither ASCII nor "
+                         "UNICODE defined");
+       }
+
        if (!(flags & STR_ASCII) && \
            ((flags & STR_UNICODE || \
-             (SVAL(base_ptr, smb_flg2) & FLAGS2_UNICODE_STRINGS)))) {
+             (smb_flags2 & FLAGS2_UNICODE_STRINGS)))) {
                return pull_ucs2(base_ptr, dest, src, dest_len, src_len, flags);
        }
        return pull_ascii(dest, src, dest_len, src_len, flags);