GCC Code Coverage Report
Directory: ./ Exec Total Coverage
File: fx_directory_default_get_copy.c Lines: 8 8 100.0 %
Date: 2024-03-11 05:15:45 Branches: 4 4 100.0 %

Line Branch Exec Source
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
/**   Directory                                                           */
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_directory.h"
29
#include "fx_utility.h"
30
31
/**************************************************************************/
32
/*                                                                        */
33
/*  FUNCTION                                               RELEASE        */
34
/*                                                                        */
35
/*    _fx_directory_default_get_copy                      PORTABLE C      */
36
/*                                                           6.1.6        */
37
/*  AUTHOR                                                                */
38
/*                                                                        */
39
/*    William E. Lamie, Microsoft Corporation                             */
40
/*                                                                        */
41
/*  DESCRIPTION                                                           */
42
/*                                                                        */
43
/*    This function copies the last path provided to the                  */
44
/*    fx_directory_default_set function into the specified buffer.        */
45
/*                                                                        */
46
/*  INPUT                                                                 */
47
/*                                                                        */
48
/*    media_ptr                             Media control block pointer   */
49
/*    return_path_name_buffer               Destination buffer for name   */
50
/*    return_path_name_buffer_size          Size of buffer pointed to by  */
51
/*                                            return_path_name_buffer     */
52
/*                                                                        */
53
/*  OUTPUT                                                                */
54
/*                                                                        */
55
/*    return status                                                       */
56
/*                                                                        */
57
/*  CALLS                                                                 */
58
/*                                                                        */
59
/*    None                                                                */
60
/*                                                                        */
61
/*  CALLED BY                                                             */
62
/*                                                                        */
63
/*    Application Code                                                    */
64
/*                                                                        */
65
/*  RELEASE HISTORY                                                       */
66
/*                                                                        */
67
/*    DATE              NAME                      DESCRIPTION             */
68
/*                                                                        */
69
/*  05-19-2020     William E. Lamie         Initial Version 6.0           */
70
/*  09-30-2020     William E. Lamie         Modified comment(s), verified */
71
/*                                            memcpy usage,               */
72
/*                                            resulting in version 6.1    */
73
/*  04-02-2021     William E. Lamie         Modified comment(s), verified */
74
/*                                            memcpy usage,               */
75
/*                                            resulting in version 6.1.6  */
76
/*                                                                        */
77
/**************************************************************************/
78
3
UINT  _fx_directory_default_get_copy(FX_MEDIA *media_ptr, CHAR *return_path_name_buffer, UINT return_path_name_buffer_size)
79
{
80
81
UINT  status;
82
CHAR *return_path_name;
83
UINT  path_name_length_with_null_terminator;
84
85
86
    /* Get the pointer to the path.  */
87
3
    status =  _fx_directory_default_get(media_ptr, &return_path_name);
88
3
    if (status == FX_SUCCESS)
89
    {
90
91
        /* Get the length of the path.  */
92
2
        path_name_length_with_null_terminator =  _fx_utility_string_length_get(return_path_name, FX_MAXIMUM_PATH) + 1;
93
94
        /* Can it fit in the user's buffer? */
95
2
        if (path_name_length_with_null_terminator <= return_path_name_buffer_size)
96
        {
97
98
            /* Copy the path name into the user's buffer.  */
99
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. */
100
        }
101
        else
102
        {
103
104
            /* Buffer is too small. Return error.  */
105
1
            return(FX_BUFFER_ERROR);
106
        }
107
108
    }
109
110
    /* Return successful status.  */
111
2
    return(status);
112
}
113