]> git.proxmox.com Git - mirror_edk2.git/blob - StdLib/LibC/StdLib/realpath.c
Add Socket Libraries.
[mirror_edk2.git] / StdLib / LibC / StdLib / realpath.c
1 /** @file
2 Implement the realpath function.
3
4 Copyright (c) 2011, 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 **/
14
15 #include <LibConfig.h>
16 #include <Library/BaseLib.h>
17 #include <Library/PathLib.h>
18 #include <Library/MemoryAllocationLib.h>
19 #include <errno.h>
20
21 /**
22 The realpath() function shall derive, from the pathname pointed to by
23 file_name, an absolute pathname that names the same file, whose resolution
24 does not involve '.', '..', or symbolic links. The generated pathname shall
25 be stored as a null-terminated string, up to a maximum of {PATH_MAX} bytes,
26 in the buffer pointed to by resolved_name.
27
28 If resolved_name is a null pointer, the behavior of realpath() is
29 implementation-defined.
30
31 @param[in] file_name The filename to convert.
32 @param[in,out] resolved_name The resultant name.
33
34 @retval NULL An error occured.
35 @return resolved_name.
36 **/
37 char *
38 realpath(
39 char *file_name,
40 char *resolved_name
41 )
42 {
43 CHAR16 *Temp;
44 if (file_name == NULL || resolved_name == NULL) {
45 errno = EINVAL;
46 return (NULL);
47 }
48 Temp = AllocateZeroPool((1+AsciiStrLen(file_name))*sizeof(CHAR16));
49 if (Temp == NULL) {
50 errno = ENOMEM;
51 return (NULL);
52 }
53 AsciiStrToUnicodeStr(file_name, Temp);
54 PathCleanUpDirectories(Temp);
55 UnicodeStrToAsciiStr(Temp, resolved_name);
56 return (resolved_name);
57 }