diff options
| author | Tomas Bzatek <tbzatek@users.sourceforge.net> | 2008-06-14 18:34:02 +0200 |
|---|---|---|
| committer | Tomas Bzatek <tbzatek@users.sourceforge.net> | 2008-06-14 18:34:02 +0200 |
| commit | c9a02bf590248c0bd8e1343198d3f9c13ce118c1 (patch) | |
| tree | cbd1b07cea6f3ccea7fc98c58d65f568e69e8527 /UCoreUtils.pas | |
| parent | b1dfa430702770c83c815bec24f1dc72175e1e5e (diff) | |
| download | tuxcmd-c9a02bf590248c0bd8e1343198d3f9c13ce118c1.tar.xz | |
Port to new ULibc unit, drop dependency to compiler Libc libraryv0.6.43
(preparation for PPC port)
Diffstat (limited to 'UCoreUtils.pas')
| -rw-r--r-- | UCoreUtils.pas | 72 |
1 files changed, 36 insertions, 36 deletions
diff --git a/UCoreUtils.pas b/UCoreUtils.pas index 3dc91f0..ed43589 100644 --- a/UCoreUtils.pas +++ b/UCoreUtils.pas @@ -24,7 +24,7 @@ unit UCoreUtils; interface -uses gdk2pixbuf, gtk2, gdk2, glib2, SysUtils, Classes, Libc, UGlibC_compat, GTKControls, GTKStdCtrls, GTKClasses, UEngines; +uses gtk2, gdk2, glib2, SysUtils, Classes, ULibc, GTKClasses, UEngines; type PIntArray = ^TIntArray; @@ -57,8 +57,8 @@ function GetErrorString(ErrorNo: integer): string; function GetSignalString(SignalNo: integer): string; function FormatSize(Value: Int64; Base: integer; OverrideSizeFormat: integer = -1): string; -function FormatDate(Value: TTimeT; const FormatTime, FormatDate: boolean; OverrideTimeFormat: integer = -1; OverrideDateFormat: integer = -1; OverrideDateTimeFormat: integer = -1; OverrideCustomDateFormat: string = ''; OverrideCustomTimeFormat: string = ''): string; -function StripDate(Value: TTimeT): TTimeT; +function FormatDate(Value: time_t; const FormatTime, FormatDate: boolean; OverrideTimeFormat: integer = -1; OverrideDateFormat: integer = -1; OverrideDateTimeFormat: integer = -1; OverrideCustomDateFormat: string = ''; OverrideCustomTimeFormat: string = ''): string; +function StripDate(Value: time_t): time_t; function AttrToStr(const Mode: Cardinal; IncludeFileType: boolean = True): string; function AttrToOctal(const Mode: Cardinal): integer; @@ -204,7 +204,7 @@ begin DebugMsg(['FormatSize(0): sprintf() failed, using old format function.']); Result := FormatFloat('###,###,##0', Value div Base); end else Result := StrToUTF8(p); - Libc.free(p); + free(p); end; 1 : begin // 123456 Result := IntToStr(Value div Base); @@ -260,7 +260,7 @@ begin end; (********************************************************************************************************************************) -function FormatDate(Value: TTimeT; const FormatTime, FormatDate: boolean; OverrideTimeFormat: integer = -1; OverrideDateFormat: integer = -1; OverrideDateTimeFormat: integer = -1; OverrideCustomDateFormat: string = ''; OverrideCustomTimeFormat: string = ''): string; +function FormatDate(Value: time_t; const FormatTime, FormatDate: boolean; OverrideTimeFormat: integer = -1; OverrideDateFormat: integer = -1; OverrideDateTimeFormat: integer = -1; OverrideCustomDateFormat: string = ''; OverrideCustomTimeFormat: string = ''): string; var DateString, TimeString: string; DateFormat, TimeFormat: string; CustDateFormat, CustTimeFormat: string; @@ -311,7 +311,7 @@ begin placed := strftime(Buf, 254, PChar(DateFormat), time_tm); if placed <= 0 then DebugMsg(['FormatDate: error converting date. The result will be unpredictable.']); DateString := String(StrToUTF8(Buf)); - Libc.free(Buf); + free(Buf); end; if FormatTime then begin @@ -335,7 +335,7 @@ begin placed := strftime(Buf, 254, PChar(TimeFormat), time_tm); if placed <= 0 then DebugMsg(['FormatDate: error converting time. The result will be unpredictable.']); TimeString := String(StrToUTF8(Buf)); - Libc.free(Buf); + free(Buf); end; if FormatDate and FormatTime then begin @@ -348,7 +348,7 @@ begin if FormatDate then Result := DateString; end; -function StripDate(Value: TTimeT): TTimeT; +function StripDate(Value: time_t): time_t; var time_tm: Ptm; begin time_tm := localtime(@Value); @@ -438,11 +438,11 @@ end; function GetHostName: string; var s: PChar; begin - s := Libc.malloc(65536); - Libc.memset(s, 0, 65536); - Libc.gethostname(s, 65536); + s := malloc(65536); + memset(s, 0, 65536); + ULibc.gethostname(s, 65536); Result := PgcharToString(strdup(s)); - Libc.free(s); + libc_free(s); end; (********************************************************************************************************************************) @@ -1073,14 +1073,14 @@ begin // Make the args_list array args_list := nil; if Length(Parameters) > 0 then begin - args_list := Libc.malloc((Length(Parameters) + 1) * SizeOf(PChar)); - Libc.memset(args_list, 0, (Length(Parameters) + 1) * SizeOf(PChar)); + args_list := malloc((Length(Parameters) + 1) * SizeOf(PChar)); + memset(args_list, 0, (Length(Parameters) + 1) * SizeOf(PChar)); for I := 0 to Length(Parameters) - 1 do begin Temp := Parameters[i]; {$R-} -// PCharArray(args_list^)[I] := Libc.malloc(Length(Temp)+1); -// Libc.memset(PCharArray(args_list^)[I], 0, Length(Temp)+1); +// PCharArray(args_list^)[I] := malloc(Length(Temp)+1); +// memset(PCharArray(args_list^)[I], 0, Length(Temp)+1); // StrCopy(PCharArray(args_list^)[I], PChar(Temp)); PCharArray(args_list^)[I] := strdup(PChar(Temp)); {$R+} @@ -1190,10 +1190,10 @@ begin if ConfUseLibcSystem then begin s := s + ' &'; DebugMsg([s]); - DebugMsg(['**** Running libc.system']); - x := Libc.system(PChar(s)); + DebugMsg(['**** Running system']); + x := libc_system(PChar(s)); Result := x <> -1; // -1 means fork failed - DebugMsg(['**** Running libc.system = ', x, ' --- done']); + DebugMsg(['**** Running system = ', x, ' --- done']); end else begin if Length(Args) = 0 then Exit; for x := 0 to Length(Args) - 1 do Args[x] := RemoveQuotation(Args[x]); @@ -1213,7 +1213,7 @@ end; function IsItX11App(const Application: string): boolean; const BSize = 32768; What = 'libX11.so'; -var stream: PIOFile; +var stream: PFILE; Buffer: Pointer; i: integer; str: string; @@ -1227,14 +1227,14 @@ begin // stream := popen(PChar(Application), 'r'); DebugMsg(['***** IsItX11App: popen OK']); if Assigned(stream) then begin - Buffer := Libc.malloc(BSize); + Buffer := malloc(BSize); if buffer = nil then Writeln('buffer nil: ', integer(errno)); if stream = nil then Writeln('stream nil'); - Libc.memset(Buffer, 0, BSize); + memset(Buffer, 0, BSize); DebugMsg(['***** IsItX11App: malloc() OK']); while feof(stream) = 0 do begin - i := Libc.fread(Buffer, 1, BSize, stream); + i := fread(Buffer, 1, BSize, stream); if i > 0 then begin SetLength(str, i); memcpy(@str[1], Buffer, i); @@ -1253,7 +1253,7 @@ end; function HandleSystemCommand(const Command, ErrorText: string): boolean; const BSize = 32768; -var stream: PIOFile; +var stream: PFILE; Buffer: Pointer; i, NumRead: integer; child_pid: __pid_t; @@ -1274,11 +1274,11 @@ begin // Main application if child_pid <> 0 then begin - __close(fds[1]); + libc_close(fds[1]); stream := fdopen(fds[0], 'r'); - Buffer := Libc.malloc(BSize); + Buffer := malloc(BSize); DebugMsg(['x0']); - Libc.memset(Buffer, 0, BSize); + memset(Buffer, 0, BSize); DebugMsg(['x1']); if buffer = nil then Writeln('buffer nil: ', integer(errno)); if stream = nil then Writeln('stream nil'); @@ -1292,12 +1292,12 @@ begin memcpy(@s[Length(s) - NumRead + 1], Buffer, NumRead); end; end; - __close(fds[0]); + libc_close(fds[0]); DebugMsg(['x2']); TrimCRLFESC(s); DebugMsg(['x3']); - Libc.free(Buffer); + free(Buffer); DebugMsg(['x4']); end @@ -1308,14 +1308,14 @@ begin // Fill the args_list array args_list := nil; if Length(Parameters) > 0 then begin - args_list := Libc.malloc((Length(Parameters) + 1) * SizeOf(PChar)); - Libc.memset(args_list, 0, (Length(Parameters) + 1) * SizeOf(PChar)); + args_list := malloc((Length(Parameters) + 1) * SizeOf(PChar)); + memset(args_list, 0, (Length(Parameters) + 1) * SizeOf(PChar)); for I := 0 to Length(Parameters) - 1 do begin Temp := Parameters[i]; {$R-} -// PCharArray(args_list^)[I] := Libc.malloc(Length(Temp)+1); -// Libc.memset(PCharArray(args_list^)[I], 0, Length(Temp)+1); +// PCharArray(args_list^)[I] := malloc(Length(Temp)+1); +// memset(PCharArray(args_list^)[I], 0, Length(Temp)+1); // StrCopy(PCharArray(args_list^)[I], PChar(Temp)); PCharArray(args_list^)[I] := strdup(PChar(Temp)); {$R+} @@ -1328,7 +1328,7 @@ begin on E: Exception do DebugMsg(['*** forked ** function HandleSystemCommand(''', Command, '''):Exception: ', E.Message]); end; - __close(fds[0]); // Close copy of reader file descriptor + libc_close(fds[0]); // Close copy of reader file descriptor dup2(fds[1], STDERR_FILENO); execvp(PChar(Parameters[0]), args_list); DebugMsg(['***** HandleSystemCommand: failed execvp: something went wrong...']); @@ -1862,9 +1862,9 @@ begin end; procedure SetupSignals; -var sigchld_action: __sigaction; +var sigchld_action: _sigaction; begin - Libc.memset(@sigchld_action, 0, SizeOf(__sigaction)); + memset(@sigchld_action, 0, SizeOf(__sigaction)); sigchld_action.__sigaction_handler := @signal_proc; sigaction(SIGUSR1, @sigchld_action, nil); sigaction(SIGCHLD, @sigchld_action, nil); |
