]> git.proxmox.com Git - mirror_edk2.git/blob - StdLib/LibC/StdLib/realpath.c
a7186184c97cda8a52db461e494818de5402a138
[mirror_edk2.git] / StdLib / LibC / StdLib / realpath.c
1 /** @file
2 Implement the realpath function.
3
4 Copyright (c) 2011 - 2014, Intel Corporation
5 All rights reserved. This program and the accompanying materials
6 are licensed and made available under the terms and conditions of the BSD License
7 which accompanies this distribution. The full text of the license may be found at
8 http://opensource.org/licenses/bsd-license.php
9
10 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
11 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
12 **/
13 #include <LibConfig.h>
14 #include <Library/BaseLib.h>
15 #include <Library/MemoryAllocationLib.h>
16 #include <Library/PathLib.h>
17 #include <errno.h>
18
19 /** The realpath() function shall derive, from the pathname pointed to by
20 file_name, an absolute pathname that names the same file, whose resolution
21 does not involve '.', '..', or symbolic links.
22
23 The generated pathname shall be stored as a null-terminated string, up to a
24 maximum of {PATH_MAX} bytes, in the buffer pointed to by resolved_name.
25
26 If resolved_name is a null pointer, the behavior of realpath() is
27 implementation-defined.
28
29 @param[in] file_name The filename to convert.
30 @param[in,out] resolved_name The resultant name.
31
32 @retval NULL An error occured.
33 @return resolved_name.
34 **/
35 char *
36 realpath(
37 char *file_name,
38 char *resolved_name
39 )
40 {
41 CHAR16 *Temp;
42 if (file_name == NULL || resolved_name == NULL) {
43 errno = EINVAL;
44 return (NULL);
45 }
46 Temp = AllocateZeroPool((1+AsciiStrLen(file_name))*sizeof(CHAR16));
47 if (Temp == NULL) {
48 errno = ENOMEM;
49 return (NULL);
50 }
51 AsciiStrToUnicodeStr(file_name, Temp);
52 PathCleanUpDirectories(Temp);
53 UnicodeStrToAsciiStr(Temp, resolved_name);
54 return (resolved_name);
55 }