|
From: <lab...@us...> - 2015-09-06 14:34:40
|
Revision: 1537
http://sourceforge.net/p/opengtoolkit/svn/1537
Author: labviewer
Date: 2015-09-06 14:34:37 +0000 (Sun, 06 Sep 2015)
Log Message:
-----------
Update Read Link function for MacOSX
Modified Paths:
--------------
trunk/lvzip/c_source/lvutil.c
trunk/lvzip/c_source/lvutil.h
trunk/lvzip/source/fileutil.llb/FILE Get Directory Content.vi
Added Paths:
-----------
trunk/lvzip/source/fileutil.llb/FILE Read Link Target.vi
Property Changed:
----------------
trunk/lvzip/c_source/
Index: trunk/lvzip/c_source
===================================================================
--- trunk/lvzip/c_source 2015-07-31 23:16:09 UTC (rev 1536)
+++ trunk/lvzip/c_source 2015-09-06 14:34:37 UTC (rev 1537)
Property changes on: trunk/lvzip/c_source
___________________________________________________________________
Modified: svn:ignore
## -4,3 +4,4 ##
.opt
.plg
.o
+Build
Modified: trunk/lvzip/c_source/lvutil.c
===================================================================
--- trunk/lvzip/c_source/lvutil.c 2015-07-31 23:16:09 UTC (rev 1536)
+++ trunk/lvzip/c_source/lvutil.c 2015-09-06 14:34:37 UTC (rev 1537)
@@ -103,10 +103,13 @@
#define usesWinPath Win32
#if usesHFSPath
+#define kPathSeperator ':'
typedef SInt16 FileRefNum;
#elif usesPosixPath
+#define kPathSeperator '/'
typedef FILE* FileRefNum;
#elif usesWinPath
+#define kPathSeperator '\'
typedef HANDLE FileRefNum;
#endif
@@ -978,6 +981,10 @@
if (!err)
err = ConvertToPosixPath(*str, str, false);
#endif
+ if (LStrBuf(**str)[LStrLen(**str) - 1] == kPathSeperator)
+ {
+ LStrLen(**str)--;
+ }
}
}
return err;
@@ -1061,7 +1068,7 @@
return err;
}
-LibAPI(MgErr) LVPath_ReadLink(Path path, Path *target)
+LibAPI(MgErr) LVPath_ReadLink(Path path, Path *target, int32 *fileType)
{
MgErr err = mgNoErr;
LStrHandle src = NULL;
@@ -1074,7 +1081,7 @@
{
#if MacOSX || Unix
struct stat st;
- char *buf = NULL;
+ char *buf = NULL, *ptr = NULL;
int len = 0;
if (lstat((const char*)LStrBuf(*src), &st))
@@ -1104,13 +1111,72 @@
}
else if (retval < len)
{
- err = LVPath_FromText((CStr)buf, retval, target, LV_FALSE);
- free(buf);
- break;
+ /* Is the link target a relative path */
+ if (buf[0] != '/')
+ {
+ ptr = realloc(buf, retval + LStrLen(*src) + 1);
+ if (ptr)
+ {
+ buf = ptr;
+ memmove(buf + LStrLen(*src) + 1, buf, retval);
+ memmove(buf, LStrBuf(*src), LStrLen(*src));
+ buf[LStrLen(*src)] = '/';
+ retval += LStrLen(*src) + 1;
+ }
+ else
+ {
+ err = mFullErr;
+ }
+ }
+ if (!err)
+ {
+ err = LVPath_FromText((CStr)buf, retval, target, LV_FALSE);
+ if (!err && fileType)
+ {
+ if (lstat(buf, &st))
+ {
+ err = UnixToLVFileErr();
+ }
+ else if (S_ISLNK(st.st_mode))
+ {
+ if (stat(buf, &st))
+ {
+ err = UnixToLVFileErr();
+ }
+ else
+ {
+ *fileType = S_ISDIR(st.st_mode) ? kIsLink : kIsLink | kIsFile;
+ }
+ }
+ else
+ {
+ if (!S_ISDIR(st.st_mode))
+ {
+ *fileType = kIsFile;
+ }
+ }
+ }
+ break;
+ }
}
- len += len;
- buf = realloc(buf, len);
+ else // retval >= len
+ {
+ len += len;
+ ptr = realloc(buf, len);
+ if (!ptr)
+ {
+ err = mFullErr;
+ }
+ else
+ {
+ buf = ptr;
+ }
+ }
}
+ if (buf)
+ {
+ free(buf);
+ }
#elif Win32
WIN32_FILE_ATTRIBUTE_DATA data;
BOOL ret = GetFileAttributesExA(LStrBuf(*src), GetFileExInfoStandard, &data);
Modified: trunk/lvzip/c_source/lvutil.h
===================================================================
--- trunk/lvzip/c_source/lvutil.h 2015-07-31 23:16:09 UTC (rev 1536)
+++ trunk/lvzip/c_source/lvutil.h 2015-09-06 14:34:37 UTC (rev 1537)
@@ -404,7 +404,8 @@
typedef enum _FMFileType {
kInvalidType =0,
kUnknownFileType=RTToL('?','?','?','?'),
- kTextFileType =RTToL('T','E','X','T'),
+ kTextFileType =RTToL('T','E','X','T'),
+ kLinkFileType =RTToL('s','l','n','k'),
/** Typical directory types */
kHardDiskDirType=RTToL('h','d','s','k'),
kFloppyDirType =RTToL('f','l','p','y'),
@@ -629,7 +630,7 @@
/* Create and read a link */
LibAPI(MgErr) LVPath_CreateLink(Path path, uInt32 flags, Path target);
-LibAPI(MgErr) LVPath_ReadLink(Path path, Path *target);
+LibAPI(MgErr) LVPath_ReadLink(Path path, Path *target, int32 *fileType);
/* Legacy functions not supported on Mac OSX and all non-Mac platforms */
LibAPI(MgErr) LVPath_EncodeMacbinary(Path srcFileName, Path dstFileName);
Modified: trunk/lvzip/source/fileutil.llb/FILE Get Directory Content.vi
===================================================================
(Binary files differ)
Added: trunk/lvzip/source/fileutil.llb/FILE Read Link Target.vi
===================================================================
(Binary files differ)
Index: trunk/lvzip/source/fileutil.llb/FILE Read Link Target.vi
===================================================================
--- trunk/lvzip/source/fileutil.llb/FILE Read Link Target.vi 2015-07-31 23:16:09 UTC (rev 1536)
+++ trunk/lvzip/source/fileutil.llb/FILE Read Link Target.vi 2015-09-06 14:34:37 UTC (rev 1537)
Property changes on: trunk/lvzip/source/fileutil.llb/FILE Read Link Target.vi
___________________________________________________________________
Added: svn:mime-type
## -0,0 +1 ##
+application/octet-stream
\ No newline at end of property
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|