From: Rolf K. <lab...@us...> - 2005-01-16 11:31:55
|
Update of /cvsroot/opengtoolkit/lvzip/c_source In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv12478/c_source Modified Files: macbin.c Log Message: Removed the UtilFileInfo function as it is not needed anymore since the same function in the file package has been fixed. Index: macbin.c =================================================================== RCS file: /cvsroot/opengtoolkit/lvzip/c_source/macbin.c,v retrieving revision 1.7 retrieving revision 1.8 diff -C2 -d -r1.7 -r1.8 *** macbin.c 25 Dec 2004 16:32:41 -0000 1.7 --- macbin.c 16 Jan 2005 11:31:46 -0000 1.8 *************** *** 19,225 **** static OSErr IfDirCloseIt(int16 vol); static MgErr OSErrToLVErr(OSErr err); - static void MacConvertFromLVTime(uInt32 time, uInt32* sTime); - static void MacConvertToLVTime(uInt32 sTime, uInt32* time); - #elif Unix - #include <sys/types.h> - #include <sys/stat.h> - #include <string.h> - #include <utime.h> - static void UnixConvertFromLVTime(uInt32 time, time_t* sTime); - static void UnixConvertToLVTime(time_t sTime, uInt32* time); - #elif Win32 - #include <windows.h> - static void Win32ConvertFromLVTime(uInt32 time, FILETIME* sTime); - static void Win32ConvertToLVTime(FILETIME sTime, uInt32* time); #endif - extern MgErr ZEXPORT UtilFileInfo(PStr path, - uInt8 write, - FileInfo *fileInfo, - PStr comment, - int32 *length) { - #if Mac - FSSpec fss; - DTPBRec dtpb; - CInfoPBRec cpb; - OSErr err = noErr; - - if (len > 255) - return mgArgErr; - - if (err = MakeFSpec(path, &fss)) - return OSErrToLVErr(err); - - memset(&cpb, 0, sizeof(CInfoPBRec)); - cpb.hFileInfo.ioNamePtr = fss.name; - cpb.hFileInfo.ioVRefNum = fss.vRefNum; - cpb.hFileInfo.ioDirID = fss.parID; - - if (err = PBGetCatInfoSync(&cpb)) - goto out; - - dtpb.ioCompletion = nil; - dtpb.ioNamePtr = NULL; - dtpb.ioVRefNum = fss.vRefNum; - - if (err = PBDTGetPath(&dtpb)) - goto out; - - dtpb.ioNamePtr = fss.name; - dtpb.ioDTBuffer = comment; - dtpb.ioDirID = fss.parID; - - if (write) - { - - if (MacIsDir(cpb) - { - cbp.dirInfo.ioDrUsrWds.frFlags = fileInfo->flags; - cbp.dirInfo.ioDrUsrWds.frLocation = fileInfo->location; - - MacConvertFromLVTime(fileInfo->cDate, cbp.dirInfo.ioDrCrDat); - MacConvertFromLVTime(fileInfo->mDate, cbp.dirInfo.ioDrMdDat); - } - else - { - cbp.hFileInfo.ioFlFndrInfo.fdType = fileInfo->type; - cbp.hFileInfo.ioFlFndrInfo.fdCreator = fileInfo->creator; - cpb.hFileInfo.ioFlFndrInfo.fdFlags = fileInfo->flags; - cpb.hFileInfo.ioFlFndrInfo.fdFldr = fileInfo->fId; - cbp.hFileInfo.ioFlFndrInfo.fdLocation = fileInfo->location; - cpb.hFileInfo.ioFlXFndrInfo.fdScript = fileInfo->sId; - cpb.hFileInfo.ioFlXFndrInfo.fdFlags = fileInfo->xFlags; - - MacConvertFromLVTime(fileInfo->cDate, cbp.hFileInfo.ioFlCrDat); - MacConvertFromLVTime(fileInfo->mDate, cbp.hFileInfo.ioFlMdDat); - } - - err = PBSetCatInfoSync(&cpb); - - if (!err && *length && comment && PStrLen(comment)) { - dtpb.ioDTReqCount = *length; - err = PBDTSetCommentSync(&dtpb); - } - } - else - { - - if (MacIsDir(cpb) - { - fileInfo->type = kUnknownType; - fileInfo->creator = kUnknownCreator; - fileInfo->flags = cbp.dirInfo.ioDrUsrWds.frFlags; - fileInfo->fId = - fileInfo->location = cbp.dirInfo.ioDrUsrWds.frLocation; - fileInfo->size = cbp.dirInfo.ioDrNmFls; - fileInfo->rfSize = 0; - - MacConvertToLVTime(cbp.dirInfo.ioDrCrDat, fileInfo->cDate); - MacConvertToLVTime(cbp.dirInfo.ioDrMdDat, fileInfo->mDate); - } - else - { - fileInfo->type = cbp.hFileInfo.ioFlFndrInfo.fdType; - fileInfo->creator = cbp.hFileInfo.ioFlFndrInfo.fdCreator; - fileInfo->flags = cpb.hFileInfo.ioFlFndrInfo.fdFlags; - fileInfo->fId = cpb.hFileInfo.ioFlFndrInfo.fdFldr; - fileInfo->location = cbp.hFileInfo.ioFlFndrInfo.fdLocation; - fileInfo->size = catInfoPB.hFileInfo.ioFlLgLen; - fileInfo->rfSize = catInfoPB.hFileInfo.ioFlRLgLen; - fileInfo->sId = cpb.hFileInfo.ioFlXFndrInfo.fdScript; - fileInfo->xFlags = cpb.hFileInfo.ioFlXFndrInfo.fdFlags; - - MacConvertToLVTime(cbp.hFileInfo.ioFlCrDat, fileInfo->cDate); - MacConvertToLVTime(cbp.hFileInfo.ioFlMdDat, fileInfo->mDate); - } - - err = PBDTGetCommentSync(&dtpb); - *length = dtpb.ioDTActCount; - } - out: - IfDirCloseIt(fss.vRefNum); - return OSErrToLVErr(err); - #elif Unix - MgErr err = fIOErr; - struct stat statbuf; - struct utimbuf buf; - char filePath[400]; - - strncpy(filePath, PStrBuf(path), PStrLen(path)); - - if (stat(filePath, &statbuf)) - return fIOErr; - - if (write) - { - buf.actime = statbuf.st_atime; - buf.modtime = statbuf.st_mtime; - - /* No modification of creation time in Unix? - UnixConvertFromLVTime(fileInfo->cDate, &statbuf.st_ctime); - */ - UnixConvertFromLVTime(fileInfo->mDate, &buf.modtime); - if (utime(filePath, &buf)) - goto out; - } - else - { - UnixConvertToLVTime(statbuf.st_ctime, &fileInfo->cDate); - UnixConvertToLVTime(statbuf.st_mtime, &fileInfo->mDate); - fileInfo->size = statbuf.st_size; - } - err = noErr; - out: - return err; - #elif Win32 - BY_HANDLE_FILE_INFORMATION fi; - HANDLE handle = NULL; - MgErr err = fIOErr; - LPSTR filePath = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, PStrSize(path)); - - if (!filePath) - return mFullErr; - - CopyMemory(filePath, PStrBuf(path), PStrLen(path)); - - if ((handle = CreateFileA(filePath, write ? GENERIC_WRITE | GENERIC_READ : GENERIC_READ, - FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, OPEN_EXISTING, - FILE_ATTRIBUTE_NORMAL, NULL)) == INVALID_HANDLE_VALUE) - { - err = 1000 + GetLastError(); - goto out; - } - - if (!GetFileInformationByHandle(handle, &fi)) - { - err = 102; - goto out; - } - - if (write) - { - Win32ConvertFromLVTime(fileInfo->cDate, &fi.ftCreationTime); - Win32ConvertFromLVTime(fileInfo->mDate, &fi.ftLastWriteTime); - if (!SetFileTime(handle, &fi.ftCreationTime, &fi.ftLastAccessTime, &fi.ftLastWriteTime)) - { - err = 103; - goto out; - } - } - else - { - Win32ConvertToLVTime(fi.ftCreationTime, &fileInfo->cDate); - Win32ConvertToLVTime(fi.ftLastWriteTime, &fileInfo->mDate); - fileInfo->size = fi.nFileSizeLow; - } - err = noErr; - out: - if (handle) CloseHandle(handle); - if (filePath) HeapFree(GetProcessHeap(), 0, filePath); - return err; - #else - return mgNotSupported; - #endif - } extern MgErr ZEXPORT OpenResFork(File *fdp, --- 19,24 ---- *************** *** 368,460 **** return fIOErr; /* fIOErr generally signifies some unknown file error */ } - - /* - Calculate difference in seconds between local time zone and daylight - savings time settings and Universal Time Coordinate (also called GMT). - */ - static int32 UTCShift() - { - MachineLocation loc; - int32 delta; - - ReadLocation(&loc); - delta = loc.u.gmtDelta & 0x00ffffff; /* get sec east of UTC */ - if (delta & 0x800000) - delta |= 0xff000000; /* sign extend */ - return -delta; /* secs from UTC */ - } - - static void MacConvertFromLVTime(uInt32 time, uInt32 *sTime) - { - if (time > 0.0) - { - *sTime = time - UTCShift(); - } - return; - } - - static void MacConvertToLVTime(uInt32 sTime, uInt32 *time) - { - *time = sTime + UTCShift(); - return; - } - #elif Unix - /* seconds between Jan 1 1904 GMT and Jan 1 1970 GMT */ - #define dt1970re1904 2082844800L - - static void UnixConvertFromLVTime(uInt32 time, time_t *sTime) - { - if (time > 0.0) - { - *sTime = time - dt1970re1904; - } - return; - } - - static void UnixConvertToLVTime(time_t sTime, uInt32 *time) - { - *time = sTime + dt1970re1904; - } - #elif Win32 - /* int64 100ns intervals from Jan 1 1601 GMT to Jan 1 1904 GMT */ - static const FILETIME dt1904FileTime = { - 0xe0fb4000 /* low int32 */, - 0x0153b281 /* high int32 */ - }; - - static void Win32ConvertFromLVTime(uInt32 time, FILETIME *pFileTime) - { - DWORD temp; - - if (time > 0.0) - { - /* Convert to int64 100ns intervals since Jan 1 1904 GMT. */ - pFileTime->dwHighDateTime = (DWORD)(time * (78125.0 / 33554432.0)); - pFileTime->dwLowDateTime = (DWORD)(time * 1E7); - - /* Convert to int64 100ns intervals since Jan 1 1601 GMT. */ - temp = pFileTime->dwLowDateTime; - pFileTime->dwLowDateTime += dt1904FileTime.dwLowDateTime; - pFileTime->dwHighDateTime += dt1904FileTime.dwHighDateTime; - if (pFileTime->dwLowDateTime < temp) - pFileTime->dwHighDateTime++; - } - return; - } - - static void Win32ConvertToLVTime(FILETIME pFileTime, uInt32 *time) - { - DWORD temp; - - /* Convert to int64 100ns intervals since Jan 1 1904 GMT. */ - temp = pFileTime.dwLowDateTime; - pFileTime.dwLowDateTime -= dt1904FileTime.dwLowDateTime; - pFileTime.dwHighDateTime -= dt1904FileTime.dwHighDateTime; - if (pFileTime.dwLowDateTime > temp) - pFileTime.dwHighDateTime--; - - /* Convert to float64 seconds since Jan 1 1904 GMT. - secs = ((Hi32 * 2^^32) + Lo32) / 10^^7 = (Hi32 * (2^^25 / 5^^7)) + (Lo32 / 10^^7) */ - *time = (uInt32)((pFileTime.dwHighDateTime * (33554432.0 / 78125.0)) + (pFileTime.dwLowDateTime / 1E7)); - } #endif --- 167,169 ---- |