Merge branch 'master' of git://cadel.mutabah.net/acess2
[tpg/acess2.git] / AcessNative / acesskernel_src / syscall_getpath.c
1 /*
2  * AcessNative Kernel
3  *
4  * syscall_getpath.c
5  * - Implementation of the SYS_AN_GETPATH system call
6  */
7
8 #include <acess.h>
9 #include <vfs_int.h>
10
11 extern char     *getcwd(char *buf, size_t size);
12
13 extern tVFS_NodeType    gNativeFS_FileNodeType;
14 extern tVFS_NodeType    gNativeFS_DirNodeType;
15
16 int Syscall_AN_GetPath_Real(char *Dst, size_t DstLen, const char *Path)
17 {
18         tVFS_Node       *node = VFS_ParsePath(Path, NULL, NULL);
19         if(!node)       return -1;
20
21         const char *relpath = NULL;
22
23         if( node->Type == &gNativeFS_FileNodeType || node->Type == &gNativeFS_DirNodeType )
24         {
25                 relpath = node->Data;
26         }
27         else
28         {
29                 relpath = NULL;
30         }
31         
32         size_t  ret;
33         if( relpath )
34         {
35                 if( relpath[0] == '/' ) {
36                         ret = snprintf(Dst, DstLen, "%s", relpath);
37                 }
38                 else {
39                         getcwd(Dst, DstLen);
40                         ret = strlen(Dst);
41                         ret += snprintf(Dst+ret, DstLen-ret, "/%s", relpath);
42                 }
43         }
44         else
45         {
46                 ret = 0;
47         }
48         
49         _CloseNode(node);
50         return ret;
51 }

UCC git Repository :: git.ucc.asn.au