mirror of https://github.com/red-prig/fpPS4.git
sceKernelTruncate/truncate
This commit is contained in:
parent
8c6a8b5313
commit
35e26766f0
|
@ -66,6 +66,9 @@ function ps4_ioctl(fd,cmd:Integer;param1:ptruint):Integer; SysV_ABI_CDecl;
|
|||
function ps4_stat(path:PChar;stat:PSceKernelStat):Integer; SysV_ABI_CDecl;
|
||||
function ps4_sceKernelStat(path:PChar;stat:PSceKernelStat):Integer; SysV_ABI_CDecl;
|
||||
|
||||
function ps4_truncate(path:PChar;length:Int64):Integer; SysV_ABI_CDecl;
|
||||
function ps4_sceKernelTruncate(path:PChar;length:Int64):Integer; SysV_ABI_CDecl;
|
||||
|
||||
function ps4_mkdir(path:PChar;mode:Integer):Integer; SysV_ABI_CDecl;
|
||||
function ps4_sceKernelMkdir(path:PChar;mode:Integer):Integer; SysV_ABI_CDecl;
|
||||
|
||||
|
@ -651,6 +654,65 @@ begin
|
|||
Result:=px2sce(Result);
|
||||
end;
|
||||
|
||||
function _sys_truncate(path:PChar;length:Int64):Integer;
|
||||
var
|
||||
fn:RawByteString;
|
||||
begin
|
||||
Result:=0;
|
||||
|
||||
if (path=nil) then Exit(EINVAL);
|
||||
if (length<=0) then Exit(EINVAL);
|
||||
|
||||
if (path[0]=#0) then
|
||||
begin
|
||||
Exit(ENOENT);
|
||||
end;
|
||||
|
||||
Writeln(SysLogPrefix,'truncate:',path,' ',length);
|
||||
|
||||
fn:='';
|
||||
Result:=parse_filename(path,fn);
|
||||
|
||||
Case Result of
|
||||
PT_ROOT:Exit(EACCES); //TODO
|
||||
PT_FILE:;
|
||||
PT_DEV :Exit(EACCES);
|
||||
else
|
||||
Exit(EACCES);
|
||||
end;
|
||||
|
||||
if FileExists(fn) then
|
||||
begin
|
||||
Result:=_sys_file_trunc(fn,length);
|
||||
end else
|
||||
begin
|
||||
if DirectoryExists(fn) then
|
||||
begin
|
||||
Result:=EISDIR;
|
||||
end else
|
||||
begin
|
||||
Result:=ENOENT;
|
||||
end;
|
||||
end;
|
||||
end;
|
||||
|
||||
function ps4_truncate(path:PChar;length:Int64):Integer; SysV_ABI_CDecl;
|
||||
begin
|
||||
_sig_lock;
|
||||
Result:=_set_errno(_sys_truncate(path,length));
|
||||
_sig_unlock;
|
||||
end;
|
||||
|
||||
function ps4_sceKernelTruncate(path:PChar;length:Int64):Integer; SysV_ABI_CDecl;
|
||||
begin
|
||||
_sig_lock;
|
||||
Result:=_sys_truncate(path,length);
|
||||
_sig_unlock;
|
||||
|
||||
_set_errno(Result);
|
||||
Result:=px2sce(Result);
|
||||
end;
|
||||
|
||||
function _sys_mkdir(path:PChar;mode:Integer):Integer;
|
||||
var
|
||||
fn:RawByteString;
|
||||
|
|
|
@ -1718,6 +1718,9 @@ begin
|
|||
lib^.set_proc($13A6A8DF8C0FC3E5,@ps4_stat);
|
||||
lib^.set_proc($795F70003DAB8880,@ps4_sceKernelStat);
|
||||
|
||||
lib^.set_proc($6B2AEDB3323B1818,@ps4_truncate);
|
||||
lib^.set_proc($5A5C8403FB0B0DFD,@ps4_sceKernelTruncate);
|
||||
|
||||
lib^.set_proc($246322A3EDB52F87,@ps4_mkdir);
|
||||
lib^.set_proc($D7F2C52E6445C713,@ps4_sceKernelMkdir);
|
||||
|
||||
|
|
|
@ -16,6 +16,7 @@ uses
|
|||
|
||||
function _sys_file_open(const path:RawByteString;flags,mode:Integer):Integer;
|
||||
function _sys_file_stat(Const path:RawByteString;stat:PSceKernelStat):Integer;
|
||||
function _sys_file_trunc(Const path:RawByteString;length:Int64):Integer;
|
||||
|
||||
implementation
|
||||
|
||||
|
@ -169,13 +170,26 @@ var
|
|||
begin
|
||||
f:=nil;
|
||||
Result:=__sys_file_open(path,O_RDONLY,0,f);
|
||||
if (Result<>0) then Exit(-Result);
|
||||
if (Result<>0) then Exit;
|
||||
|
||||
Result:=f.fstat(stat);
|
||||
|
||||
f.Destroy;
|
||||
end;
|
||||
|
||||
function _sys_file_trunc(Const path:RawByteString;length:Int64):Integer;
|
||||
var
|
||||
f:TFile;
|
||||
begin
|
||||
f:=nil;
|
||||
Result:=__sys_file_open(path,O_RDWR,0,f);
|
||||
if (Result<>0) then Exit;
|
||||
|
||||
Result:=f.ftruncate(length);
|
||||
|
||||
f.Destroy;
|
||||
end;
|
||||
|
||||
//
|
||||
|
||||
Constructor TFile.Create;
|
||||
|
|
Loading…
Reference in New Issue