diff options
author | Andrew Tridgell <tridge@samba.org> | 2001-09-30 13:30:52 +0000 |
---|---|---|
committer | Andrew Tridgell <tridge@samba.org> | 2001-09-30 13:30:52 +0000 |
commit | 57196635d9b7edfcbfe1708dd22308ab30c02240 (patch) | |
tree | 29fc4faa26fe6ff397452995131ce98839aef15f | |
parent | 14bfd9107a9c875c54e281262f8061c20a5e9398 (diff) | |
download | samba-57196635d9b7edfcbfe1708dd22308ab30c02240.tar.gz samba-57196635d9b7edfcbfe1708dd22308ab30c02240.tar.xz samba-57196635d9b7edfcbfe1708dd22308ab30c02240.zip |
make strupper() and strlower() not modify the string if it doesn't
need modifying
that makes constant strings OK
-rw-r--r-- | source/lib/charcnv.c | 4 | ||||
-rw-r--r-- | source/lib/util_unistr.c | 18 |
2 files changed, 16 insertions, 6 deletions
diff --git a/source/lib/charcnv.c b/source/lib/charcnv.c index adcd8b2aa94..55d56acf59c 100644 --- a/source/lib/charcnv.c +++ b/source/lib/charcnv.c @@ -140,7 +140,7 @@ int unix_strupper(const char *src, size_t srclen, char *dest, size_t destlen) smb_ucs2_t *buffer=(smb_ucs2_t*)cvtbuf; size=convert_string(CH_UNIX, CH_UCS2, src, srclen, buffer, sizeof(cvtbuf)); len=size/2; - strupper_w(buffer); + if (!strupper_w(buffer) && (dest == src)) return srclen; return convert_string(CH_UCS2, CH_UNIX, buffer, size, dest, destlen); } @@ -150,7 +150,7 @@ int unix_strlower(const char *src, size_t srclen, char *dest, size_t destlen) smb_ucs2_t *buffer=(smb_ucs2_t*)cvtbuf; size=convert_string(CH_UNIX, CH_UCS2, src, srclen, buffer, sizeof(cvtbuf)); len=size/2; - strlower_w(buffer); + if (!strlower_w(buffer) && (dest == src)) return srclen; return convert_string(CH_UCS2, CH_UNIX, buffer, size, dest, destlen); } diff --git a/source/lib/util_unistr.c b/source/lib/util_unistr.c index 8248ac073cc..887c15f0d9c 100644 --- a/source/lib/util_unistr.c +++ b/source/lib/util_unistr.c @@ -248,26 +248,36 @@ smb_ucs2_t *strchr_w(const smb_ucs2_t *s, smb_ucs2_t c) /******************************************************************* Convert a string to lower case. + return True if any char is converted ********************************************************************/ -void strlower_w(smb_ucs2_t *s) +BOOL strlower_w(smb_ucs2_t *s) { + BOOL ret = False; while (*s) { - if (isupper_w(*s)) + if (isupper_w(*s)) { *s = tolower_w(*s); + ret = True; + } s++; } + return ret; } /******************************************************************* Convert a string to upper case. + return True if any char is converted ********************************************************************/ -void strupper_w(smb_ucs2_t *s) +BOOL strupper_w(smb_ucs2_t *s) { + BOOL ret = False; while (*s) { - if (islower_w(*s)) + if (islower_w(*s)) { *s = toupper_w(*s); + ret = True; + } s++; } + return ret; } /******************************************************************* |