GCC Code Coverage Report
Directory: ./ Exec Total Coverage
File: gx_utility_ltoa.c Lines: 21 21 100.0 %
Date: 2026-03-06 19:21:09 Branches: 10 10 100.0 %

Line Branch Exec Source
1
/***************************************************************************
2
 * Copyright (c) 2024 Microsoft Corporation
3
 * Copyright (c) 2026-present Eclipse ThreadX contributors
4
 *
5
 * This program and the accompanying materials are made available under the
6
 * terms of the MIT License which is available at
7
 * https://opensource.org/licenses/MIT.
8
 *
9
 * SPDX-License-Identifier: MIT
10
 **************************************************************************/
11
12
13
/**************************************************************************/
14
/**************************************************************************/
15
/**                                                                       */
16
/** GUIX Component                                                        */
17
/**                                                                       */
18
/**   Utility (Utility)                                                   */
19
/**                                                                       */
20
/**************************************************************************/
21
22
#define GX_SOURCE_CODE
23
24
25
/* Include necessary system files.  */
26
27
#include "gx_api.h"
28
#include "gx_utility.h"
29
30
31
/**************************************************************************/
32
/*                                                                        */
33
/*  FUNCTION                                               RELEASE        */
34
/*                                                                        */
35
/*    _gx_utility_ltoa                                    PORTABLE C      */
36
/*                                                           6.1          */
37
/*  AUTHOR                                                                */
38
/*                                                                        */
39
/*    Kenneth Maxwell, Microsoft Corporation                              */
40
/*                                                                        */
41
/*  DESCRIPTION                                                           */
42
/*                                                                        */
43
/*    This service converts a long integer value into an ASCII string.    */
44
/*                                                                        */
45
/*  INPUT                                                                 */
46
/*                                                                        */
47
/*    value                                 Long integer value to convert */
48
/*    return_buffer                         Destination buffer for ASCII  */
49
/*                                            string                      */
50
/*    return_buffer_size                    Size of destination buffer    */
51
/*                                                                        */
52
/*  OUTPUT                                                                */
53
/*                                                                        */
54
/*    None                                                                */
55
/*                                                                        */
56
/*  CALLS                                                                 */
57
/*                                                                        */
58
/*    None                                                                */
59
/*                                                                        */
60
/*  CALLED BY                                                             */
61
/*                                                                        */
62
/*    Application Code                                                    */
63
/*    GUIX Internal Code                                                  */
64
/*                                                                        */
65
/**************************************************************************/
66
42358
UINT _gx_utility_ltoa(LONG value, GX_CHAR *return_buffer, UINT return_buffer_size)
67
{
68
LONG     temp_val;
69
GX_CHAR  temp_buf[20];
70
GX_CHAR *mirror;
71
GX_CHAR *putchar;
72
INT      quotient;
73
42358
INT      sign = 0;
74
75
42358
    temp_val = value;
76
77
42358
    if (value < 0)
78
    {
79
52
        sign = -1;
80
52
        temp_val = -value;
81
    }
82
83
    /* build the string in our temp_buf. The string will
84
       be in reverse (mirrored) order, we will fix that
85
       when we copy into the output buffer
86
     */
87
88
42358
    mirror = temp_buf;
89
90
    do
91
    {
92
80920
        quotient = temp_val % 10;
93
80920
        temp_val = temp_val / 10;
94
80920
        quotient = quotient | 0x30;
95
80920
        *mirror++ = (GX_CHAR)quotient;
96
80920
    } while (temp_val != 0);
97
98
    /* put a negative sign at the end if needed */
99
100
42358
    if (sign != 0)
101
    {
102
52
        *mirror++ = '-';
103
    }
104
105
    /* now copy the result back into the caller's buffer,
106
       being careful not to exceed the buffer size
107
     */
108
109
42358
    mirror--;
110
42358
    putchar = return_buffer;
111
112

123324
    while (mirror >= temp_buf && return_buffer_size > 1)
113
    {
114
80966
        *putchar++ = *mirror--;
115
80966
        return_buffer_size--;
116
    }
117
118
    /* termniate the return string */
119
42358
    *putchar = 0;
120
42358
    return GX_SUCCESS;
121
}
122