mirror of
https://github.com/vishapoberon/compiler.git
synced 2026-10-10 00:27:23 +00:00
Platform.SetFileMtime and oocFiles.SetModTime.
This commit is contained in:
parent
0decbe950e
commit
575ea5c236
4 changed files with 86 additions and 3 deletions
|
|
@ -566,9 +566,29 @@ BEGIN
|
|||
END Tmp;
|
||||
|
||||
PROCEDURE SetModTime* (file: ARRAY OF CHAR; mtime: Time.TimeStamp; VAR res: Result);
|
||||
VAR
|
||||
name: ARRAY maxPath OF CHAR;
|
||||
day, month: SHORTINT;
|
||||
year: INTEGER;
|
||||
hour, minute, second, seconds: LONGINT;
|
||||
error: Host.Error;
|
||||
BEGIN
|
||||
(* The current host interface exposes modification-time queries only. *)
|
||||
res := GetError(noModTime)
|
||||
IF (mtime.msecs < 0) OR (mtime.msecs >= Time.msecPerDay) THEN
|
||||
res := GetError(invalidTime);
|
||||
RETURN
|
||||
END;
|
||||
JulianDay.DaysToDate(mtime.days, day, month, year);
|
||||
IF year <= 0 THEN
|
||||
res := GetError(invalidTime);
|
||||
RETURN
|
||||
END;
|
||||
seconds := mtime.msecs DIV Time.msecPerSec;
|
||||
hour := seconds DIV 3600;
|
||||
minute := (seconds DIV 60) MOD 60;
|
||||
second := seconds MOD 60;
|
||||
COPY(file, name);
|
||||
error := Host.SetModTime(name, year, month, day, hour, minute, second);
|
||||
IF error = 0 THEN res := done ELSE res := OpenError(error) END
|
||||
END SetModTime;
|
||||
|
||||
PROCEDURE GetModTime* (file: ARRAY OF CHAR; VAR mtime: Time.TimeStamp; VAR res: Result);
|
||||
|
|
|
|||
|
|
@ -109,6 +109,12 @@ BEGIN
|
|||
RETURN error
|
||||
END GetModTime;
|
||||
|
||||
PROCEDURE SetModTime* (VAR name: ARRAY OF CHAR; year, month, day,
|
||||
hour, minute, second: LONGINT): Error;
|
||||
BEGIN
|
||||
RETURN Platform.SetFileMTime(name, year, month, day, hour, minute, second)
|
||||
END SetModTime;
|
||||
|
||||
PROCEDURE CurrentDirectory* (VAR path: ARRAY OF CHAR);
|
||||
BEGIN
|
||||
COPY(Platform.CWD, path)
|
||||
|
|
|
|||
|
|
@ -41,6 +41,7 @@ PROCEDURE -Aincludeunistd '#include <unistd.h>';
|
|||
PROCEDURE -Aincludesysstat '#include <sys/stat.h>';
|
||||
PROCEDURE -Aincludefcntl '#include <fcntl.h>';
|
||||
PROCEDURE -Aincludeerrno '#include <errno.h>';
|
||||
PROCEDURE -Aincludeutime '#include <utime.h>';
|
||||
PROCEDURE -Astdlib '#include <stdlib.h>';
|
||||
PROCEDURE -Astdio '#include <stdio.h>';
|
||||
PROCEDURE -Aerrno '#include <errno.h>';
|
||||
|
|
@ -262,6 +263,33 @@ BEGIN
|
|||
END Close;
|
||||
|
||||
|
||||
PROCEDURE -mtimevars "struct tm mtm = {0}; struct utimbuf mtimes";
|
||||
PROCEDURE -setmtimedate(year, month, day: LONGINT)
|
||||
"mtm.tm_year = (int)year-1900; mtm.tm_mon = (int)month-1; mtm.tm_mday = (int)day";
|
||||
PROCEDURE -setmtimetime(hour, minute, second: LONGINT)
|
||||
"mtm.tm_hour = (int)hour; mtm.tm_min = (int)minute; mtm.tm_sec = (int)second; mtm.tm_isdst = -1";
|
||||
PROCEDURE -makemtime(): INTEGER "(mtimes.modtime = mktime(&mtm)) != (time_t)-1";
|
||||
PROCEDURE -invalidmtime "errno = EINVAL";
|
||||
PROCEDURE -applymtime(n: ARRAY OF CHAR): INTEGER
|
||||
"(mtimes.actime = mtimes.modtime, utime((char*)n, &mtimes))";
|
||||
|
||||
PROCEDURE SetFileMTime* (VAR n: ARRAY OF CHAR; year, month, day,
|
||||
hour, minute, second: LONGINT): ErrorCode;
|
||||
BEGIN
|
||||
mtimevars;
|
||||
setmtimedate(year, month, day);
|
||||
setmtimetime(hour, minute, second);
|
||||
IF makemtime() = 0 THEN
|
||||
invalidmtime;
|
||||
RETURN err()
|
||||
ELSIF applymtime(n) < 0 THEN
|
||||
RETURN err()
|
||||
ELSE
|
||||
RETURN 0
|
||||
END
|
||||
END SetFileMTime;
|
||||
|
||||
|
||||
PROCEDURE -isatty(fd: LONGINT): INTEGER "isatty(fd)";
|
||||
|
||||
PROCEDURE IsConsole*(h: FileHandle): BOOLEAN;
|
||||
|
|
|
|||
|
|
@ -171,7 +171,7 @@ PROCEDURE -styear(): INTEGER "(INTEGER)st.wYear";
|
|||
|
||||
PROCEDURE YMDHMStoClock(ye,mo,da,ho,mi,se: INTEGER; VAR t, d: LONGINT);
|
||||
BEGIN
|
||||
d := ASH(ye MOD 100, 9) + ASH(mo+1, 5) + da;
|
||||
d := ASH(ye MOD 100, 9) + ASH(mo, 5) + da;
|
||||
t := ASH(ho, 12) + ASH(mi, 6) + se;
|
||||
END YMDHMStoClock;
|
||||
|
||||
|
|
@ -289,6 +289,35 @@ BEGIN
|
|||
END Close;
|
||||
|
||||
|
||||
PROCEDURE -openwriteattributes(n: ARRAY OF CHAR): FileHandle
|
||||
"(ADDRESS)CreateFile((char*)n, FILE_WRITE_ATTRIBUTES, FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE, 0, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0)";
|
||||
|
||||
PROCEDURE -mtimevars "SYSTEMTIME mst = {0}; FILETIME mft";
|
||||
PROCEDURE -setmtimedate(year, month, day: LONGINT)
|
||||
"mst.wYear = (WORD)year; mst.wMonth = (WORD)month; mst.wDay = (WORD)day";
|
||||
PROCEDURE -setmtimetime(hour, minute, second: LONGINT)
|
||||
"mst.wHour = (WORD)hour; mst.wMinute = (WORD)minute; mst.wSecond = (WORD)second";
|
||||
PROCEDURE -makemtime(): INTEGER "(INTEGER)SystemTimeToFileTime(&mst, &mft)";
|
||||
PROCEDURE -applymtime(h: FileHandle): INTEGER
|
||||
"(INTEGER)SetFileTime((HANDLE)h, 0, 0, &mft)";
|
||||
|
||||
PROCEDURE SetFileMTime* (VAR n: ARRAY OF CHAR; year, month, day,
|
||||
hour, minute, second: LONGINT): ErrorCode;
|
||||
VAR handle: FileHandle; result: INTEGER; error, closeError: ErrorCode;
|
||||
BEGIN
|
||||
handle := openwriteattributes(n);
|
||||
IF handle = invalidHandleValue() THEN RETURN err() END;
|
||||
mtimevars;
|
||||
setmtimedate(year, month, day);
|
||||
setmtimetime(hour, minute, second);
|
||||
result := makemtime();
|
||||
IF result # 0 THEN result := applymtime(handle) END;
|
||||
IF result = 0 THEN error := err() ELSE error := 0 END;
|
||||
closeError := Close(handle);
|
||||
IF error # 0 THEN RETURN error ELSE RETURN closeError END
|
||||
END SetFileMTime;
|
||||
|
||||
|
||||
|
||||
PROCEDURE -byHandleFileInformation "BY_HANDLE_FILE_INFORMATION bhfi";
|
||||
PROCEDURE -getFileInformationByHandle(h: FileHandle): INTEGER "(INTEGER)GetFileInformationByHandle((HANDLE)h, &bhfi)";
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue