1 /***************************************************************************
2  * Copyright (c) 2024 Microsoft Corporation
3  *
4  * This program and the accompanying materials are made available under the
5  * terms of the MIT License which is available at
6  * https://opensource.org/licenses/MIT.
7  *
8  * SPDX-License-Identifier: MIT
9  **************************************************************************/
10 
11 
12 /**************************************************************************/
13 /**************************************************************************/
14 /**                                                                       */
15 /** FileX Component                                                       */
16 /**                                                                       */
17 /**   Unicode                                                             */
18 /**                                                                       */
19 /**************************************************************************/
20 /**************************************************************************/
21 
22 #define FX_SOURCE_CODE
23 
24 
25 /* Include necessary system files.  */
26 
27 #include "fx_api.h"
28 #include "fx_unicode.h"
29 
30 
31 /**************************************************************************/
32 /*                                                                        */
33 /*  FUNCTION                                               RELEASE        */
34 /*                                                                        */
35 /*    _fx_unicode_length_get_extended                     PORTABLE C      */
36 /*                                                           6.1          */
37 /*  AUTHOR                                                                */
38 /*                                                                        */
39 /*    William E. Lamie, Microsoft Corporation                             */
40 /*                                                                        */
41 /*  DESCRIPTION                                                           */
42 /*                                                                        */
43 /*    This function returns the length of the supplied unicode name.      */
44 /*                                                                        */
45 /*  INPUT                                                                 */
46 /*                                                                        */
47 /*    unicode_name                          Pointer to unicode name       */
48 /*    buffer_length                         Buffer length for unicode name*/
49 /*                                                                        */
50 /*  OUTPUT                                                                */
51 /*                                                                        */
52 /*    length                                                              */
53 /*                                                                        */
54 /*  CALLS                                                                 */
55 /*                                                                        */
56 /*    None                                                                */
57 /*                                                                        */
58 /*  CALLED BY                                                             */
59 /*                                                                        */
60 /*    Application Code                                                    */
61 /*                                                                        */
62 /*  RELEASE HISTORY                                                       */
63 /*                                                                        */
64 /*    DATE              NAME                      DESCRIPTION             */
65 /*                                                                        */
66 /*  05-19-2020     William E. Lamie         Initial Version 6.0           */
67 /*  09-30-2020     William E. Lamie         Modified comment(s),          */
68 /*                                            resulting in version 6.1    */
69 /*                                                                        */
70 /**************************************************************************/
_fx_unicode_length_get_extended(UCHAR * unicode_name,UINT buffer_length)71 ULONG  _fx_unicode_length_get_extended(UCHAR *unicode_name, UINT buffer_length)
72 {
73 
74 ULONG i;
75 ULONG length;
76 
77 
78     i =  0;
79     length =  0;
80     while (i < buffer_length)
81     {
82 
83         /* See if we are at the end of the unicode string...  This assumes that there is a NULL at the end of the string.  */
84         if ((unicode_name[i] == 0) && (unicode_name[i + 1] == 0))
85         {
86             break;
87         }
88 
89         /* Increment index.  */
90         i =  i + 2;
91 
92         /* Increment the length.  */
93         length++;
94     }
95 
96     /* If trace is enabled, insert this event into the trace buffer.  */
97     FX_TRACE_IN_LINE_INSERT(FX_TRACE_UNICODE_LENGTH_GET, unicode_name, length, 0, 0, FX_TRACE_FILE_EVENTS, 0, 0)
98 
99     /* Return length.  */
100     return(length);
101 }
102 
103