Add function next_mb_char_size() that returns a size_t of the number of
authorJeremy Allison <jra@samba.org>
Tue, 16 Mar 2004 21:59:20 +0000 (21:59 +0000)
committerJeremy Allison <jra@samba.org>
Tue, 16 Mar 2004 21:59:20 +0000 (21:59 +0000)
bytes in the mb character at a pointer. Will be useful in fixing check_path_syntax()
to not use a "blacklist". Also re-added my (C) to reply.c. I mean, really - I've
been adding code to the file for over 10 years and I recognise many of the
fuctions as mine ! :-).
Jeremy.

source/lib/charcnv.c
source/smbd/reply.c

index b06d869bcc3eccbd6a1cf5f8b311d57cd3ca8802..9ec6e739705d8b49dc106f099ffd4c8c58f0d5f8 100644 (file)
@@ -1313,3 +1313,27 @@ size_t align_string(const void *base_ptr, const char *p, int flags)
        }
        return 0;
 }
+
+/****************************************************************
+ Calculate the size (in bytes) of the next multibyte character in
+ our internal character set. Note that p must be pointing to a
+ valid mb char, not within one.
+****************************************************************/
+
+size_t next_mb_char_size(const char *s)
+{
+       size_t i;
+
+       if (!(*s & 0x80))
+               return 1; /* ascii. */
+
+       for ( i = 1; i <=4; i++ ) {
+               smb_ucs2_t uc;
+               if (convert_string(CH_UNIX, CH_UCS2, s, i, &uc, 2, False) == 2) {
+                       return i;
+               }
+       }
+       /* We're hosed - we don't know how big this is... */
+       DEBUG(10,("next_mb_char_size: unknown size at string %s\n", s));
+       return 1;
+}
index 48894308d1b7bfe5c3e8a0acea173bd286a7d10c..c470d15645da811bf6c4c082227364ca59cc5ffa 100644 (file)
@@ -3,6 +3,7 @@
    Main SMB reply routines
    Copyright (C) Andrew Tridgell 1992-1998
    Copyright (C) Andrew Bartlett      2001
+   Copyright (C) Jeremy Allison 1992-2004.
 
    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