1 /* SPDX-License-Identifier: GPL-2.0-or-later */
3 * Copyright (C) International Business Machines Corp., 2000-2002
4 * Portions Copyright (C) Christoph Hellwig, 2001-2002
9 #include <linux/slab.h>
10 #include <asm/byteorder.h>
11 #include "jfs_types.h"
19 extern signed char UniUpperTable
[512];
20 extern UNICASERANGE UniUpperRange
[];
21 extern int get_UCSname(struct component_name
*, struct dentry
*);
22 extern int jfs_strfromUCS_le(char *, const __le16
*, int, struct nls_table
*);
24 #define free_UCSname(COMP) kfree((COMP)->name)
27 * UniStrcpy: Copy a string
29 static inline wchar_t *UniStrcpy(wchar_t * ucs1
, const wchar_t * ucs2
)
31 wchar_t *anchor
= ucs1
; /* save the start of result string */
33 while ((*ucs1
++ = *ucs2
++));
40 * UniStrncpy: Copy length limited string with pad
42 static inline __le16
*UniStrncpy_le(__le16
* ucs1
, const __le16
* ucs2
,
45 __le16
*anchor
= ucs1
;
47 while (n
-- && *ucs2
) /* Copy the strings */
51 while (n
--) /* Pad with nulls */
57 * UniStrncmp_le: Compare length limited string - native to little-endian
59 static inline int UniStrncmp_le(const wchar_t * ucs1
, const __le16
* ucs2
,
63 return 0; /* Null strings are equal */
64 while ((*ucs1
== __le16_to_cpu(*ucs2
)) && *ucs1
&& --n
) {
68 return (int) *ucs1
- (int) __le16_to_cpu(*ucs2
);
72 * UniStrncpy_to_le: Copy length limited string with pad to little-endian
74 static inline __le16
*UniStrncpy_to_le(__le16
* ucs1
, const wchar_t * ucs2
,
77 __le16
*anchor
= ucs1
;
79 while (n
-- && *ucs2
) /* Copy the strings */
80 *ucs1
++ = cpu_to_le16(*ucs2
++);
83 while (n
--) /* Pad with nulls */
89 * UniStrncpy_from_le: Copy length limited string with pad from little-endian
91 static inline wchar_t *UniStrncpy_from_le(wchar_t * ucs1
, const __le16
* ucs2
,
94 wchar_t *anchor
= ucs1
;
96 while (n
-- && *ucs2
) /* Copy the strings */
97 *ucs1
++ = __le16_to_cpu(*ucs2
++);
100 while (n
--) /* Pad with nulls */
106 * UniToupper: Convert a unicode character to upper case
108 static inline wchar_t UniToupper(wchar_t uc
)
112 if (uc
< sizeof(UniUpperTable
)) { /* Latin characters */
113 return uc
+ UniUpperTable
[uc
]; /* Use base tables */
115 rp
= UniUpperRange
; /* Use range tables */
117 if (uc
< rp
->start
) /* Before start of range */
118 return uc
; /* Uppercase = input */
119 if (uc
<= rp
->end
) /* In range */
120 return uc
+ rp
->table
[uc
- rp
->start
];
121 rp
++; /* Try next range */
124 return uc
; /* Past last range */
129 * UniStrupr: Upper case a unicode string
131 static inline wchar_t *UniStrupr(wchar_t * upin
)
136 while (*up
) { /* For all characters */
137 *up
= UniToupper(*up
);
140 return upin
; /* Return input pointer */
143 #endif /* !_H_JFS_UNICODE */