GCC Code Coverage Report
Directory: ./ Exec Total Coverage
File: fx_directory_local_path_get_copy.c Lines: 10 10 100.0 %
Date: 2026-03-06 18:49:02 Branches: 6 6 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
/** FileX Component                                                       */
17
/**                                                                       */
18
/**   Directory                                                           */
19
/**                                                                       */
20
/**************************************************************************/
21
/**************************************************************************/
22
23
#define FX_SOURCE_CODE
24
25
26
/* Include necessary system files.  */
27
28
#include "fx_api.h"
29
#include "fx_system.h"
30
#include "fx_file.h"
31
#include "fx_utility.h"
32
#include "fx_directory.h"
33
34
/**************************************************************************/
35
/*                                                                        */
36
/*  FUNCTION                                               RELEASE        */
37
/*                                                                        */
38
/*    _fx_directory_local_path_get_copy                   PORTABLE C      */
39
/*                                                           6.1          */
40
/*  AUTHOR                                                                */
41
/*                                                                        */
42
/*    William E. Lamie, Microsoft Corporation                             */
43
/*                                                                        */
44
/*  DESCRIPTION                                                           */
45
/*                                                                        */
46
/*    This function copies the local default directory for this thread    */
47
/*    into the specified buffer.                                          */
48
/*                                                                        */
49
/*  INPUT                                                                 */
50
/*                                                                        */
51
/*    media_ptr                             Media control block pointer   */
52
/*    return_path_name_buffer               Destination buffer for name   */
53
/*    return_path_name_buffer_size          Size of buffer pointed to by  */
54
/*                                            return_path_name_buffer     */
55
/*                                                                        */
56
/*  OUTPUT                                                                */
57
/*                                                                        */
58
/*    return status                                                       */
59
/*                                                                        */
60
/*  CALLS                                                                 */
61
/*                                                                        */
62
/*    None                                                                */
63
/*                                                                        */
64
/*  CALLED BY                                                             */
65
/*                                                                        */
66
/*    Application Code                                                    */
67
/*                                                                        */
68
/**************************************************************************/
69
4
UINT  _fx_directory_local_path_get_copy(FX_MEDIA *media_ptr, CHAR *return_path_name_buffer, UINT return_path_name_buffer_size)
70
{
71
72
UINT  status;
73
CHAR *return_path_name;
74
UINT  path_name_length_with_null_terminator;
75
76
77
    /* Get the pointer to the path.  */
78
4
    status =  _fx_directory_local_path_get(media_ptr, &return_path_name);
79
4
    if (status == FX_SUCCESS)
80
    {
81
82
        /* Was a path set?  */
83
3
        if (return_path_name != FX_NULL)
84
        {
85
86
            /* Get the length of the path.  */
87
2
            path_name_length_with_null_terminator =  _fx_utility_string_length_get(return_path_name, FX_MAXIMUM_PATH) + 1;
88
89
            /* Can it fit in the user's buffer? */
90
2
            if (path_name_length_with_null_terminator <= return_path_name_buffer_size)
91
            {
92
93
                /* Copy the path name into the user's buffer.  */
94
1
                _fx_utility_memory_copy((UCHAR *) return_path_name, (UCHAR *) return_path_name_buffer, path_name_length_with_null_terminator); /* Use case of memcpy is verified. */
95
            }
96
            else
97
            {
98
99
                /* Buffer is too small. Return error.  */
100
1
                return(FX_BUFFER_ERROR);
101
            }
102
        }
103
        else
104
        {
105
106
            /* Set zero-length string.  */
107
1
            return_path_name_buffer[0] = '\0';
108
        }
109
    }
110
111
    /* Return status.  */
112
3
    return(status);
113
}
114