diff --git a/ChangeLog b/ChangeLog index 8c100e32..18afbdae 100644 --- a/ChangeLog +++ b/ChangeLog @@ -165,6 +165,8 @@ - Don't free extent inodes in attrib.c! (Szakacsits Szabolcs) - Return the attribute list attribute when enumerating attributes, too. Thanks to Szakacsits Szabolcs for pointing this problem out. + - New API function provided by unistr.[hc] and use it in mkntfs: + ntfs_ucsnlen(). 12/03/2002 - 1.6.0 - More mkntfs options and cleanups. Fix typo in usage information of mkntfs. Thanks to Richard Russon for diff --git a/include/unistr.h b/include/unistr.h index 73c99f2c..7b1c45a6 100644 --- a/include/unistr.h +++ b/include/unistr.h @@ -42,6 +42,8 @@ extern int ntfs_ucsncmp(const uchar_t *s1, const uchar_t *s2, size_t n); extern int ntfs_ucsncasecmp(const uchar_t *s1, const uchar_t *s2, size_t n, const uchar_t *upcase, const u32 upcase_size); +extern u32 ntfs_ucsnlen(const uchar_t *s, u32 maxlen); + extern void ntfs_name_upcase(uchar_t *name, u32 name_len, const uchar_t *upcase, const u32 upcase_len); diff --git a/libntfs/unistr.c b/libntfs/unistr.c index 9376cc34..b7f0d014 100644 --- a/libntfs/unistr.c +++ b/libntfs/unistr.c @@ -227,6 +227,29 @@ int ntfs_ucsncasecmp(const uchar_t *s1, const uchar_t *s2, size_t n, return 0; } +/** + * ntfs_ucsnlen - determine the length of a little endian Unicode string + * @s: pointer to Unicode string + * @maxlen: maximum length of string @s + * + * Return the number of Unicode characters in the little endian Unicode + * string @s up to a maximum of maxlen Unicode characters, not including + * the terminating (uchar_t)'\0'. If there is no (uchar_t)'\0' between @s + * and @s + @maxlen, @maxlen is returned. + * + * This function never looks beyond @s + @maxlen. + */ +u32 ntfs_ucsnlen(const uchar_t *s, u32 maxlen) +{ + u32 i; + + for (i = 0; i < maxlen; i++) { + if (!le16_to_cpu(s[i])) + break; + } + return i; +} + /** * ntfs_name_upcase */