FireBirdLib - Topfield TMS PVR TAP Programming Library
HDD_FindSymbolicLink.c
Go to the documentation of this file.
1#include <string.h>
2#include <unistd.h>
3#include "libFireBird.h"
4
5int HDD_FindSymbolicLink(const char *pathName, char *returnedPath, char *fullPathName)
6{
8
9 int pathLen = strlen(pathName);
10 int i = 0;
11 int ret = 0;
12
13 char tempPath[513];
14 char linkpath[513];
15
16 if(!pathName || !*pathName || (!returnedPath && !fullPathName))
17 {
18 TRACEEXIT();
19 return 0;
20 }
21
22 memset(tempPath, 0, sizeof(tempPath));
23 memset(linkpath, 0, sizeof(linkpath));
24
25 for(i = 0; i < pathLen; i++)
26 {
27 tempPath[i] = pathName[i];
28
29 if(pathName[i] == '/' || i == (pathLen - 1))
30 {
31
32 if(pathName[i] == '/') {tempPath[i] = 0;} //Remove the trailing "/" if this is not the end of the path
33
34 ret = readlink(tempPath, linkpath, sizeof(linkpath));
35 if(ret != -1)
36 {
37 if(returnedPath) strcpy(returnedPath, linkpath);
38
39 if(fullPathName)
40 {
41 strcpy(fullPathName, linkpath);
42 if(pathName[i] == '/') strcat(fullPathName, &pathName[i]);
43 }
44
45 TRACEEXIT();
46 return ret;
47 }
48 }
49
50 tempPath[i] = pathName[i];
51 }
52
53 TRACEEXIT();
54 return 0;
55
56}
#define TRACEEXIT()
Definition: libFireBird.h:1244
#define TRACEENTER()
Definition: libFireBird.h:1243