mirror of
https://gitlab.com/freepascal.org/fpc/source.git
synced 2025-04-20 11:29:27 +02:00
* nds: implemented write(ln) output on the screen (it needs flush tough...)
git-svn-id: trunk@17915 -
This commit is contained in:
parent
e357dc3fb9
commit
fb1e29aef5
@ -14,12 +14,6 @@
|
||||
|
||||
*****************************************************************************}
|
||||
|
||||
function __errno: plongint; cdecl; export;
|
||||
begin
|
||||
|
||||
end;
|
||||
|
||||
|
||||
function S_ISBLK(m: longint): boolean; inline;
|
||||
begin
|
||||
result := (m and _IFMT) = _IFBLK;
|
||||
|
@ -57,9 +57,11 @@ type
|
||||
TSort = function (const a, b: pointer): integer;
|
||||
procedure qsort(__base: pointer; __nmemb: integer; __size: integer; __compar: TSort); cdecl; external;
|
||||
|
||||
function __errno: plongint; cdecl; export;
|
||||
var
|
||||
errno: plongint; external name '__errno';
|
||||
|
||||
type
|
||||
{
|
||||
_FILE = record
|
||||
firstCluster: longword;
|
||||
length: longword;
|
||||
@ -79,7 +81,16 @@ type
|
||||
dirEntOffset: integer; // The offset within the directory sector
|
||||
end;
|
||||
P_FILE = ^_FILE;
|
||||
|
||||
}
|
||||
|
||||
P_iobuf = ^_iobuf;
|
||||
_iobuf = record
|
||||
reserved : longint;
|
||||
end;
|
||||
_FILE = _iobuf;
|
||||
P_FILE = ^_FILE;
|
||||
PP_FILE = ^P_FILE;
|
||||
|
||||
const
|
||||
SEEK_SET = 0;
|
||||
SEEK_CUR = 1;
|
||||
@ -203,24 +214,26 @@ function fileno(para1: P_FILE): longint; cdecl; external;
|
||||
function fileno(var para1: _FILE): longint; cdecl; external;
|
||||
function fstat(fildes: longint; buf: PStat): longint; cdecl; external;
|
||||
function fstat(fildes: longint; var buf: TStat): longint; cdecl; external;
|
||||
function _stat(__file:Pchar; var __buf:Tstat):longint; cdecl; external name 'stat';
|
||||
function _stat(__file: Pchar; var __buf: Tstat): longint; cdecl; external name 'stat';
|
||||
function _stat(path: Pchar; buf: Pstat): longint; cdecl; external name 'stat';
|
||||
function ftruncate(fildes: longint; len: longint): longint; cdecl; external;
|
||||
function unlink(path: Pchar): longint; cdecl; external;
|
||||
function rename(para1: Pchar; para2: Pchar): longint; cdecl; external;
|
||||
|
||||
function FpOpen(path: Pchar; oflag: longint): longint; cdecl; external name 'open';
|
||||
function FpOpen(path: Pchar; oflag, mode: longint): longint; cdecl; external name 'open';
|
||||
function FpRead(fildes:longint; buf:pointer; nbytes:dword):longint;cdecl;external name 'read';
|
||||
function FpRead(fildes:longint; var buf; nbytes:dword):longint;cdecl;external name 'read';
|
||||
function FpWrite(fildes:longint; buf:pointer; nbytes:dword):longint;cdecl;external name 'write';
|
||||
function FpWrite(fildes:longint; var buf; nbytes:dword):longint;cdecl;external name 'write';
|
||||
function fplseek(fildes:longint; offset:longint; whence:longint):longint;cdecl;external name 'lseek';
|
||||
function FpClose(fildes:longint):longint;cdecl;external name 'close';
|
||||
function FpUnlink(path:Pchar):longint;cdecl;external name 'unlink';
|
||||
function FpRename(para1: Pchar; para2: Pchar): longint; cdecl; external name 'rename';
|
||||
function Fpstat(path:Pchar; buf:Pstat):longint;cdecl;external name 'stat';
|
||||
function Fpstat(path:Pchar; var buf:Tstat):longint;cdecl;external name 'stat';
|
||||
function FpAccess(path:Pchar; mode:longint):longint;cdecl;external name 'access';
|
||||
function _open(path: Pchar; oflag: longint): longint; cdecl; external name 'open';
|
||||
function _open(path: Pchar; oflag, mode: longint): longint; cdecl; external name 'open';
|
||||
function _read(fildes:longint; buf:pointer; nbytes:dword):longint;cdecl;external name 'read';
|
||||
function _read(fildes:longint; var buf; nbytes:dword):longint;cdecl;external name 'read';
|
||||
function _write(fildes:longint; buf:pointer; nbytes:dword):longint;cdecl;external name 'write';
|
||||
function _write(fildes:longint; var buf; nbytes:dword):longint;cdecl;external name 'write';
|
||||
function _lseek(fildes:longint; offset:longint; whence:longint):longint;cdecl;external name 'lseek';
|
||||
function _close(fildes:longint): longint; cdecl; external name 'close';
|
||||
function _unlink(path:Pchar): longint; cdecl; external name 'unlink';
|
||||
function _rename(para1: Pchar; para2: Pchar): longint; cdecl; external name 'rename';
|
||||
function _access(path: Pchar; mode: longint): longint; cdecl; external name 'access';
|
||||
function _tell(fildes: longint): longint; cdecl; external name 'tell';
|
||||
function _isatty(fildes: longint): longint; cdecl; external name 'isatty';
|
||||
function _truncate(fildes: longint; len: longint): longint; cdecl; external name 'truncate';
|
||||
|
||||
|
||||
|
||||
@ -275,4 +288,140 @@ const
|
||||
SH_DENYRD = $00000030; // deny read mode
|
||||
SH_DENYNO = $00000040; // deny none mode
|
||||
|
||||
Const
|
||||
|
||||
Sys_EPERM = 1; { Operation not permitted }
|
||||
Sys_ENOENT = 2; { No such file or directory }
|
||||
Sys_ESRCH = 3; { No such process }
|
||||
Sys_EINTR = 4; { Interrupted system call }
|
||||
Sys_EIO = 5; { I/O error }
|
||||
Sys_ENXIO = 6; { No such device or address }
|
||||
Sys_E2BIG = 7; { Arg list too long }
|
||||
Sys_ENOEXEC = 8; { Exec format error }
|
||||
Sys_EBADF = 9; { Bad file number }
|
||||
Sys_ECHILD = 10; { No child processes }
|
||||
Sys_EAGAIN = 11; { Try again }
|
||||
Sys_ENOMEM = 12; { Out of memory }
|
||||
Sys_EACCES = 13; { Permission denied }
|
||||
Sys_EFAULT = 14; { Bad address }
|
||||
Sys_ENOTBLK = 15; { Block device required, NOT POSIX! }
|
||||
Sys_EBUSY = 16; { Device or resource busy }
|
||||
Sys_EEXIST = 17; { File exists }
|
||||
Sys_EXDEV = 18; { Cross-device link }
|
||||
Sys_ENODEV = 19; { No such device }
|
||||
Sys_ENOTDIR = 20; { Not a directory }
|
||||
Sys_EISDIR = 21; { Is a directory }
|
||||
Sys_EINVAL = 22; { Invalid argument }
|
||||
Sys_ENFILE = 23; { File table overflow }
|
||||
Sys_EMFILE = 24; { Too many open files }
|
||||
Sys_ENOTTY = 25; { Not a typewriter }
|
||||
Sys_ETXTBSY = 26; { Text file busy. The new process was
|
||||
a pure procedure (shared text) file which was
|
||||
open for writing by another process, or file
|
||||
which was open for writing by another process,
|
||||
or while the pure procedure file was being
|
||||
executed an open(2) call requested write access
|
||||
requested write access.}
|
||||
Sys_EFBIG = 27; { File too large }
|
||||
Sys_ENOSPC = 28; { No space left on device }
|
||||
Sys_ESPIPE = 29; { Illegal seek }
|
||||
Sys_EROFS = 30; { Read-only file system }
|
||||
Sys_EMLINK = 31; { Too many links }
|
||||
Sys_EPIPE = 32; { Broken pipe }
|
||||
Sys_EDOM = 33; { Math argument out of domain of func }
|
||||
Sys_ERANGE = 34; { Math result not representable }
|
||||
Sys_EDEADLK = 35; { Resource deadlock would occur }
|
||||
Sys_ENAMETOOLONG= 36; { File name too long }
|
||||
Sys_ENOLCK = 37; { No record locks available }
|
||||
Sys_ENOSYS = 38; { Function not implemented }
|
||||
Sys_ENOTEMPTY= 39; { Directory not empty }
|
||||
Sys_ELOOP = 40; { Too many symbolic links encountered }
|
||||
Sys_EWOULDBLOCK = Sys_EAGAIN; { Operation would block }
|
||||
Sys_ENOMSG = 42; { No message of desired type }
|
||||
Sys_EIDRM = 43; { Identifier removed }
|
||||
Sys_ECHRNG = 44; { Channel number out of range }
|
||||
Sys_EL2NSYNC= 45; { Level 2 not synchronized }
|
||||
Sys_EL3HLT = 46; { Level 3 halted }
|
||||
Sys_EL3RST = 47; { Level 3 reset }
|
||||
Sys_ELNRNG = 48; { Link number out of range }
|
||||
Sys_EUNATCH = 49; { Protocol driver not attached }
|
||||
Sys_ENOCSI = 50; { No CSI structure available }
|
||||
Sys_EL2HLT = 51; { Level 2 halted }
|
||||
Sys_EBADE = 52; { Invalid exchange }
|
||||
Sys_EBADR = 53; { Invalid request descriptor }
|
||||
Sys_EXFULL = 54; { Exchange full }
|
||||
Sys_ENOANO = 55; { No anode }
|
||||
Sys_EBADRQC = 56; { Invalid request code }
|
||||
Sys_EBADSLT = 57; { Invalid slot }
|
||||
Sys_EDEADLOCK= 58; { File locking deadlock error }
|
||||
Sys_EBFONT = 59; { Bad font file format }
|
||||
Sys_ENOSTR = 60; { Device not a stream }
|
||||
Sys_ENODATA = 61; { No data available }
|
||||
Sys_ETIME = 62; { Timer expired }
|
||||
Sys_ENOSR = 63; { Out of streams resources }
|
||||
Sys_ENONET = 64; { Machine is not on the network }
|
||||
Sys_ENOPKG = 65; { Package not installed }
|
||||
Sys_EREMOTE = 66; { Object is remote }
|
||||
Sys_ENOLINK = 67; { Link has been severed }
|
||||
Sys_EADV = 68; { Advertise error }
|
||||
Sys_ESRMNT = 69; { Srmount error }
|
||||
Sys_ECOMM = 70; { Communication error on send }
|
||||
Sys_EPROTO = 71; { Protocol error }
|
||||
Sys_EMULTIHOP= 72; { Multihop attempted }
|
||||
Sys_EDOTDOT = 73; { RFS specific error }
|
||||
Sys_EBADMSG = 74; { Not a data message }
|
||||
Sys_EOVERFLOW= 75; { Value too large for defined data type }
|
||||
Sys_ENOTUNIQ= 76; { Name not unique on network }
|
||||
Sys_EBADFD = 77; { File descriptor in bad state }
|
||||
Sys_EREMCHG = 78; { Remote address changed }
|
||||
Sys_ELIBACC = 79; { Can not access a needed shared library }
|
||||
Sys_ELIBBAD = 80; { Accessing a corrupted shared library }
|
||||
Sys_ELIBSCN = 81; { .lib section in a.out corrupted }
|
||||
Sys_ELIBMAX = 82; { Attempting to link in too many shared libraries }
|
||||
Sys_ELIBEXEC= 83; { Cannot exec a shared library directly }
|
||||
Sys_EILSEQ = 84; { Illegal byte sequence }
|
||||
Sys_ERESTART= 85; { Interrupted system call should be restarted }
|
||||
Sys_ESTRPIPE= 86; { Streams pipe error }
|
||||
Sys_EUSERS = 87; { Too many users }
|
||||
Sys_ENOTSOCK= 88; { Socket operation on non-socket }
|
||||
Sys_EDESTADDRREQ= 89; { Destination address required }
|
||||
Sys_EMSGSIZE= 90; { Message too long }
|
||||
Sys_EPROTOTYPE= 91; { Protocol wrong type for socket }
|
||||
Sys_ENOPROTOOPT= 92; { Protocol not available }
|
||||
Sys_EPROTONOSUPPORT= 93; { Protocol not supported }
|
||||
Sys_ESOCKTNOSUPPORT= 94; { Socket type not supported }
|
||||
Sys_EOPNOTSUPP= 95; { Operation not supported on transport endpoint }
|
||||
Sys_EPFNOSUPPORT= 96; { Protocol family not supported }
|
||||
Sys_EAFNOSUPPORT= 97; { Address family not supported by protocol }
|
||||
Sys_EADDRINUSE= 98; { Address already in use }
|
||||
Sys_EADDRNOTAVAIL= 99; { Cannot assign requested address }
|
||||
Sys_ENETDOWN= 100; { Network is down }
|
||||
Sys_ENETUNREACH= 101; { Network is unreachable }
|
||||
Sys_ENETRESET= 102; { Network dropped connection because of reset }
|
||||
Sys_ECONNABORTED= 103; { Software caused connection abort }
|
||||
Sys_ECONNRESET= 104; { Connection reset by peer }
|
||||
Sys_ENOBUFS = 105; { No buffer space available }
|
||||
Sys_EISCONN = 106; { Transport endpoint is already connected }
|
||||
Sys_ENOTCONN= 107; { Transport endpoint is not connected }
|
||||
Sys_ESHUTDOWN= 108; { Cannot send after transport endpoint shutdown }
|
||||
Sys_ETOOMANYREFS= 109; { Too many references: cannot splice }
|
||||
Sys_ETIMEDOUT= 110; { Connection timed out }
|
||||
Sys_ECONNREFUSED= 111; { Connection refused }
|
||||
Sys_EHOSTDOWN= 112; { Host is down }
|
||||
Sys_EHOSTUNREACH= 113; { No route to host }
|
||||
Sys_EALREADY= 114; { Operation already in progress }
|
||||
Sys_EINPROGRESS= 115; { Operation now in progress }
|
||||
Sys_ESTALE = 116; { Stale NFS file handle }
|
||||
Sys_EUCLEAN = 117; { Structure needs cleaning }
|
||||
Sys_ENOTNAM = 118; { Not a XENIX named type file }
|
||||
Sys_ENAVAIL = 119; { No XENIX semaphores available }
|
||||
Sys_EISNAM = 120; { Is a named type file }
|
||||
Sys_EREMOTEIO= 121; { Remote I/O error }
|
||||
Sys_EDQUOT = 122; { Quota exceeded }
|
||||
|
||||
|
||||
{ This value was suggested by Daniel
|
||||
based on infos from www.linuxassembly.org }
|
||||
|
||||
Sys_ERROR_MAX = $fff;
|
||||
|
@ -22,71 +22,206 @@
|
||||
All these functions can set InOutRes on errors
|
||||
****************************************************************************}
|
||||
|
||||
|
||||
procedure NDS2PASErr(Err: longint);
|
||||
begin
|
||||
if Err = 0 then { Else it will go through all the cases }
|
||||
exit;
|
||||
case Err of
|
||||
Sys_ENFILE,
|
||||
Sys_EMFILE : Inoutres := 4;
|
||||
Sys_ENOENT : Inoutres := 2;
|
||||
Sys_EBADF : Inoutres := 6;
|
||||
Sys_ENOMEM,
|
||||
Sys_EFAULT : Inoutres := 217;
|
||||
Sys_EINVAL : Inoutres := 218;
|
||||
Sys_EPIPE,
|
||||
Sys_EINTR,
|
||||
Sys_EIO,
|
||||
Sys_EAGAIN,
|
||||
Sys_ENOSPC : Inoutres := 101;
|
||||
Sys_ENAMETOOLONG,
|
||||
Sys_ELOOP,
|
||||
Sys_ENOTDIR : Inoutres := 3;
|
||||
Sys_EROFS,
|
||||
Sys_EEXIST,
|
||||
Sys_EACCES : Inoutres := 5;
|
||||
Sys_EBUSY : Inoutres := 162
|
||||
else begin
|
||||
Writeln(stderr, 'NDS2PASErr: unknown error ', err);
|
||||
flush(stderr);
|
||||
Inoutres := Err;
|
||||
end;
|
||||
end;
|
||||
END;
|
||||
|
||||
|
||||
procedure Errno2Inoutres;
|
||||
begin
|
||||
NDS2PASErr(errno^);
|
||||
end;
|
||||
|
||||
procedure SetFileError(var Err: longint);
|
||||
begin
|
||||
if Err >= 0 then
|
||||
InOutRes := 0
|
||||
else begin
|
||||
Err := errno^;
|
||||
NDS2PASErr(Err);
|
||||
Err := 0;
|
||||
end;
|
||||
end;
|
||||
|
||||
|
||||
|
||||
|
||||
{ close a file from the handle value }
|
||||
procedure do_close(handle: THandle);
|
||||
var
|
||||
res: longint;
|
||||
begin
|
||||
fclose(P_FILE(Handle));
|
||||
//fclose(P_FILE(Handle));
|
||||
res := _close(handle);
|
||||
if res <> 0 then
|
||||
SetFileError(res)
|
||||
else
|
||||
InOutRes := 0;
|
||||
end;
|
||||
|
||||
procedure do_erase(p: pchar);
|
||||
var
|
||||
res: longint;
|
||||
begin
|
||||
unlink(p);
|
||||
//unlink(p);
|
||||
res := _unlink(p);
|
||||
if res <> 0 then
|
||||
SetFileError(res)
|
||||
else
|
||||
InOutRes := 0;
|
||||
end;
|
||||
|
||||
procedure do_rename(p1, p2: pchar);
|
||||
var
|
||||
res: longint;
|
||||
begin
|
||||
rename(p1, p2);
|
||||
//rename(p1, p2);
|
||||
res := _rename(p1, p2);
|
||||
if res <> 0 then
|
||||
SetFileError(res)
|
||||
else
|
||||
InOutRes := 0;
|
||||
end;
|
||||
|
||||
function do_write(h: THandle; addr: pointer; len: longint) : longint;
|
||||
var
|
||||
res: longint;
|
||||
begin
|
||||
result := fwrite(addr, 1, len, P_FILE(h));
|
||||
//result := fwrite(addr, 1, len, P_FILE(h));
|
||||
res := _write(h, addr, len);
|
||||
if res > 0 then
|
||||
InOutRes := 0
|
||||
else
|
||||
SetFileError(res);
|
||||
do_write := res;
|
||||
end;
|
||||
|
||||
function do_read(h: THandle; addr: pointer; len: longint) : longint;
|
||||
var
|
||||
res: longint;
|
||||
begin
|
||||
result := fread(addr, 1, len, P_FILE(h));
|
||||
//result := fread(addr, 1, len, P_FILE(h));
|
||||
res := _read(h, addr, len);
|
||||
if res > 0 then
|
||||
InOutRes := 0
|
||||
else
|
||||
SetFileError(res);
|
||||
do_read := res;
|
||||
end;
|
||||
|
||||
function do_filepos(handle: THandle): longint;
|
||||
var
|
||||
res: longint;
|
||||
begin
|
||||
result := ftell(P_FILE(handle));
|
||||
InOutRes := 0;
|
||||
|
||||
//result := ftell(P_FILE(handle));
|
||||
res := _tell(handle);
|
||||
if res < 0 then
|
||||
SetFileError(res)
|
||||
else
|
||||
InOutRes := 0;
|
||||
do_filepos := res;
|
||||
end;
|
||||
|
||||
procedure do_seek(handle: THandle; pos: longint);
|
||||
var
|
||||
res: longint;
|
||||
begin
|
||||
fseek(P_FILE(handle), pos, SEEK_SET);
|
||||
//fseek(P_FILE(handle), pos, SEEK_SET);
|
||||
_lseek(handle, pos, SEEK_SET);
|
||||
if res < 0 then
|
||||
SetFileError(res)
|
||||
else
|
||||
InOutRes := 0;
|
||||
end;
|
||||
|
||||
function do_seekend(handle: THandle): longint;
|
||||
var
|
||||
res: longint;
|
||||
begin
|
||||
result := fseek(P_FILE(handle), 0, SEEK_END);
|
||||
//result := fseek(P_FILE(handle), 0, SEEK_END);
|
||||
res := _lseek(handle, 0, SEEK_END);
|
||||
if res < 0 then
|
||||
SetFileError(res)
|
||||
else
|
||||
InOutRes := 0;
|
||||
do_seekend := res;
|
||||
end;
|
||||
|
||||
function do_filesize(handle: THandle): longint;
|
||||
var
|
||||
res : LONGINT;
|
||||
res : longint;
|
||||
statbuf : TStat;
|
||||
begin
|
||||
res := fstat(fileno(P_FILE(handle)), statbuf);
|
||||
//res := fstat(fileno(P_FILE(handle)), statbuf);
|
||||
res := fstat(handle, statbuf);
|
||||
if res = 0 then
|
||||
begin
|
||||
InOutRes := 0;
|
||||
result := statbuf.st_size
|
||||
else
|
||||
result := -1;
|
||||
end else
|
||||
begin
|
||||
SetFileError(Res);
|
||||
do_filesize := -1;
|
||||
end;
|
||||
end;
|
||||
|
||||
{ truncate at a given position }
|
||||
procedure do_truncate(handle: THandle; pos: longint);
|
||||
var
|
||||
res : longint;
|
||||
begin
|
||||
ftruncate(fileno(P_FILE(handle)), pos);
|
||||
//ftruncate(fileno(P_FILE(handle)), pos);
|
||||
res := _truncate(handle, pos);
|
||||
if res <> 0 then
|
||||
SetFileError(res)
|
||||
else
|
||||
InOutRes := 0;
|
||||
end;
|
||||
|
||||
procedure do_open(var f; p: pchar; flags: longint);
|
||||
procedure do_open(var f;p:pchar;flags:longint);
|
||||
{
|
||||
filerec and textrec have both handle and mode as the first items so
|
||||
they could use the same routine for opening/creating.
|
||||
when (flags and $10) the file will be append
|
||||
when (flags and $100) the file will be truncate/rewritten
|
||||
when (flags and $1000) there is no check for close (needed for textfiles)
|
||||
}
|
||||
var
|
||||
oflags : string[10];
|
||||
oflags: longint;
|
||||
begin
|
||||
{ close first if opened }
|
||||
if ((flags and $10000) = 0) then
|
||||
if ((flags and $10000)=0) then
|
||||
begin
|
||||
case FileRec(f).mode of
|
||||
fminput,fmoutput,fminout : Do_Close(FileRec(f).Handle);
|
||||
@ -104,65 +239,63 @@ begin
|
||||
{ We do the conversion of filemodes here, concentrated on 1 place }
|
||||
case (flags and 3) of
|
||||
0 : begin
|
||||
oflags := 'rb'#0;
|
||||
oflags := O_RDONLY;
|
||||
filerec(f).mode := fminput;
|
||||
end;
|
||||
1 : begin
|
||||
if (flags and $1000)=$1000 then
|
||||
oflags := 'w+b' else
|
||||
oflags := 'wb';
|
||||
oflags := O_WRONLY;
|
||||
filerec(f).mode := fmoutput;
|
||||
end;
|
||||
2 : begin
|
||||
if (flags and $1000)=$1000 then
|
||||
oflags := 'w+' else
|
||||
oflags := 'r+';
|
||||
oflags := O_RDWR;
|
||||
filerec(f).mode := fminout;
|
||||
end;
|
||||
end;
|
||||
{if (flags and $1000)=$1000 then
|
||||
oflags:=oflags or (O_CREAT or O_TRUNC)
|
||||
if (flags and $1000) = $1000 then
|
||||
oflags := oflags or (O_CREAT or O_TRUNC)
|
||||
else
|
||||
if (flags and $100)=$100 then
|
||||
oflags:=oflags or (O_APPEND);}
|
||||
if (flags and $100) = $100 then
|
||||
oflags := oflags or (O_APPEND);
|
||||
{ empty name is special }
|
||||
if p[0]=#0 then
|
||||
if p[0] = #0 then
|
||||
begin
|
||||
case FileRec(f).mode of
|
||||
fminput :
|
||||
FileRec(f).Handle:=StdInputHandle;
|
||||
fminput:
|
||||
FileRec(f).Handle := StdInputHandle;
|
||||
fminout, { this is set by rewrite }
|
||||
fmoutput :
|
||||
FileRec(f).Handle:=StdOutputHandle;
|
||||
FileRec(f).Handle := StdOutputHandle;
|
||||
fmappend :
|
||||
begin
|
||||
FileRec(f).Handle:=StdOutputHandle;
|
||||
FileRec(f).mode:=fmoutput; {fool fmappend}
|
||||
FileRec(f).Handle := StdOutputHandle;
|
||||
FileRec(f).mode := fmoutput; {fool fmappend}
|
||||
end;
|
||||
end;
|
||||
exit;
|
||||
end;
|
||||
{ real open call }
|
||||
FileRec(f).Handle := THandle(fopen(p, @oflags[1]));//_open(p,oflags,438);
|
||||
//WriteLn ('_open (',p,') returned ',ErrNo, 'Handle: ',FileRec(f).Handle);
|
||||
// errno does not seem to be set on succsess ??
|
||||
{IF FileRec(f).Handle < 0 THEN
|
||||
if (ErrNo=Sys_EROFS) and ((OFlags and O_RDWR)<>0) then
|
||||
errno^ := 0;
|
||||
FileRec(f).Handle := _open(p, oflags, 438);
|
||||
{ open somtimes returns > -1 but errno was set }
|
||||
if (errno^ <> 0) or (longint(FileRec(f).Handle) < 0) then
|
||||
if (errno^ = Sys_EROFS) and ((OFlags and O_RDWR) <> 0) then
|
||||
begin // i.e. for cd-rom
|
||||
Oflags:=Oflags and not(O_RDWR);
|
||||
Oflags := Oflags and not(O_RDWR);
|
||||
FileRec(f).Handle := _open(p,oflags,438);
|
||||
end;}
|
||||
{
|
||||
if FileRec(f).Handle = 0 then
|
||||
end;
|
||||
if (errno^ <> 0) or (longint(FileRec(f).Handle) < 0) then
|
||||
Errno2Inoutres
|
||||
else
|
||||
InOutRes := 0;
|
||||
}
|
||||
end;
|
||||
|
||||
|
||||
|
||||
|
||||
function do_isdevice(handle: THandle): boolean;
|
||||
begin
|
||||
result := (isatty(fileno(P_FILE(handle))) > 0);
|
||||
//result := (isatty(fileno(P_FILE(handle))) > 0);
|
||||
do_isdevice := (_isatty(handle) > 0);
|
||||
end;
|
||||
|
||||
|
||||
|
@ -246,7 +246,6 @@ begin
|
||||
end;
|
||||
|
||||
function get_cmdline:Pchar;
|
||||
|
||||
begin
|
||||
if calculated_cmdline=nil then
|
||||
setupcmdline;
|
||||
@ -256,11 +255,11 @@ end;
|
||||
|
||||
procedure SysInitStdIO;
|
||||
begin
|
||||
OpenStdIO(Input,fmInput,0);
|
||||
OpenStdIO(Output,fmOutput,0);
|
||||
OpenStdIO(ErrOutput,fmOutput,0);
|
||||
OpenStdIO(StdOut,fmOutput,0);
|
||||
OpenStdIO(StdErr,fmOutput,0);
|
||||
OpenStdIO(Input,fmInput,StdInputHandle);
|
||||
OpenStdIO(Output,fmOutput,StdOutputHandle);
|
||||
OpenStdIO(ErrOutput,fmOutput,StdErrorHandle);
|
||||
OpenStdIO(StdOut,fmOutput,StdOutputHandle);
|
||||
OpenStdIO(StdErr,fmOutput,StdErrorHandle);
|
||||
end;
|
||||
|
||||
|
||||
@ -284,7 +283,6 @@ begin
|
||||
|
||||
SetupCmdLine;
|
||||
|
||||
|
||||
{$ifdef FPC_HAS_FEATURE_CONSOLEIO}
|
||||
{ Setup stdin, stdout and stderr }
|
||||
SysInitStdIO;
|
||||
|
@ -55,7 +55,7 @@ begin
|
||||
fmOpenWrite : NDSFlags := NDSFlags or O_WrOnly;
|
||||
fmOpenReadWrite : NDSFlags := NDSFlags or O_RdWr;
|
||||
end;
|
||||
FileOpen := fpopen(pchar(FileName), NDSFlags);
|
||||
FileOpen := _open(pchar(FileName), NDSFlags);
|
||||
end;
|
||||
|
||||
|
||||
@ -73,13 +73,13 @@ end;
|
||||
|
||||
function FileCreate(const FileName: string) : LongInt;
|
||||
begin
|
||||
FileCreate:=fpopen(pointer(FileName), O_RdWr or O_Creat or O_Trunc);
|
||||
FileCreate:=_open(pointer(FileName), O_RdWr or O_Creat or O_Trunc);
|
||||
end;
|
||||
|
||||
|
||||
function FileCreate(const FileName: string; Rights: integer): LongInt;
|
||||
begin
|
||||
FileCreate:=fpOpen(pointer(FileName),O_RdWr or O_Creat or O_Trunc,Rights);
|
||||
FileCreate:=_Open(pointer(FileName),O_RdWr or O_Creat or O_Trunc,Rights);
|
||||
end;
|
||||
|
||||
|
||||
@ -91,13 +91,13 @@ end;
|
||||
|
||||
function FileRead(Handle: LongInt; Out Buffer; Count: LongInt): LongInt;
|
||||
begin
|
||||
FileRead := fpRead(Handle, Buffer, Count);
|
||||
FileRead := _Read(Handle, Buffer, Count);
|
||||
end;
|
||||
|
||||
|
||||
function FileWrite(Handle: LongInt; const Buffer; Count: LongInt): LongInt;
|
||||
begin
|
||||
FileWrite := fpWrite(Handle, @Buffer, Count);
|
||||
FileWrite := _Write(Handle, @Buffer, Count);
|
||||
end;
|
||||
|
||||
|
||||
@ -108,13 +108,13 @@ end;
|
||||
|
||||
function FileSeek(Handle: LongInt; FOffset: Int64; Origin: Longint): Int64;
|
||||
begin
|
||||
FileSeek := fplSeek(Handle, FOffset, Origin);
|
||||
FileSeek := _lSeek(Handle, FOffset, Origin);
|
||||
end;
|
||||
|
||||
|
||||
procedure FileClose(Handle: LongInt);
|
||||
begin
|
||||
fpclose(Handle);
|
||||
_close(Handle);
|
||||
end;
|
||||
|
||||
|
||||
@ -123,19 +123,19 @@ begin
|
||||
if Size > high (longint) then
|
||||
FileTruncate := false
|
||||
else
|
||||
FileTruncate:=(ftruncate(Handle,Size) = 0);
|
||||
FileTruncate:=(_truncate(Handle,Size) = 0);
|
||||
end;
|
||||
|
||||
|
||||
function DeleteFile(const FileName: string) : Boolean;
|
||||
begin
|
||||
Result := fpUnLink(pointer(FileName))>= 0;
|
||||
Result := _UnLink(pointer(FileName))>= 0;
|
||||
end;
|
||||
|
||||
|
||||
function RenameFile(const OldName, NewName: string): Boolean;
|
||||
begin
|
||||
RenameFile := FpRename(pointer(OldNAme), pointer(NewName)) >= 0;
|
||||
RenameFile := _Rename(pointer(OldNAme), pointer(NewName)) >= 0;
|
||||
end;
|
||||
|
||||
|
||||
@ -146,7 +146,7 @@ Function FileAge (Const FileName : String): Longint;
|
||||
var
|
||||
info: Stat;
|
||||
begin
|
||||
if (fpstat(pointer(FileName), Info) < 0) or S_ISDIR(info.st_mode) then
|
||||
if (_stat(pchar(FileName), Info) < 0) or S_ISDIR(info.st_mode) then
|
||||
exit(-1)
|
||||
else
|
||||
Result := (info.st_mtime);
|
||||
@ -155,7 +155,7 @@ end;
|
||||
|
||||
Function FileExists (Const FileName : String) : Boolean;
|
||||
begin
|
||||
FileExists := fpAccess(pointer(filename), F_OK) = 0;
|
||||
FileExists := _Access(pointer(filename), F_OK) = 0;
|
||||
end;
|
||||
|
||||
|
||||
@ -179,7 +179,7 @@ end;
|
||||
Function FileGetAttr (Const FileName : String) : Longint;
|
||||
Var Info : TStat;
|
||||
begin
|
||||
If Fpstat(pchar(FileName), Info) <> 0 then
|
||||
If _stat(pchar(FileName), Info) <> 0 then
|
||||
Result := -1
|
||||
Else
|
||||
Result := (Info.st_mode shr 16) and $ffff;
|
||||
|
Loading…
Reference in New Issue
Block a user