Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: GPL-2.0-or-later */
0002 /*
0003  *   Copyright (C) International Business Machines Corp., 2000-2002
0004  *   Portions Copyright (C) Christoph Hellwig, 2001-2002
0005  */
0006 #ifndef _H_JFS_UNICODE
0007 #define _H_JFS_UNICODE
0008 
0009 #include <linux/slab.h>
0010 #include <asm/byteorder.h>
0011 #include "jfs_types.h"
0012 
0013 typedef struct {
0014     wchar_t start;
0015     wchar_t end;
0016     signed char *table;
0017 } UNICASERANGE;
0018 
0019 extern signed char UniUpperTable[512];
0020 extern UNICASERANGE UniUpperRange[];
0021 extern int get_UCSname(struct component_name *, struct dentry *);
0022 extern int jfs_strfromUCS_le(char *, const __le16 *, int, struct nls_table *);
0023 
0024 #define free_UCSname(COMP) kfree((COMP)->name)
0025 
0026 /*
0027  * UniStrcpy:  Copy a string
0028  */
0029 static inline wchar_t *UniStrcpy(wchar_t * ucs1, const wchar_t * ucs2)
0030 {
0031     wchar_t *anchor = ucs1; /* save the start of result string */
0032 
0033     while ((*ucs1++ = *ucs2++));
0034     return anchor;
0035 }
0036 
0037 
0038 
0039 /*
0040  * UniStrncpy:  Copy length limited string with pad
0041  */
0042 static inline __le16 *UniStrncpy_le(__le16 * ucs1, const __le16 * ucs2,
0043                   size_t n)
0044 {
0045     __le16 *anchor = ucs1;
0046 
0047     while (n-- && *ucs2)    /* Copy the strings */
0048         *ucs1++ = *ucs2++;
0049 
0050     n++;
0051     while (n--)     /* Pad with nulls */
0052         *ucs1++ = 0;
0053     return anchor;
0054 }
0055 
0056 /*
0057  * UniStrncmp_le:  Compare length limited string - native to little-endian
0058  */
0059 static inline int UniStrncmp_le(const wchar_t * ucs1, const __le16 * ucs2,
0060                 size_t n)
0061 {
0062     if (!n)
0063         return 0;   /* Null strings are equal */
0064     while ((*ucs1 == __le16_to_cpu(*ucs2)) && *ucs1 && --n) {
0065         ucs1++;
0066         ucs2++;
0067     }
0068     return (int) *ucs1 - (int) __le16_to_cpu(*ucs2);
0069 }
0070 
0071 /*
0072  * UniStrncpy_to_le:  Copy length limited string with pad to little-endian
0073  */
0074 static inline __le16 *UniStrncpy_to_le(__le16 * ucs1, const wchar_t * ucs2,
0075                        size_t n)
0076 {
0077     __le16 *anchor = ucs1;
0078 
0079     while (n-- && *ucs2)    /* Copy the strings */
0080         *ucs1++ = cpu_to_le16(*ucs2++);
0081 
0082     n++;
0083     while (n--)     /* Pad with nulls */
0084         *ucs1++ = 0;
0085     return anchor;
0086 }
0087 
0088 /*
0089  * UniStrncpy_from_le:  Copy length limited string with pad from little-endian
0090  */
0091 static inline wchar_t *UniStrncpy_from_le(wchar_t * ucs1, const __le16 * ucs2,
0092                       size_t n)
0093 {
0094     wchar_t *anchor = ucs1;
0095 
0096     while (n-- && *ucs2)    /* Copy the strings */
0097         *ucs1++ = __le16_to_cpu(*ucs2++);
0098 
0099     n++;
0100     while (n--)     /* Pad with nulls */
0101         *ucs1++ = 0;
0102     return anchor;
0103 }
0104 
0105 /*
0106  * UniToupper:  Convert a unicode character to upper case
0107  */
0108 static inline wchar_t UniToupper(wchar_t uc)
0109 {
0110     UNICASERANGE *rp;
0111 
0112     if (uc < sizeof(UniUpperTable)) {   /* Latin characters */
0113         return uc + UniUpperTable[uc];  /* Use base tables */
0114     } else {
0115         rp = UniUpperRange; /* Use range tables */
0116         while (rp->start) {
0117             if (uc < rp->start) /* Before start of range */
0118                 return uc;  /* Uppercase = input */
0119             if (uc <= rp->end)  /* In range */
0120                 return uc + rp->table[uc - rp->start];
0121             rp++;   /* Try next range */
0122         }
0123     }
0124     return uc;      /* Past last range */
0125 }
0126 
0127 
0128 /*
0129  * UniStrupr:  Upper case a unicode string
0130  */
0131 static inline wchar_t *UniStrupr(wchar_t * upin)
0132 {
0133     wchar_t *up;
0134 
0135     up = upin;
0136     while (*up) {       /* For all characters */
0137         *up = UniToupper(*up);
0138         up++;
0139     }
0140     return upin;        /* Return input pointer */
0141 }
0142 
0143 #endif              /* !_H_JFS_UNICODE */