Linux 6.14-rc2
[linux.git] / fs / jfs / jfs_unicode.h
blobb6a78d4aef1b02960254d9fb497592e31894cd03
1 /* SPDX-License-Identifier: GPL-2.0-or-later */
2 /*
3 * Copyright (C) International Business Machines Corp., 2000-2002
4 * Portions Copyright (C) Christoph Hellwig, 2001-2002
5 */
6 #ifndef _H_JFS_UNICODE
7 #define _H_JFS_UNICODE
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++));
27 return anchor;
33 * UniStrncpy: Copy length limited string with pad
35 static inline __le16 *UniStrncpy_le(__le16 * ucs1, const __le16 * ucs2,
36 size_t n)
38 __le16 *anchor = ucs1;
40 while (n-- && *ucs2) /* Copy the strings */
41 *ucs1++ = *ucs2++;
43 n++;
44 while (n--) /* Pad with nulls */
45 *ucs1++ = 0;
46 return anchor;
50 * UniStrncmp_le: Compare length limited string - native to little-endian
52 static inline int UniStrncmp_le(const wchar_t * ucs1, const __le16 * ucs2,
53 size_t n)
55 if (!n)
56 return 0; /* Null strings are equal */
57 while ((*ucs1 == __le16_to_cpu(*ucs2)) && *ucs1 && --n) {
58 ucs1++;
59 ucs2++;
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,
68 size_t n)
70 __le16 *anchor = ucs1;
72 while (n-- && *ucs2) /* Copy the strings */
73 *ucs1++ = cpu_to_le16(*ucs2++);
75 n++;
76 while (n--) /* Pad with nulls */
77 *ucs1++ = 0;
78 return anchor;
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,
85 size_t n)
87 wchar_t *anchor = ucs1;
89 while (n-- && *ucs2) /* Copy the strings */
90 *ucs1++ = __le16_to_cpu(*ucs2++);
92 n++;
93 while (n--) /* Pad with nulls */
94 *ucs1++ = 0;
95 return anchor;
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 */
107 } else {
108 rp = NlsUniUpperRange; /* Use range tables */
109 while (rp->start) {
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)
126 wchar_t *up;
128 up = upin;
129 while (*up) { /* For all characters */
130 *up = UniToupper(*up);
131 up++;
133 return upin; /* Return input pointer */
136 #endif /* !_H_JFS_UNICODE */