7
dev:longint; {"device" that this file resides on}
8
ino:int64; {this file's inode #, unique per device}
9
mode:dword; {mode bits (rwx for user, group, etc)}
10
nlink:longint; {number of hard links to this file}
11
uid:dword; {user id of the owner of this file}
12
gid:dword; {group id of the owner of this file}
13
size:int64; {size of this file (in bytes)}
14
rdev:longint; {device type (not used)}
15
blksize:longint; {preferref block size for i/o}
16
atime:longint; {last access time}
17
mtime:longint; {last modification time}
18
ctime:longint; {last change time, not creation time}
19
crtime:longint; {creation time}
25
PathStr = String[255];
27
NameStr = String[255];
30
function FStat(Path:String;Var Info:stat):Boolean;
31
function FStat(var f:File;Var Info:stat):Boolean;
32
function GetEnv(P: string): pchar;
34
function FExpand(Const Path: PathStr):PathStr;
35
function FSearch(const path:pathstr;dirlist:string):pathstr;
36
procedure FSplit(const Path:PathStr;Var Dir:DirStr;Var Name:NameStr;Var Ext:ExtStr);
37
function Dirname(Const path:pathstr):pathstr;
38
function Basename(Const path:pathstr;Const suf:pathstr):pathstr;
39
function FNMatch(const Pattern,Name:string):Boolean;
40
{function StringToPPChar(Var S:STring):ppchar;}
42
function PExists(path:string):boolean;
43
function FExists(path:string):boolean;
45
Function Shell(const Command:String):Longint;
54
function sys_stat (a:cardinal;path:pchar;info:pstat;n:longint):longint; cdecl; external name 'sys_stat';
56
function FStat(Path:String;Var Info:stat):Boolean;
58
Get all information on a file, and return it in Info.
65
FStat:=(sys_stat($FF000000,p,@Info,0)=0);
68
function FStat(var f:File;Var Info:stat):Boolean;
70
Get all information on a file, and return it in Info.
73
FStat:=(sys_stat($FF000000,PChar(@FileRec(f).Name),@Info,0)=0);
78
Function GetEnv(P:string):Pchar;
80
Searches the environment for a string with name p and
81
returns a pchar to it's value.
82
A pchar is used to accomodate for strings of length > 255
88
p:=p+'='; {Else HOST will also find HOSTNAME, etc}
93
while (not found) and (ep^<>nil) do
95
if strlcomp(@p[1],(ep^),length(p))=0 then
102
getenv:=ep^+length(p)
105
{ writeln ('GETENV (',P,') =',getenv);}
110
Function StringToPPChar(Var S:String; Var nr:longint):ppchar;
112
Create a PPChar to structure of pchars which are the arguments specified
113
in the string S. Especially usefull for creating an ArgV for Exec-calls
124
while (buf^ in [' ',#8,#10]) do
127
while not (buf^ in [' ',#0,#8,#10]) do
134
{ LinuxError:=sys_enomem;}
140
while (buf^ in [' ',#8,#10]) do
148
while not (buf^ in [' ',#0,#8,#10]) do
156
function FExpand (const Path: PathStr): PathStr;
157
- declared in fexpand.inc
160
{$DEFINE FPC_FEXPAND_TILDE} { Tilde is expanded to home }
161
{$DEFINE FPC_FEXPAND_GETENVPCHAR} { GetEnv result is a PChar }
165
{$UNDEF FPC_FEXPAND_GETENVPCHAR}
166
{$UNDEF FPC_FEXPAND_TILDE}
170
Function FSearch(const path:pathstr;dirlist:string):pathstr;
172
Searches for a file 'path' in the list of direcories in 'dirlist'.
173
returns an empty string if not found. Wildcards are NOT allowed.
174
If dirlist is empty, it is set to '.'
181
{Replace ':' with ';'}
182
for p1:=1to length(dirlist) do
183
if dirlist[p1]=':' then
185
{Check for WildCards}
186
If (Pos('?',Path) <> 0) or (Pos('*',Path) <> 0) Then
187
FSearch:='' {No wildcards allowed in these things.}
190
Dirlist:='.;'+dirlist;{Make sure current dir is first to be searched.}
192
p1:=Pos(';',DirList);
195
NewDir:=Copy(DirList,1,P1 - 1);
196
if NewDir[Length(NewDir)]<>'/' then
199
Delete(DirList,1,p1);
200
if FStat(NewDir,Info) then
202
If Pos('./',NewDir)=1 Then
204
{DOS strips off an initial .\}
208
Until (DirList='') or (Length(NewDir) > 0);
215
Procedure FSplit(const Path:PathStr;Var Dir:DirStr;Var Name:NameStr;Var Ext:ExtStr);
217
DotPos,SlashPos,i : longint;
222
While (i>0) and (SlashPos=0) Do
224
If (DotPos=256) and (Path[i]='.') Then
226
If (Path[i]='/') Then
230
Ext:=Copy(Path,DotPos,255);
231
Dir:=Copy(Path,1,SlashPos);
232
Name:=Copy(Path,SlashPos + 1,DotPos - SlashPos - 1);
237
Function Dirname(Const path:pathstr):pathstr;
239
This function returns the directory part of a complete path.
240
Unless the directory is root '/', The last character is not
248
FSplit(Path,Dir,Name,Ext);
249
if length(Dir)>1 then
250
Delete(Dir,length(Dir),1);
256
Function Basename(Const path:pathstr;Const suf:pathstr):pathstr;
258
This function returns the filename part of a complete path. If suf is
259
supplied, it is cut off the filename.
266
FSplit(Path,Dir,Name,Ext);
274
Function FNMatch(const Pattern,Name:string):Boolean;
276
LenPat,LenName : longint;
278
Function DoFNMatch(i,j:longint):Boolean;
283
While Found and (i<=LenPat) Do
286
'?' : Found:=(j<=LenName);
288
{find the next character in pattern, different of ? and *}
289
while Found and (i<LenPat) do
302
{Now, find in name the character which i points to, if the * or ?
303
wasn't the last character in the pattern, else, use up all the
309
{find a letter (not only first !) which maches pattern[i]}
310
while (j<=LenName) and (name[j]<>pattern[i]) do
314
if DoFnMatch(i+1,j+1) then
317
j:=LenName;{we can stop}
321
inc(j);{We didn't find one, need to look further}
326
j:=LenName;{we can stop}
328
else {not a wildcard character in pattern}
329
Found:=(j<=LenName) and (pattern[i]=name[j]);
334
DoFnMatch:=Found and (j>LenName);
337
Begin {start FNMatch}
338
LenPat:=Length(Pattern);
339
LenName:=Length(Name);
340
FNMatch:=DoFNMatch(1,1);
344
function PExists(path:string):boolean;
346
PExists:=FExists(path);
349
function FExists(path:string):boolean;
353
FExists:=Fstat(path,info);
356
function sys_load_image(a:cardinal; argp:ppchar; envp:ppchar):longint; cdecl; external name 'sys_load_image';
357
function sys_wait_for_thread (th:longint; var exitcode:longint):longint; cdecl; external name 'sys_wait_for_thread';
359
Function Shell(const Command:String):Longint;
366
argv:=StringToPPChar(s,argc);
368
{ writeln ('argc = ',argc);
369
while argv[th]<>Nil do begin
370
writeln ('argv[',th,'] = ',argv[th]);
374
th:=sys_load_image(argc,argv,system.envp);
379
sys_wait_for_thread(th,Shell);