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 "../nls/nls_ucs2_data.h"
12 #include "jfs_types.h"
14 extern int get_UCSname(struct component_name
*, struct dentry
*);
15 extern int jfs_strfromUCS_le(char *, const __le16
*, int, struct nls_table
*);
17 #define free_UCSname(COMP) kfree((COMP)->name)
20 * UniStrcpy: Copy a string
22 static inline wchar_t *UniStrcpy(wchar_t * ucs1
, const wchar_t * ucs2
)
24 wchar_t *anchor
= ucs1
; /* save the start of result string */
26 while ((*ucs1
++ = *ucs2
++));
33 * UniStrncpy: Copy length limited string with pad
35 static inline __le16
*UniStrncpy_le(__le16
* ucs1
, const __le16
* ucs2
,
38 __le16
*anchor
= ucs1
;
40 while (n
-- && *ucs2
) /* Copy the strings */
44 while (n
--) /* Pad with nulls */
50 * UniStrncmp_le: Compare length limited string - native to little-endian
52 static inline int UniStrncmp_le(const wchar_t * ucs1
, const __le16
* ucs2
,
56 return 0; /* Null strings are equal */
57 while ((*ucs1
== __le16_to_cpu(*ucs2
)) && *ucs1
&& --n
) {
61 return (int) *ucs1
- (int) __le16_to_cpu(*ucs2
);
65 * UniStrncpy_to_le: Copy length limited string with pad to little-endian
67 static inline __le16
*UniStrncpy_to_le(__le16
* ucs1
, const wchar_t * ucs2
,
70 __le16
*anchor
= ucs1
;
72 while (n
-- && *ucs2
) /* Copy the strings */
73 *ucs1
++ = cpu_to_le16(*ucs2
++);
76 while (n
--) /* Pad with nulls */
82 * UniStrncpy_from_le: Copy length limited string with pad from little-endian
84 static inline wchar_t *UniStrncpy_from_le(wchar_t * ucs1
, const __le16
* ucs2
,
87 wchar_t *anchor
= ucs1
;
89 while (n
-- && *ucs2
) /* Copy the strings */
90 *ucs1
++ = __le16_to_cpu(*ucs2
++);
93 while (n
--) /* Pad with nulls */
99 * UniToupper: Convert a unicode character to upper case
101 static inline wchar_t UniToupper(wchar_t uc
)
103 const struct UniCaseRange
*rp
;
105 if (uc
< sizeof(NlsUniUpperTable
)) { /* Latin characters */
106 return uc
+ NlsUniUpperTable
[uc
]; /* Use base tables */
108 rp
= NlsUniUpperRange
; /* Use range tables */
110 if (uc
< rp
->start
) /* Before start of range */
111 return uc
; /* Uppercase = input */
112 if (uc
<= rp
->end
) /* In range */
113 return uc
+ rp
->table
[uc
- rp
->start
];
114 rp
++; /* Try next range */
117 return uc
; /* Past last range */
122 * UniStrupr: Upper case a unicode string
124 static inline wchar_t *UniStrupr(wchar_t * upin
)
129 while (*up
) { /* For all characters */
130 *up
= UniToupper(*up
);
133 return upin
; /* Return input pointer */
136 #endif /* !_H_JFS_UNICODE */