~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

TOMOYO Linux Cross Reference
Linux/fs/nls/nls_ucs2_utils.h

Version: ~ [ linux-6.12-rc7 ] ~ [ linux-6.11.7 ] ~ [ linux-6.10.14 ] ~ [ linux-6.9.12 ] ~ [ linux-6.8.12 ] ~ [ linux-6.7.12 ] ~ [ linux-6.6.60 ] ~ [ linux-6.5.13 ] ~ [ linux-6.4.16 ] ~ [ linux-6.3.13 ] ~ [ linux-6.2.16 ] ~ [ linux-6.1.116 ] ~ [ linux-6.0.19 ] ~ [ linux-5.19.17 ] ~ [ linux-5.18.19 ] ~ [ linux-5.17.15 ] ~ [ linux-5.16.20 ] ~ [ linux-5.15.171 ] ~ [ linux-5.14.21 ] ~ [ linux-5.13.19 ] ~ [ linux-5.12.19 ] ~ [ linux-5.11.22 ] ~ [ linux-5.10.229 ] ~ [ linux-5.9.16 ] ~ [ linux-5.8.18 ] ~ [ linux-5.7.19 ] ~ [ linux-5.6.19 ] ~ [ linux-5.5.19 ] ~ [ linux-5.4.285 ] ~ [ linux-5.3.18 ] ~ [ linux-5.2.21 ] ~ [ linux-5.1.21 ] ~ [ linux-5.0.21 ] ~ [ linux-4.20.17 ] ~ [ linux-4.19.323 ] ~ [ linux-4.18.20 ] ~ [ linux-4.17.19 ] ~ [ linux-4.16.18 ] ~ [ linux-4.15.18 ] ~ [ linux-4.14.336 ] ~ [ linux-4.13.16 ] ~ [ linux-4.12.14 ] ~ [ linux-4.11.12 ] ~ [ linux-4.10.17 ] ~ [ linux-4.9.337 ] ~ [ linux-4.4.302 ] ~ [ linux-3.10.108 ] ~ [ linux-2.6.32.71 ] ~ [ linux-2.6.0 ] ~ [ linux-2.4.37.11 ] ~ [ unix-v6-master ] ~ [ ccs-tools-1.8.12 ] ~ [ policy-sample ] ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

Diff markup

Differences between /fs/nls/nls_ucs2_utils.h (Version linux-6.12-rc7) and /fs/nls/nls_ucs2_utils.h (Version linux-5.7.19)


  1 /* SPDX-License-Identifier: GPL-2.0-or-later *      1 
  2 /*                                                
  3  * Some of the source code in this file came f    
  4  * and then via server/unicode.c                  
  5  * cifs_unicode:  Unicode kernel case support     
  6  *                                                
  7  * Function:                                      
  8  *     Convert a unicode character to upper or    
  9  *     compressed tables.                         
 10  *                                                
 11  *   Copyright (c) International Business Mach    
 12  *                                                
 13  *                                                
 14  * Notes:                                         
 15  *     These APIs are based on the C library f    
 16  *     should match the C functions but with e    
 17  *                                                
 18  *     The upper/lower functions are based on     
 19  *     This is a compressed table of upper and    
 20  *                                                
 21  */                                               
 22 #ifndef _NLS_UCS2_UTILS_H                         
 23 #define _NLS_UCS2_UTILS_H                         
 24                                                   
 25 #include <asm/byteorder.h>                        
 26 #include <linux/types.h>                          
 27 #include <linux/nls.h>                            
 28 #include <linux/unicode.h>                        
 29 #include "nls_ucs2_data.h"                        
 30                                                   
 31 /*                                                
 32  * Windows maps these to the user defined 16 b    
 33  * reserved symbols (along with \ and /), othe    
 34  * in filenames in NTFS                           
 35  */                                               
 36 #define UNI_ASTERISK    ((__u16)('*' + 0xF000)    
 37 #define UNI_QUESTION    ((__u16)('?' + 0xF000)    
 38 #define UNI_COLON       ((__u16)(':' + 0xF000)    
 39 #define UNI_GRTRTHAN    ((__u16)('>' + 0xF000)    
 40 #define UNI_LESSTHAN    ((__u16)('<' + 0xF000)    
 41 #define UNI_PIPE        ((__u16)('|' + 0xF000)    
 42 #define UNI_SLASH       ((__u16)('\\' + 0xF000    
 43                                                   
 44 /*                                                
 45  * UniStrcat:  Concatenate the second string t    
 46  *                                                
 47  * Returns:                                       
 48  *     Address of the first string                
 49  */                                               
 50 static inline wchar_t *UniStrcat(wchar_t *ucs1    
 51 {                                                 
 52         wchar_t *anchor = ucs1; /* save a poin    
 53                                                   
 54         while (*ucs1++)                           
 55         /*NULL*/;       /* To end of first str    
 56         ucs1--;                 /* Return to t    
 57         while ((*ucs1++ = *ucs2++))               
 58         /*NULL*/;       /* copy string 2 over     
 59         return anchor;                            
 60 }                                                 
 61                                                   
 62 /*                                                
 63  * UniStrchr:  Find a character in a string       
 64  *                                                
 65  * Returns:                                       
 66  *     Address of first occurrence of characte    
 67  *     or NULL if the character is not in the     
 68  */                                               
 69 static inline wchar_t *UniStrchr(const wchar_t    
 70 {                                                 
 71         while ((*ucs != uc) && *ucs)              
 72                 ucs++;                            
 73                                                   
 74         if (*ucs == uc)                           
 75                 return (wchar_t *)ucs;            
 76         return NULL;                              
 77 }                                                 
 78                                                   
 79 /*                                                
 80  * UniStrcmp:  Compare two strings                
 81  *                                                
 82  * Returns:                                       
 83  *     < 0:  First string is less than second     
 84  *     = 0:  Strings are equal                    
 85  *     > 0:  First string is greater than seco    
 86  */                                               
 87 static inline int UniStrcmp(const wchar_t *ucs    
 88 {                                                 
 89         while ((*ucs1 == *ucs2) && *ucs1) {       
 90                 ucs1++;                           
 91                 ucs2++;                           
 92         }                                         
 93         return (int)*ucs1 - (int)*ucs2;           
 94 }                                                 
 95                                                   
 96 /*                                                
 97  * UniStrcpy:  Copy a string                      
 98  */                                               
 99 static inline wchar_t *UniStrcpy(wchar_t *ucs1    
100 {                                                 
101         wchar_t *anchor = ucs1; /* save the st    
102                                                   
103         while ((*ucs1++ = *ucs2++))               
104         /*NULL*/;                                 
105         return anchor;                            
106 }                                                 
107                                                   
108 /*                                                
109  * UniStrlen:  Return the length of a string (    
110  */                                               
111 static inline size_t UniStrlen(const wchar_t *    
112 {                                                 
113         int i = 0;                                
114                                                   
115         while (*ucs1++)                           
116                 i++;                              
117         return i;                                 
118 }                                                 
119                                                   
120 /*                                                
121  * UniStrnlen:  Return the length (in 16 bit U    
122  *              string (length limited)           
123  */                                               
124 static inline size_t UniStrnlen(const wchar_t     
125 {                                                 
126         int i = 0;                                
127                                                   
128         while (*ucs1++) {                         
129                 i++;                              
130                 if (i >= maxlen)                  
131                         break;                    
132         }                                         
133         return i;                                 
134 }                                                 
135                                                   
136 /*                                                
137  * UniStrncat:  Concatenate length limited str    
138  */                                               
139 static inline wchar_t *UniStrncat(wchar_t *ucs    
140 {                                                 
141         wchar_t *anchor = ucs1; /* save pointe    
142                                                   
143         while (*ucs1++)                           
144         /*NULL*/;                                 
145         ucs1--;                 /* point to nu    
146         while (n-- && (*ucs1 = *ucs2)) {          
147                 ucs1++;                           
148                 ucs2++;                           
149         }                                         
150         *ucs1 = 0;              /* Null termin    
151         return anchor;                            
152 }                                                 
153                                                   
154 /*                                                
155  * UniStrncmp:  Compare length limited string     
156  */                                               
157 static inline int UniStrncmp(const wchar_t *uc    
158 {                                                 
159         if (!n)                                   
160                 return 0;       /* Null string    
161         while ((*ucs1 == *ucs2) && *ucs1 && --    
162                 ucs1++;                           
163                 ucs2++;                           
164         }                                         
165         return (int)*ucs1 - (int)*ucs2;           
166 }                                                 
167                                                   
168 /*                                                
169  * UniStrncmp_le:  Compare length limited stri    
170  */                                               
171 static inline int                                 
172 UniStrncmp_le(const wchar_t *ucs1, const wchar    
173 {                                                 
174         if (!n)                                   
175                 return 0;       /* Null string    
176         while ((*ucs1 == __le16_to_cpu(*ucs2))    
177                 ucs1++;                           
178                 ucs2++;                           
179         }                                         
180         return (int)*ucs1 - (int)__le16_to_cpu    
181 }                                                 
182                                                   
183 /*                                                
184  * UniStrncpy:  Copy length limited string wit    
185  */                                               
186 static inline wchar_t *UniStrncpy(wchar_t *ucs    
187 {                                                 
188         wchar_t *anchor = ucs1;                   
189                                                   
190         while (n-- && *ucs2)    /* Copy the st    
191                 *ucs1++ = *ucs2++;                
192                                                   
193         n++;                                      
194         while (n--)             /* Pad with nu    
195                 *ucs1++ = 0;                      
196         return anchor;                            
197 }                                                 
198                                                   
199 /*                                                
200  * UniStrncpy_le:  Copy length limited string     
201  */                                               
202 static inline wchar_t *UniStrncpy_le(wchar_t *    
203 {                                                 
204         wchar_t *anchor = ucs1;                   
205                                                   
206         while (n-- && *ucs2)    /* Copy the st    
207                 *ucs1++ = __le16_to_cpu(*ucs2+    
208                                                   
209         n++;                                      
210         while (n--)             /* Pad with nu    
211                 *ucs1++ = 0;                      
212         return anchor;                            
213 }                                                 
214                                                   
215 /*                                                
216  * UniStrstr:  Find a string in a string          
217  *                                                
218  * Returns:                                       
219  *     Address of first match found               
220  *     NULL if no matching string is found        
221  */                                               
222 static inline wchar_t *UniStrstr(const wchar_t    
223 {                                                 
224         const wchar_t *anchor1 = ucs1;            
225         const wchar_t *anchor2 = ucs2;            
226                                                   
227         while (*ucs1) {                           
228                 if (*ucs1 == *ucs2) {             
229                         /* Partial match found    
230                         ucs1++;                   
231                         ucs2++;                   
232                 } else {                          
233                         if (!*ucs2)     /* Mat    
234                                 return (wchar_    
235                         ucs1 = ++anchor1;         
236                         ucs2 = anchor2;           
237                 }                                 
238         }                                         
239                                                   
240         if (!*ucs2)             /* Both end to    
241                 return (wchar_t *)anchor1;        
242         return NULL;            /* No match */    
243 }                                                 
244                                                   
245 #ifndef UNIUPR_NOUPPER                            
246 /*                                                
247  * UniToupper:  Convert a unicode character to    
248  */                                               
249 static inline wchar_t UniToupper(register wcha    
250 {                                                 
251         register const struct UniCaseRange *rp    
252                                                   
253         if (uc < sizeof(NlsUniUpperTable)) {      
254                 /* Latin characters */            
255                 return uc + NlsUniUpperTable[u    
256         }                                         
257                                                   
258         rp = NlsUniUpperRange;  /* Use range t    
259         while (rp->start) {                       
260                 if (uc < rp->start)     /* Bef    
261                         return uc;      /* Upp    
262                 if (uc <= rp->end)      /* In     
263                         return uc + rp->table[    
264                 rp++;   /* Try next range */      
265         }                                         
266         return uc;              /* Past last r    
267 }                                                 
268                                                   
269 /*                                                
270  * UniStrupr:  Upper case a unicode string        
271  */                                               
272 static inline __le16 *UniStrupr(register __le1    
273 {                                                 
274         register __le16 *up;                      
275                                                   
276         up = upin;                                
277         while (*up) {           /* For all cha    
278                 *up = cpu_to_le16(UniToupper(l    
279                 up++;                             
280         }                                         
281         return upin;            /* Return inpu    
282 }                                                 
283 #endif                          /* UNIUPR_NOUP    
284                                                   
285 #endif /* _NLS_UCS2_UTILS_H */                    
286                                                   

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

kernel.org | git.kernel.org | LWN.net | Project Home | SVN repository | Mail admin

Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.

sflogo.php