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_system.h"
29 #include "fx_file.h"
30 #include "fx_utility.h"
31 #include "fx_directory.h"
32 
33 /**************************************************************************/
34 /*                                                                        */
35 /*  FUNCTION                                               RELEASE        */
36 /*                                                                        */
37 /*    _fx_directory_local_path_get_copy                   PORTABLE C      */
38 /*                                                           6.1          */
39 /*  AUTHOR                                                                */
40 /*                                                                        */
41 /*    William E. Lamie, Microsoft Corporation                             */
42 /*                                                                        */
43 /*  DESCRIPTION                                                           */
44 /*                                                                        */
45 /*    This function copies the local default directory for this thread    */
46 /*    into the specified buffer.                                          */
47 /*                                                                        */
48 /*  INPUT                                                                 */
49 /*                                                                        */
50 /*    media_ptr                             Media control block pointer   */
51 /*    return_path_name_buffer               Destination buffer for name   */
52 /*    return_path_name_buffer_size          Size of buffer pointed to by  */
53 /*                                            return_path_name_buffer     */
54 /*                                                                        */
55 /*  OUTPUT                                                                */
56 /*                                                                        */
57 /*    return status                                                       */
58 /*                                                                        */
59 /*  CALLS                                                                 */
60 /*                                                                        */
61 /*    None                                                                */
62 /*                                                                        */
63 /*  CALLED BY                                                             */
64 /*                                                                        */
65 /*    Application Code                                                    */
66 /*                                                                        */
67 /*  RELEASE HISTORY                                                       */
68 /*                                                                        */
69 /*    DATE              NAME                      DESCRIPTION             */
70 /*                                                                        */
71 /*  05-19-2020     William E. Lamie         Initial Version 6.0           */
72 /*  09-30-2020     William E. Lamie         Modified comment(s), verified */
73 /*                                            memcpy usage,               */
74 /*                                            resulting in version 6.1    */
75 /*                                                                        */
76 /**************************************************************************/
_fx_directory_local_path_get_copy(FX_MEDIA * media_ptr,CHAR * return_path_name_buffer,UINT return_path_name_buffer_size)77 UINT  _fx_directory_local_path_get_copy(FX_MEDIA *media_ptr, CHAR *return_path_name_buffer, UINT return_path_name_buffer_size)
78 {
79 
80 UINT  status;
81 CHAR *return_path_name;
82 UINT  path_name_length_with_null_terminator;
83 
84 
85     /* Get the pointer to the path.  */
86     status =  _fx_directory_local_path_get(media_ptr, &return_path_name);
87     if (status == FX_SUCCESS)
88     {
89 
90         /* Was a path set?  */
91         if (return_path_name != FX_NULL)
92         {
93 
94             /* Get the length of the path.  */
95             path_name_length_with_null_terminator =  _fx_utility_string_length_get(return_path_name, FX_MAXIMUM_PATH) + 1;
96 
97             /* Can it fit in the user's buffer? */
98             if (path_name_length_with_null_terminator <= return_path_name_buffer_size)
99             {
100 
101                 /* Copy the path name into the user's buffer.  */
102                 _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. */
103             }
104             else
105             {
106 
107                 /* Buffer is too small. Return error.  */
108                 return(FX_BUFFER_ERROR);
109             }
110         }
111         else
112         {
113 
114             /* Set zero-length string.  */
115             return_path_name_buffer[0] = '\0';
116         }
117     }
118 
119     /* Return status.  */
120     return(status);
121 }
122 
123