|
From: <lab...@us...> - 2019-09-14 14:19:55
|
Revision: 1602
http://sourceforge.net/p/opengtoolkit/svn/1602
Author: labviewer
Date: 2019-09-14 14:19:53 +0000 (Sat, 14 Sep 2019)
Log Message:
-----------
Extend the returned file info structure
Modified Paths:
--------------
trunk/lvzip/c_source/lvutil.c
trunk/lvzip/c_source/lvutil.h
Modified: trunk/lvzip/c_source/lvutil.c
===================================================================
--- trunk/lvzip/c_source/lvutil.c 2019-09-14 14:19:12 UTC (rev 1601)
+++ trunk/lvzip/c_source/lvutil.c 2019-09-14 14:19:53 UTC (rev 1602)
@@ -95,6 +95,7 @@
#include <dirent.h>
#include <fcntl.h>
#include <unistd.h>
+ #include <sys/stat.h>
#define ftruncate64 ftruncate
#ifdef HAVE_ICONV
#include <iconv.h>
@@ -102,10 +103,9 @@
#include <wchar.h>
#if VxWorks
#include <sys/types.h>
- #include <sys/stat.h>
#include <string.h>
#include <utime.h>
- #include <ioLib.h>
+// #include <ioLib.h>
#ifdef __GNUC__
#define ___unused __attribute__((unused))
#else
@@ -120,7 +120,7 @@
inline int link(const char* path1 ___unused, const char* path2 ___unused)
{
// VxWorks < 6.2 has no link() support
- errno = EACCES;
+ errno = ENOTSUP;
return -1;
}
@@ -127,7 +127,7 @@
inline int chmod(const char* _path ___unused, mode_t _mode ___unused)
{
// VxWorks < 6.2 has no chmod() support
- errno = EACCES;
+ errno = ENOTSUP;
return -1;
}
#endif
@@ -136,7 +136,7 @@
inline int symlink(const char* path1 ___unused, const char* path2 ___unused)
{
// vxWorks has no symlinks -> always return an error!
- errno = EACCES;
+ errno = ENOTSUP;
return -1;
}
@@ -217,19 +217,6 @@
return err;
}
-/* Convert a Macintosh UTDDateTime to a LabVIEW timestamp and vice versa */
-static void MacConvertFromLVTime(uInt32 time, UTCDateTime *mTime)
-{
- mTime->fraction = 0;
- mTime->lowSeconds = time;
- mTime->highSeconds = 0;
-}
-
-static void MacConvertToLVTime(UTCDateTime *mTime, uInt32 *time)
-{
- *time = mTime->lowSeconds;
-}
-
static MgErr OSErrToLVErr(OSErr err)
{
switch(err)
@@ -300,20 +287,6 @@
pt->u.f.fract = ((li.QuadPart - pt->u.f.val) * 0x100000000 / SECS_TO_FT_MULT) << 32;
}
-LibAPI(void) SystemTimeToATime(SYSTEMTIME *pst, ATime128 *pt)
-{
- FILETIME ft;
- SystemTimeToFileTime(pst, &ft);
- FileTimeToATime(&ft, pt);
-}
-
-LibAPI(void) ATimeToSystemTime(ATime128 *pt, SYSTEMTIME *pst)
-{
- FILETIME ft;
- ATimeToFileTime(pt, &ft);
- FileTimeToSystemTime(&ft, pst);
-}
-
static MgErr Win32ToLVFileErr(DWORD winErr)
{
switch (winErr)
@@ -453,6 +426,8 @@
#if Unix || MacOSX || defined(EMBEDDED)
#define LWStrPtr LStrPtr
+#define SStrBuf(s) (char*)LStrBuf(s)
+
/* wstr is filled with an 8 bit local encoded string from the path, which could be UTF8 on Linux and MacOSX systems */
static int32 MakePathDSString(Path path, LWStrPtr *lstr, size_t reserve)
{
@@ -1205,12 +1180,8 @@
LibAPI(MgErr) LVPath_HasResourceFork(Path path, LVBoolean *hasResFork, uInt32 *sizeLow, uInt32 *sizeHigh)
{
MgErr err = mgNoErr;
-#if Mac
-#if usesHFSPath
- FSRef ref;
-#else
+#if MacOSX
LStrHandle lstr = NULL;
-#endif
#else
Unused(path);
#endif
@@ -1221,32 +1192,10 @@
if (sizeHigh)
*sizeHigh = 0;
-#if Mac
-#if usesHFSPath // 32-Bit MacOSX
- err = FSMakePathRef(path, &ref);
+#if MacOSX
+ err = MakePathDSString(path, &lstr, 0);
if (!err)
{
- FSCatalogInfoBitmap whichInfo = kFSCatInfoNodeFlags | kFSCatInfoRsrcSizes;
- FSCatalogInfo catalogInfo;
-
- /* get nodeFlags and catalog info */
- err = OSErrToLVErr(FSGetCatalogInfo(&ref, whichInfo, &catalogInfo, NULL, NULL,NULL));
- if (!err && catalogInfo.nodeFlags & kFSNodeIsDirectoryMask)
- err = fIOErr;
- if (!err && catalogInfo.rsrcLogicalSize > 0)
- {
- if (hasResFork)
- *hasResFork = LV_TRUE;
- if (sizeLow)
- *sizeLow = Lo32(catalogInfo.rsrcLogicalSize);
- if (sizeHigh)
- *sizeHigh = Hi32(catalogInfo.rsrcLogicalSize);
- }
- }
-#else // 64-Bit MacOSX
- err = LVPath_ToText(path, &lstr);
- if (!err)
- {
ssize_t len = getxattr((const char)LStrBuf(*lstr), XATTR_RESOURCEFORK_NAME, NULL, 0, 0, O_NOFOLLOW);
if (len != -1)
{
@@ -1261,7 +1210,6 @@
DSDisposeHandle((UHandle)lstr);
}
#endif
-#endif
return err;
}
@@ -1399,6 +1347,8 @@
{
fileInfo->type = kUnknownFileType;
fileInfo->creator = kUnknownCreator;
+ fileInfo->uid = 0xFFFFFFFF;
+ fileInfo->gid = 0xFFFFFFFF;
FileTimeToATime(&fi.ftCreationTime, &fileInfo->cDate);
FileTimeToATime(&fi.ftLastWriteTime, &fileInfo->mDate);
FileTimeToATime(&fi.ftLastAccessTime, &fileInfo->aDate);
@@ -1405,6 +1355,7 @@
fileInfo->rfSize = 0;
fileInfo->winFlags = Lo16(fi.dwFileAttributes);
fileInfo->unixFlags = FlagsFromWindows(fileInfo->winFlags);
+ fileInfo->xtraFlags = 0;
if (fi.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
{
if (!FDepth(path))
@@ -1484,12 +1435,31 @@
UnixConvertFromATime(&fileInfo->cDate, &statbuf.st_ctim);
UnixConvertFromATime(&fileInfo->aDate, ×[0]);
UnixConvertFromATime(&fileInfo->mDate, ×[1]);
- if (utimensat(0, LStrBuf(lstr), times, AT_SYMLINK_NOFOLLOW))
+ if (utimensat(0, SStrBuf(lstr), times, AT_SYMLINK_NOFOLLOW))
#endif
err = UnixToLVFileErr();
- else if (chmod(LStrBuf(lstr), (statbuf.st_mode & 0170000) | (fileInfo->unixFlags & 07777)))
+
+#if !VxWorks
+ /*
+ * Changing the ownership probably won't succeed, unless we're root
+ * or POSIX_CHOWN_RESTRICTED is not set. Set uid/gid before setting
+ * the mode; current BSD behavior is to remove all setuid bits on
+ * chown. If chown fails, lose setuid/setgid bits.
+ */
+ else if (chown(SStrBuf(lstr), fileInfo->uid, fileInfo->gid))
+ {
+ if (errno != EPERM && errno != ENOTSUP)
+ err = UnixToLVFileErr();
+ fileInfo->unixFlags &= ~(S_ISUID | S_ISGID);
+ }
+#endif
+ if (!err && chmod(SStrBuf(lstr), (statbuf.st_mode & 0170000) | (fileInfo->unixFlags & 07777)) && errno != ENOTSUP)
err = UnixToLVFileErr();
+#if MacOSX
+ else if (chflags(SStrBuf(lstr), fileInfo->xtraFlags)
+ err = UnixToLVFileErr();
+#endif
}
else
{
@@ -1505,6 +1475,8 @@
fileInfo->type = kUnknownFileType;
fileInfo->creator = kUnknownCreator;
}
+ fileInfo->uid = statbuf.st_uid;
+ fileInfo->gid = statbuf.st_gid;
#if VxWorks
VxWorksConvertToATime(statbuf.st_ctime, &fileInfo->cDate);
VxWorksConvertToATime(statbuf.st_atime, &fileInfo->aDate);
@@ -1514,10 +1486,6 @@
UnixConvertToATime(&statbuf.st_mtim, &fileInfo->mDate);
UnixConvertToATime(&statbuf.st_atim, &fileInfo->aDate);
#endif
- fileInfo->rfSize = 0;
- fileInfo->size = statbuf.st_size;
- fileInfo->unixFlags = Lo16(statbuf.st_mode);
- fileInfo->winFlags = FlagsFromUnix(fileInfo->unixFlags);
if (S_ISDIR(statbuf.st_mode))
{
DIR *dirp;
@@ -1530,15 +1498,27 @@
count++;
closedir(dirp);
fileInfo->size = count - 2;
+ fileInfo->rfSize = 0;
}
else
{
+ fileInfo->size = statbuf.st_size;
#if MacOSX
ssize_t size = getxattr(LStrBuf(*lstr), XATTR_RESOURCEFORK_NAME, NULL, 0, 0, O_NOFOLLOW);
if (size > 0)
fileInfo->rfSize = (uInt64)size;
+ else
+#else
+ fileInfo->rfSize = 0;
#endif
}
+ fileInfo->unixFlags = Lo16(statbuf.st_mode);
+ fileInfo->winFlags = FlagsFromUnix(fileInfo->unixFlags);
+#if MacOSX
+ fileInfo->xtraFlags = statbuf.st_flags;
+#else
+ fileInfo->xtraFlags = 0;
+#endif
}
}
#endif
Modified: trunk/lvzip/c_source/lvutil.h
===================================================================
--- trunk/lvzip/c_source/lvutil.h 2019-09-14 14:19:12 UTC (rev 1601)
+++ trunk/lvzip/c_source/lvutil.h 2019-09-14 14:19:53 UTC (rev 1602)
@@ -678,17 +678,20 @@
#define kWinFileInfoEncrypted 0x00004000
#define kWinFileInfoVirtual 0x00010000
-typedef struct {
- uInt32 type; /* handled by LabVIEW Type & Creator */
- uInt32 creator; /* handled by LabVIEW Type & Creator */
- uInt64 size; /* file size or file count for directories */
- uInt64 rfSize; /* resource fork size, 0 on non MacOS platforms */
- ATime128 cDate; /* Creation date */
- ATime128 mDate; /* Modification date */
- ATime128 aDate; /* ast access date */
- uInt16 winFlags; /* Windows compatible flags */
- uInt32 unixFlags; /* Unix compatible flags */
-} LVFileInfo;
+typedef struct { /* off */
+ uInt32 type; /* 0: handled by LabVIEW Type & Creator */
+ uInt32 creator; /* 4: handled by LabVIEW Type & Creator */
+ uInt32 uid; /* 8: Unix user id */
+ uInt32 gid; /* 12: Unix group id */
+ uInt64 size; /* 16: file size or file count for directories */
+ uInt64 rfSize; /* 24: resource fork size, 0 on non MacOS platforms */
+ ATime128 cDate; /* 32: Creation date */
+ ATime128 mDate; /* 48: Modification date */
+ ATime128 aDate; /* 64: ast access date */
+ uInt16 winFlags; /* 80: Windows compatible flags */
+ uInt16 unixFlags; /* 82: Unix compatible flags */
+ uInt32 xtraFlags; /* 84: MacOSX extra file flags */
+} LVFileInfo; /* 88: Total length */
/* Retrieve file information from the path */
LibAPI(MgErr) LVPath_FileInfo(Path path, uInt8 write, LVFileInfo *fileInfo);
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|