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