mirror of
https://gitlab.com/freepascal.org/fpc/source.git
synced 2026-01-06 17:10:50 +01:00
+ rawbytestring/unicodestring overloads for FileCreate and FileOpen.
The WinCE implementation converts the rawbytestring arguments to
unicodestring and calls unicode OS APIs, while the others convert
unicodestring arguments to DefaultFileSystemCodePage and call
single byte OS APIs
+ test for the above
git-svn-id: branches/cpstrrtl@22467 -
This commit is contained in:
parent
598d2feeb6
commit
a3c936fe5f
2
.gitattributes
vendored
2
.gitattributes
vendored
@ -8294,6 +8294,7 @@ rtl/objpas/sysconst.pp svneol=native#text/plain
|
||||
rtl/objpas/sysutils/dati.inc svneol=native#text/plain
|
||||
rtl/objpas/sysutils/datih.inc svneol=native#text/plain
|
||||
rtl/objpas/sysutils/diskh.inc svneol=native#text/plain
|
||||
rtl/objpas/sysutils/filutil.inc svneol=native#text/plain
|
||||
rtl/objpas/sysutils/filutilh.inc svneol=native#text/plain
|
||||
rtl/objpas/sysutils/fina.inc svneol=native#text/plain
|
||||
rtl/objpas/sysutils/finah.inc svneol=native#text/plain
|
||||
@ -11636,6 +11637,7 @@ tests/test/units/sysutils/tlocale.pp svneol=native#text/plain
|
||||
tests/test/units/sysutils/trwsync.pp svneol=native#text/plain
|
||||
tests/test/units/sysutils/tsscanf.pp svneol=native#text/plain
|
||||
tests/test/units/sysutils/tstrtobool.pp svneol=native#text/plain
|
||||
tests/test/units/sysutils/tunifile.pp svneol=native#text/plain
|
||||
tests/test/units/variants/tcustomvariant.pp svneol=native#text/plain
|
||||
tests/test/units/variants/tvararrayofintf.pp svneol=native#text/plain
|
||||
tests/test/uobjc24.pp svneol=native#text/plain
|
||||
|
||||
@ -41,6 +41,9 @@ uses dos,sysconst;
|
||||
{$DEFINE FPC_FEXPAND_DRIVESEP_IS_ROOT}
|
||||
{$DEFINE FPC_FEXPAND_NO_DEFAULT_PATHS}
|
||||
|
||||
{ used OS file system APIs use ansistring }
|
||||
{$define SYSUTILS_HAS_ANSISTR_FILEUTIL_IMPL}
|
||||
|
||||
{ Include platform independent implementation part }
|
||||
{$i sysutils.inc}
|
||||
|
||||
@ -104,13 +107,16 @@ end;
|
||||
|
||||
(****** non portable routines ******)
|
||||
|
||||
function FileOpen(const FileName: string; Mode: Integer): LongInt;
|
||||
function FileOpen(const FileName: rawbytestring; Mode: Integer): LongInt;
|
||||
var
|
||||
SystemFileName: RawByteString;
|
||||
dosResult: LongInt;
|
||||
tmpStr : array[0..255] of char;
|
||||
begin
|
||||
SystemFileName:=ToSingleByteFileSystemEncodedFileName(FileName);
|
||||
{$WARNING FIX ME! To do: FileOpen Access Modes}
|
||||
tmpStr:=PathConv(FileName)+#0;
|
||||
{$WARNING FIX ME! PathConv takes a shortstring, which means 255 char truncation and conversion to defaultsystemcodepage, ignoring the defaultfilesystemcodepage setting}
|
||||
tmpStr:=PathConv(SystemFileName)+#0;
|
||||
dosResult:=Open(@tmpStr,MODE_OLDFILE);
|
||||
if dosResult=0 then
|
||||
dosResult:=-1
|
||||
@ -134,11 +140,14 @@ begin
|
||||
end;
|
||||
|
||||
|
||||
function FileCreate(const FileName: string) : LongInt;
|
||||
function FileCreate(const FileName: RawByteString) : LongInt;
|
||||
var
|
||||
SystemFileName: RawByteString;
|
||||
dosResult: LongInt;
|
||||
tmpStr : array[0..255] of char;
|
||||
begin
|
||||
SystemFileName:=ToSingleByteFileSystemEncodedFileName(FileName);
|
||||
{$WARNING FIX ME! PathConv takes a shortstring, which means 255 char truncation and conversion to defaultsystemcodepage, ignoring the defaultfilesystemcodepage setting}
|
||||
tmpStr:=PathConv(FileName)+#0;
|
||||
dosResult:=Open(@tmpStr,MODE_NEWFILE);
|
||||
if dosResult=0 then
|
||||
@ -150,13 +159,13 @@ begin
|
||||
end;
|
||||
|
||||
|
||||
function FileCreate(const FileName: string; Rights: integer): LongInt;
|
||||
function FileCreate(const FileName: RawByteString; Rights: integer): LongInt;
|
||||
begin
|
||||
{$WARNING FIX ME! To do: FileCreate Access Modes}
|
||||
FileCreate:=FileCreate(FileName);
|
||||
end;
|
||||
|
||||
function FileCreate(const FileName: string; ShareMode: integer; Rights : Integer): LongInt;
|
||||
function FileCreate(const FileName: RawByteString; ShareMode: integer; Rights : Integer): LongInt;
|
||||
begin
|
||||
{$WARNING FIX ME! To do: FileCreate Access Modes}
|
||||
FileCreate:=FileCreate(FileName);
|
||||
|
||||
@ -38,6 +38,9 @@ implementation
|
||||
{$DEFINE FPC_FEXPAND_UNC} (* UNC paths are supported *)
|
||||
{$DEFINE FPC_FEXPAND_DRIVES} (* Full paths begin with drive specification *)
|
||||
|
||||
{ used OS file system APIs use ansistring }
|
||||
{$define SYSUTILS_HAS_ANSISTR_FILEUTIL_IMPL}
|
||||
|
||||
{ Include platform independent implementation part }
|
||||
{$i sysutils.inc}
|
||||
|
||||
@ -452,7 +455,7 @@ const
|
||||
specification for DosFindFirst call.}
|
||||
|
||||
{$ASMMODE INTEL}
|
||||
function FileOpen (const FileName: string; Mode: integer): longint; assembler;
|
||||
function FileOpen (const FileName: pointer; Mode: integer): longint; assembler;
|
||||
asm
|
||||
push ebx
|
||||
{$IFDEF REGCALL}
|
||||
@ -477,21 +480,28 @@ asm
|
||||
pop ebx
|
||||
end {['eax', 'ebx', 'ecx', 'edx']};
|
||||
|
||||
function FileOpen (const FileName: rawbytestring; Mode: integer): longint;
|
||||
var
|
||||
SystemFileName: RawByteString;
|
||||
begin
|
||||
SystemFileName := ToSingleByteFileSystemEncodedFileName(FileName);
|
||||
FileOpen := FileOpen(pointer(SystemFileName),Mode);
|
||||
end;
|
||||
|
||||
function FileCreate (const FileName: string): longint;
|
||||
function FileCreate (const FileName: RawByteString): longint;
|
||||
begin
|
||||
FileCreate := FileCreate (FileName, ofReadWrite or faCreate or doDenyRW, 777);
|
||||
(* Sharing to DenyAll *)
|
||||
end;
|
||||
|
||||
|
||||
function FileCreate (const FileName: string; Rights: integer): longint;
|
||||
function FileCreate (const FileName: RawByteString; Rights: integer): longint;
|
||||
begin
|
||||
FileCreate := FileCreate (FileName, ofReadWrite or faCreate or doDenyRW,
|
||||
Rights); (* Sharing to DenyAll *)
|
||||
end;
|
||||
|
||||
function FileCreate (const FileName: string; ShareMode: integer; Rights: integer): longint; assembler;
|
||||
function FileCreate (const FileName: Pointer; ShareMode: integer; Rights: integer): longint; assembler;
|
||||
asm
|
||||
push ebx
|
||||
{$IFDEF REGCALL}
|
||||
@ -515,6 +525,13 @@ asm
|
||||
pop ebx
|
||||
end {['eax', 'ebx', 'ecx', 'edx']};
|
||||
|
||||
function FileCreate (const FileName: RawByteString; ShareMode: integer; Rights: integer): longint;
|
||||
var
|
||||
SystemFileName: RawByteString;
|
||||
begin
|
||||
SystemFileName := ToSingleByteFileSystemEncodedFileName(FileName);
|
||||
FileOpen := FileCreate(pointer(SystemFileName),ShareMode,Rights);
|
||||
end;
|
||||
|
||||
function FileRead (Handle: longint; Out Buffer; Count: longint): longint;
|
||||
assembler;
|
||||
|
||||
@ -41,6 +41,9 @@ implementation
|
||||
uses
|
||||
dos, sysconst;
|
||||
|
||||
{ used OS file system APIs use ansistring }
|
||||
{$define SYSUTILS_HAS_ANSISTR_FILEUTIL_IMPL}
|
||||
|
||||
{ Include platform independent implementation part }
|
||||
{$i sysutils.inc}
|
||||
|
||||
@ -48,7 +51,7 @@ uses
|
||||
{****************************************************************************
|
||||
File Functions
|
||||
****************************************************************************}
|
||||
function FileOpen(const FileName: string; Mode: Integer): LongInt;
|
||||
function FileOpen(const FileName: rawbytestring; Mode: Integer): LongInt;
|
||||
begin
|
||||
result := -1;
|
||||
end;
|
||||
@ -66,19 +69,19 @@ begin
|
||||
end;
|
||||
|
||||
|
||||
function FileCreate(const FileName: string) : LongInt;
|
||||
function FileCreate(const FileName: RawByteString) : LongInt;
|
||||
begin
|
||||
result := -1;
|
||||
end;
|
||||
|
||||
|
||||
function FileCreate(const FileName: string; Rights: integer): LongInt;
|
||||
function FileCreate(const FileName: RawByteString; Rights: integer): LongInt;
|
||||
begin
|
||||
result := -1;
|
||||
end;
|
||||
|
||||
|
||||
function FileCreate(const FileName: string; ShareMode: integer; rights : integer): LongInt;
|
||||
function FileCreate(const FileName: RawByteString; ShareMode: integer; rights : integer): LongInt;
|
||||
begin
|
||||
result := -1;
|
||||
end;
|
||||
|
||||
@ -40,6 +40,9 @@ implementation
|
||||
{$DEFINE FPC_FEXPAND_UNC} (* UNC paths are supported *)
|
||||
{$DEFINE FPC_FEXPAND_DRIVES} (* Full paths begin with drive specification *)
|
||||
|
||||
{ used OS file system APIs use ansistring }
|
||||
{$define SYSUTILS_HAS_ANSISTR_FILEUTIL_IMPL}
|
||||
|
||||
{ Include platform independent implementation part }
|
||||
{$i sysutils.inc}
|
||||
|
||||
@ -67,7 +70,7 @@ Type
|
||||
procedure StringToTB(const S: string);
|
||||
var
|
||||
P: pchar;
|
||||
Len: integer;
|
||||
Len: longint;
|
||||
begin
|
||||
Len := Length(S) + 1;
|
||||
P := StrPCopy(StrAlloc(Len), S);
|
||||
@ -75,10 +78,23 @@ begin
|
||||
StrDispose(P);
|
||||
end ;
|
||||
|
||||
procedure StringToTB(const S: rawbytestring);
|
||||
var
|
||||
P: pchar;
|
||||
Len: longint;
|
||||
begin
|
||||
Len := Length(S) + 1;
|
||||
if Len > tb_size then
|
||||
Len := tb_size;
|
||||
P := StrPCopy(StrAlloc(Len), S);
|
||||
SysCopyToDos(longint(P), Len);
|
||||
StrDispose(P);
|
||||
end ;
|
||||
|
||||
|
||||
{ Native OpenFile function.
|
||||
if return value <> 0 call failed. }
|
||||
function OpenFile(const FileName: string; var Handle: longint; Mode, Action: word): longint;
|
||||
function OpenFile(const FileName: rawbytestring; var Handle: longint; Mode, Action: word): longint;
|
||||
var
|
||||
Regs: registers;
|
||||
begin
|
||||
@ -110,33 +126,37 @@ begin
|
||||
end;
|
||||
|
||||
|
||||
Function FileOpen (Const FileName : string; Mode : Integer) : Longint;
|
||||
Function FileOpen (Const FileName : rawbytestring; Mode : Integer) : Longint;
|
||||
var
|
||||
SystemFileName: RawByteString;
|
||||
e: integer;
|
||||
Begin
|
||||
e := OpenFile(FileName, result, Mode, faOpen);
|
||||
begin
|
||||
SystemFileName:=ToSingleByteFileSystemEncodedFileName(FileName);
|
||||
e := OpenFile(SystemFileName, result, Mode, faOpen);
|
||||
if e <> 0 then
|
||||
result := -1;
|
||||
end;
|
||||
|
||||
|
||||
Function FileCreate (Const FileName : String) : Longint;
|
||||
Function FileCreate (Const FileName : RawByteString) : Longint;
|
||||
var
|
||||
SystemFileName: RawByteString;
|
||||
e: integer;
|
||||
begin
|
||||
SystemFileName := ToSingleByteFileSystemEncodedFileName(FileName);
|
||||
e := OpenFile(FileName, result, ofReadWrite, faCreate or faOpenReplace);
|
||||
if e <> 0 then
|
||||
result := -1;
|
||||
end;
|
||||
|
||||
|
||||
Function FileCreate (Const FileName : String; ShareMode:longint; Rights : longint) : Longint;
|
||||
Function FileCreate (Const FileName : RawByteString; ShareMode:longint; Rights : longint) : Longint;
|
||||
begin
|
||||
FileCreate:=FileCreate(FileName);
|
||||
end;
|
||||
|
||||
|
||||
Function FileCreate (Const FileName : String; Rights:longint) : Longint;
|
||||
Function FileCreate (Const FileName : RawByteString; Rights:longint) : Longint;
|
||||
begin
|
||||
FileCreate:=FileCreate(FileName);
|
||||
end;
|
||||
|
||||
@ -58,6 +58,9 @@ uses
|
||||
{$DEFINE FPC_FEXPAND_NO_DOTS_UPDIR}
|
||||
{$DEFINE FPC_FEXPAND_NO_CURDIR}
|
||||
|
||||
{ used OS file system APIs use ansistring }
|
||||
{$define SYSUTILS_HAS_ANSISTR_FILEUTIL_IMPL}
|
||||
|
||||
{ Include platform independent implementation part }
|
||||
{$i sysutils.inc}
|
||||
|
||||
@ -66,12 +69,13 @@ uses
|
||||
File Functions
|
||||
****************************************************************************}
|
||||
|
||||
Function FileOpen (Const FileName : string; Mode : Integer) : Longint;
|
||||
Function FileOpen (Const FileName : rawbytestring; Mode : Integer) : Longint;
|
||||
|
||||
Var LinuxFlags : longint;
|
||||
|
||||
BEGIN
|
||||
SystemFileName: RawByteString;
|
||||
begin
|
||||
(* TODO fix
|
||||
SystemFileName:=ToSingleByteFileSystemEncodedFileName(FileName);
|
||||
LinuxFlags:=0;
|
||||
Case (Mode and 3) of
|
||||
0 : LinuxFlags:=LinuxFlags or Open_RdOnly;
|
||||
@ -84,7 +88,7 @@ BEGIN
|
||||
end;
|
||||
|
||||
|
||||
Function FileCreate (Const FileName : String) : Longint;
|
||||
Function FileCreate (Const FileName : RawByteString) : Longint;
|
||||
|
||||
begin
|
||||
(* TODO fix
|
||||
@ -93,7 +97,7 @@ begin
|
||||
end;
|
||||
|
||||
|
||||
Function FileCreate (Const FileName : String;Rights : Longint) : Longint;
|
||||
Function FileCreate (Const FileName : RawByteString;Rights : Longint) : Longint;
|
||||
|
||||
Var LinuxFlags : longint;
|
||||
|
||||
@ -109,7 +113,7 @@ BEGIN
|
||||
*)
|
||||
end;
|
||||
|
||||
Function FileCreate (Const FileName : String;ShareMode : Longint; Rights : Longint) : Longint;
|
||||
Function FileCreate (Const FileName : RawByteString;ShareMode : Longint; Rights : Longint) : Longint;
|
||||
|
||||
Var LinuxFlags : longint;
|
||||
|
||||
|
||||
@ -42,6 +42,9 @@ uses dos,sysconst;
|
||||
{$DEFINE FPC_FEXPAND_DRIVESEP_IS_ROOT}
|
||||
{$DEFINE FPC_FEXPAND_NO_DEFAULT_PATHS}
|
||||
|
||||
{ used OS file system APIs use ansistring }
|
||||
{$define SYSUTILS_HAS_ANSISTR_FILEUTIL_IMPL}
|
||||
|
||||
{ Include platform independent implementation part }
|
||||
{$i sysutils.inc}
|
||||
|
||||
@ -105,13 +108,16 @@ end;
|
||||
|
||||
(****** non portable routines ******)
|
||||
|
||||
function FileOpen(const FileName: string; Mode: Integer): LongInt;
|
||||
function FileOpen(const FileName: rawbytestring; Mode: Integer): LongInt;
|
||||
var
|
||||
SystemFileName: RawByteString;
|
||||
dosResult: LongInt;
|
||||
tmpStr : array[0..255] of char;
|
||||
begin
|
||||
SystemFileName:=ToSingleByteFileSystemEncodedFileName(FileName);
|
||||
{$WARNING FIX ME! To do: FileOpen Access Modes}
|
||||
tmpStr:=PathConv(FileName)+#0;
|
||||
{$WARNING FIX ME! PathConv takes a shortstring, which means 255 char truncation and conversion to defaultsystemcodepage, ignoring the defaultfilesystemcodepage setting}
|
||||
tmpStr:=PathConv(SystemFileName)+#0;
|
||||
dosResult:=Open(@tmpStr,MODE_OLDFILE);
|
||||
if dosResult=0 then
|
||||
dosResult:=-1
|
||||
@ -135,12 +141,15 @@ begin
|
||||
end;
|
||||
|
||||
|
||||
function FileCreate(const FileName: string) : LongInt;
|
||||
function FileCreate(const FileName: RawByteString) : LongInt;
|
||||
var
|
||||
SystemFileName: RawByteString;
|
||||
dosResult: LongInt;
|
||||
tmpStr : array[0..255] of char;
|
||||
begin
|
||||
tmpStr:=PathConv(FileName)+#0;
|
||||
SystemFileName:=ToSingleByteFileSystemEncodedFileName(FileName);
|
||||
{$WARNING FIX ME! PathConv takes a shortstring, which means 255 char truncation and conversion to defaultsystemcodepage, ignoring the defaultfilesystemcodepage setting}
|
||||
tmpStr:=PathConv(SystemFileName)+#0;
|
||||
dosResult:=Open(@tmpStr,MODE_NEWFILE);
|
||||
if dosResult=0 then
|
||||
dosResult:=-1
|
||||
@ -151,13 +160,13 @@ begin
|
||||
end;
|
||||
|
||||
|
||||
function FileCreate(const FileName: string; Rights: integer): LongInt;
|
||||
function FileCreate(const FileName: RawByteString; Rights: integer): LongInt;
|
||||
begin
|
||||
{$WARNING FIX ME! To do: FileCreate Access Modes}
|
||||
FileCreate:=FileCreate(FileName);
|
||||
end;
|
||||
|
||||
function FileCreate(const FileName: string; ShareMode: integer; Rights : integer): LongInt;
|
||||
function FileCreate(const FileName: RawByteString; ShareMode: integer; Rights : integer): LongInt;
|
||||
begin
|
||||
{$WARNING FIX ME! To do: FileCreate Access Modes}
|
||||
FileCreate:=FileCreate(FileName);
|
||||
|
||||
@ -24,7 +24,7 @@ uses
|
||||
|
||||
// Helpers for converting Pascal string types to NT's UNICODE_STRING
|
||||
procedure ShortStrToNTStr(aStr: ShortString; var aNTStr: UNICODE_STRING);
|
||||
procedure AnsiStrToNTStr(const aStr: String; var aNTStr: UNICODE_STRING);
|
||||
procedure AnsiStrToNTStr(const aStr: RawByteString; var aNTStr: UNICODE_STRING);
|
||||
procedure UnicodeStrToNtStr(const aStr: UnicodeString;
|
||||
var aNTStr: UNICODE_STRING);
|
||||
procedure PCharToNTStr(aStr: PChar; aLen: Cardinal; var aNTStr: UNICODE_STRING);
|
||||
@ -53,7 +53,7 @@ begin
|
||||
aNTStr.MaximumLength := aNTStr.Length;
|
||||
end;
|
||||
|
||||
procedure AnsiStrToNTStr(const aStr: String; var aNTStr: UNICODE_STRING);
|
||||
procedure AnsiStrToNTStr(const aStr: RawByteString; var aNTStr: UNICODE_STRING);
|
||||
var
|
||||
buf: PWideChar;
|
||||
i: Integer;
|
||||
|
||||
@ -49,6 +49,9 @@ implementation
|
||||
|
||||
{$DEFINE FPC_NOGENERICANSIROUTINES}
|
||||
|
||||
{ used OS file system APIs use ansistring }
|
||||
{$define SYSUTILS_HAS_ANSISTR_FILEUTIL_IMPL}
|
||||
|
||||
{ Include platform independent implementation part }
|
||||
{$i sysutils.inc}
|
||||
|
||||
@ -56,7 +59,7 @@ implementation
|
||||
File Functions
|
||||
****************************************************************************}
|
||||
|
||||
function FileOpen(const FileName : string; Mode : Integer) : THandle;
|
||||
function FileOpen(const FileName : rawbytestring; Mode : Integer) : THandle;
|
||||
const
|
||||
AccessMode: array[0..2] of ACCESS_MASK = (
|
||||
GENERIC_READ,
|
||||
@ -73,7 +76,7 @@ var
|
||||
objattr: OBJECT_ATTRIBUTES;
|
||||
iostatus: IO_STATUS_BLOCK;
|
||||
begin
|
||||
AnsiStrToNtStr(FileName, ntstr);
|
||||
AnsiStrToNtStr(ToSingleByteFileSystemEncodedFileName(FileName), ntstr);
|
||||
InitializeObjectAttributes(objattr, @ntstr, 0, 0, Nil);
|
||||
NtCreateFile(@Result, AccessMode[Mode and 3] or NT_SYNCHRONIZE, @objattr,
|
||||
@iostatus, Nil, FILE_ATTRIBUTE_NORMAL, ShareMode[(Mode and $F0) shr 4],
|
||||
@ -82,19 +85,19 @@ begin
|
||||
end;
|
||||
|
||||
|
||||
function FileCreate(const FileName : String) : THandle;
|
||||
function FileCreate(const FileName : RawByteString) : THandle;
|
||||
begin
|
||||
FileCreate := FileCreate(FileName, fmShareDenyNone, 0);
|
||||
end;
|
||||
|
||||
|
||||
function FileCreate(const FileName : String; Rights: longint) : THandle;
|
||||
function FileCreate(const FileName : RawByteString; Rights: longint) : THandle;
|
||||
begin
|
||||
FileCreate := FileCreate(FileName, fmShareDenyNone, Rights);
|
||||
end;
|
||||
|
||||
|
||||
function FileCreate(const FileName : String; ShareMode : longint; Rights: longint) : THandle;
|
||||
function FileCreate(const FileName : RawByteString; ShareMode : longint; Rights: longint) : THandle;
|
||||
const
|
||||
ShareModeFlags: array[0..4] of ULONG = (
|
||||
0,
|
||||
@ -108,7 +111,7 @@ var
|
||||
iostatus: IO_STATUS_BLOCK;
|
||||
res: NTSTATUS;
|
||||
begin
|
||||
AnsiStrToNTStr(FileName, ntstr);
|
||||
AnsiStrToNTStr(ToSingleByteFileSystemEncodedFileName(FileName), ntstr);
|
||||
InitializeObjectAttributes(objattr, @ntstr, 0, 0, Nil);
|
||||
NtCreateFile(@Result, GENERIC_READ or GENERIC_WRITE or NT_SYNCHRONIZE,
|
||||
@objattr, @iostatus, Nil, FILE_ATTRIBUTE_NORMAL,
|
||||
|
||||
@ -37,6 +37,9 @@ implementation
|
||||
uses
|
||||
sysconst;
|
||||
|
||||
{ used OS file system APIs use ansistring }
|
||||
{$define SYSUTILS_HAS_ANSISTR_FILEUTIL_IMPL}
|
||||
|
||||
{ Include platform independent implementation part }
|
||||
{$i sysutils.inc}
|
||||
|
||||
@ -44,10 +47,12 @@ uses
|
||||
{****************************************************************************
|
||||
File Functions
|
||||
****************************************************************************}
|
||||
function FileOpen(const FileName: string; Mode: Integer): LongInt;
|
||||
function FileOpen(const FileName: rawbytestring; Mode: Integer): LongInt;
|
||||
var
|
||||
NDSFlags: longint;
|
||||
SystemFileName: RawByteString;
|
||||
begin
|
||||
SystemFileName:=ToSingleByteFileSystemEncodedFileName(FileName);
|
||||
NDSFlags := 0;
|
||||
|
||||
case (Mode and (fmOpenRead or fmOpenWrite or fmOpenReadWrite)) of
|
||||
@ -55,7 +60,7 @@ begin
|
||||
fmOpenWrite : NDSFlags := NDSFlags or O_WrOnly;
|
||||
fmOpenReadWrite : NDSFlags := NDSFlags or O_RdWr;
|
||||
end;
|
||||
FileOpen := _open(pchar(FileName), NDSFlags);
|
||||
FileOpen := _open(pchar(SystemFileName), NDSFlags);
|
||||
end;
|
||||
|
||||
|
||||
@ -71,19 +76,25 @@ begin
|
||||
end;
|
||||
|
||||
|
||||
function FileCreate(const FileName: string) : LongInt;
|
||||
function FileCreate(const FileName: RawByteString) : LongInt;
|
||||
var
|
||||
SystemFileName: RawByteString;
|
||||
begin
|
||||
FileCreate:=_open(pointer(FileName), O_RdWr or O_Creat or O_Trunc);
|
||||
SystemFileName:=ToSingleByteFileSystemEncodedFileName(FileName);
|
||||
FileCreate:=_open(pointer(SystemFileName), O_RdWr or O_Creat or O_Trunc);
|
||||
end;
|
||||
|
||||
|
||||
function FileCreate(const FileName: string; Rights: integer): LongInt;
|
||||
function FileCreate(const FileName: RawByteString; Rights: integer): LongInt;
|
||||
var
|
||||
SystemFileName: RawByteString;
|
||||
begin
|
||||
FileCreate:=_Open(pointer(FileName),O_RdWr or O_Creat or O_Trunc,Rights);
|
||||
SystemFileName:=ToSingleByteFileSystemEncodedFileName(FileName);
|
||||
FileCreate:=_Open(pointer(SystemFileName),O_RdWr or O_Creat or O_Trunc,Rights);
|
||||
end;
|
||||
|
||||
|
||||
function FileCreate(const FileName: string; ShareMode : Integer; Rights: integer): LongInt;
|
||||
function FileCreate(const FileName: RawByteString; ShareMode : Integer; Rights: integer): LongInt;
|
||||
begin
|
||||
result := FileCreate(FileName, Rights);
|
||||
end;
|
||||
|
||||
@ -77,6 +77,9 @@ implementation
|
||||
{$define FPC_FEXPAND_VOLUMES}
|
||||
{$define FPC_FEXPAND_NO_DEFAULT_PATHS}
|
||||
|
||||
{ used OS file system APIs use ansistring }
|
||||
{$define SYSUTILS_HAS_ANSISTR_FILEUTIL_IMPL}
|
||||
|
||||
{ Include platform independent implementation part }
|
||||
{$i sysutils.inc}
|
||||
|
||||
@ -85,35 +88,38 @@ implementation
|
||||
File Functions
|
||||
****************************************************************************}
|
||||
|
||||
Function FileOpen (Const FileName : string; Mode : Integer) : THandle;
|
||||
Function FileOpen (Const FileName : rawbytestring; Mode : Integer) : THandle;
|
||||
VAR NWOpenFlags : longint;
|
||||
BEGIN
|
||||
SystemFileName: RawByteString;
|
||||
begin
|
||||
SystemFileName:=ToSingleByteFileSystemEncodedFileName(FileName);
|
||||
NWOpenFlags:=0;
|
||||
Case (Mode and 3) of
|
||||
0 : NWOpenFlags:=NWOpenFlags or O_RDONLY;
|
||||
1 : NWOpenFlags:=NWOpenFlags or O_WRONLY;
|
||||
2 : NWOpenFlags:=NWOpenFlags or O_RDWR;
|
||||
end;
|
||||
FileOpen := _open (pchar(FileName),NWOpenFlags,0);
|
||||
FileOpen := _open (pchar(SystemFileName),NWOpenFlags,0);
|
||||
|
||||
//!! We need to set locking based on Mode !!
|
||||
end;
|
||||
|
||||
|
||||
Function FileCreate (Const FileName : String) : THandle;
|
||||
|
||||
Function FileCreate (Const FileName : RawByteString) : THandle;
|
||||
VAR SystemFileName: RawByteString;
|
||||
begin
|
||||
FileCreate:=_open(Pchar(FileName),O_RdWr or O_Creat or O_Trunc,0);
|
||||
SystemFileName:=ToSingleByteFileSystemEncodedFileName(FileName);
|
||||
FileCreate:=_open(Pchar(SystemFileName),O_RdWr or O_Creat or O_Trunc,0);
|
||||
end;
|
||||
|
||||
Function FileCreate (Const FileName : String; Rights:longint) : THandle;
|
||||
Function FileCreate (Const FileName : RawByteString; Rights:longint) : THandle;
|
||||
|
||||
begin
|
||||
FileCreate:=FileCreate (FileName);
|
||||
end;
|
||||
|
||||
|
||||
Function FileCreate (Const FileName : String; ShareMode: Longint; Rights:longint) : THandle;
|
||||
Function FileCreate (Const FileName : RawByteString; ShareMode: Longint; Rights:longint) : THandle;
|
||||
|
||||
begin
|
||||
FileCreate:=FileCreate (FileName);
|
||||
|
||||
@ -79,6 +79,9 @@ implementation
|
||||
{$DEFINE FPC_FEXPAND_VOLUMES}
|
||||
{$DEFINE FPC_FEXPAND_NO_DEFAULT_PATHS}
|
||||
|
||||
{ used OS file system APIs use ansistring }
|
||||
{$define SYSUTILS_HAS_ANSISTR_FILEUTIL_IMPL}
|
||||
|
||||
{ Include platform independent implementation part }
|
||||
{$i sysutils.inc}
|
||||
|
||||
@ -87,35 +90,39 @@ implementation
|
||||
File Functions
|
||||
****************************************************************************}
|
||||
|
||||
Function FileOpen (Const FileName : string; Mode : Integer) : THandle;
|
||||
Function FileOpen (Const FileName : rawbytestring; Mode : Integer) : THandle;
|
||||
VAR NWOpenFlags : longint;
|
||||
BEGIN
|
||||
SystemFileName: RawByteString;
|
||||
begin
|
||||
SystemFileName:=ToSingleByteFileSystemEncodedFileName(FileName);
|
||||
NWOpenFlags:=0;
|
||||
Case (Mode and 3) of
|
||||
0 : NWOpenFlags:=NWOpenFlags or O_RDONLY;
|
||||
1 : NWOpenFlags:=NWOpenFlags or O_WRONLY;
|
||||
2 : NWOpenFlags:=NWOpenFlags or O_RDWR;
|
||||
end;
|
||||
FileOpen := Fpopen (pchar(FileName),NWOpenFlags);
|
||||
FileOpen := Fpopen (pchar(SystemFileName),NWOpenFlags);
|
||||
|
||||
//!! We need to set locking based on Mode !!
|
||||
end;
|
||||
|
||||
|
||||
Function FileCreate (Const FileName : String) : THandle;
|
||||
Function FileCreate (Const FileName : RawByteString) : THandle;
|
||||
var SystemFileName: RawByteString;
|
||||
begin
|
||||
FileCreate:=Fpopen(Pchar(FileName),O_RdWr or O_Creat or O_Trunc or O_Binary);
|
||||
SystemFileName:=ToSingleByteFileSystemEncodedFileName(FileName);
|
||||
FileCreate:=Fpopen(Pchar(SystemFileName),O_RdWr or O_Creat or O_Trunc or O_Binary);
|
||||
if FileCreate >= 0 then
|
||||
FileSetAttr (Filename, 0); // dont know why but open always sets ReadOnly flag
|
||||
end;
|
||||
|
||||
Function FileCreate (Const FileName : String; rights:longint) : THandle;
|
||||
Function FileCreate (Const FileName : RawByteString; rights:longint) : THandle;
|
||||
begin
|
||||
FileCreate:=FileCreate (FileName);
|
||||
end;
|
||||
|
||||
|
||||
Function FileCreate (Const FileName : String; ShareMode:longint; rights : longint) : THandle;
|
||||
Function FileCreate (Const FileName : RawByteString; ShareMode:longint; rights : longint) : THandle;
|
||||
begin
|
||||
FileCreate:=FileCreate (FileName);
|
||||
end;
|
||||
|
||||
80
rtl/objpas/sysutils/filutil.inc
Normal file
80
rtl/objpas/sysutils/filutil.inc
Normal file
@ -0,0 +1,80 @@
|
||||
{
|
||||
This file is part of the Free Pascal run time library.
|
||||
Copyright (c) 2012 by the Free Pascal development team
|
||||
|
||||
File utility calls
|
||||
|
||||
See the file COPYING.FPC, included in this distribution,
|
||||
for details about the copyright.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
||||
|
||||
**********************************************************************}
|
||||
|
||||
Function ToSingleByteFileSystemEncodedFileName(const Str: UnicodeString): RawByteString;
|
||||
Begin
|
||||
widestringmanager.Unicode2AnsiMoveProc(punicodechar(Str),Result,
|
||||
DefaultFileSystemCodePage,Length(Str));
|
||||
End;
|
||||
|
||||
|
||||
Function ToSingleByteFileSystemEncodedFileName(const Str: RawByteString): RawByteString;
|
||||
Begin
|
||||
Result:=Str;
|
||||
SetCodePage(Result,DefaultFileSystemCodePage,True);
|
||||
End;
|
||||
|
||||
|
||||
{$ifndef SYSUTILS_HAS_UNICODESTR_FILEUTIL_IMPL}
|
||||
Function FileOpen (Const FileName : unicodestring; Mode : Integer) : THandle;
|
||||
begin
|
||||
Result:=FileOpen(ToSingleByteFileSystemEncodedFileName(FileName),Mode);
|
||||
end;
|
||||
|
||||
|
||||
Function FileCreate (Const FileName : UnicodeString) : THandle;
|
||||
begin
|
||||
Result:=FileCreate(ToSingleByteFileSystemEncodedFileName(FileName));
|
||||
end;
|
||||
|
||||
|
||||
Function FileCreate (Const FileName : UnicodeString; Rights : Integer) : THandle;
|
||||
begin
|
||||
Result:=FileCreate(ToSingleByteFileSystemEncodedFileName(FileName),Rights);
|
||||
end;
|
||||
|
||||
|
||||
Function FileCreate (Const FileName : UnicodeString; ShareMode : Integer; Rights : Integer) : THandle;
|
||||
begin
|
||||
Result:=FileCreate(ToSingleByteFileSystemEncodedFileName(FileName),ShareMode,Rights);
|
||||
end;
|
||||
{$endif}
|
||||
|
||||
|
||||
{$ifndef SYSUTILS_HAS_ANSISTR_FILEUTIL_IMPL}
|
||||
Function FileOpen (Const FileName : rawbytestring; Mode : Integer) : THandle;
|
||||
begin
|
||||
Result:=FileOpen(UnicodeString(FileName),Mode);
|
||||
end;
|
||||
|
||||
|
||||
Function FileCreate (Const FileName : RawByteString) : THandle;
|
||||
begin
|
||||
Result:=FileCreate(UnicodeString(FileName));
|
||||
end;
|
||||
|
||||
|
||||
Function FileCreate (Const FileName : RawByteString; Rights : Integer) : THandle;
|
||||
begin
|
||||
Result:=FileCreate(UnicodeString(FileName),Rights);
|
||||
end;
|
||||
|
||||
|
||||
Function FileCreate (Const FileName : RawByteString; ShareMode : Integer; Rights : Integer) : THandle;
|
||||
begin
|
||||
Result:=FileCreate(UnicodeString(FileName),ShareMode,Rights);
|
||||
end;
|
||||
{$endif}
|
||||
|
||||
@ -78,10 +78,14 @@ Type
|
||||
TFileSearchOption = (sfoImplicitCurrentDir,sfoStripQuotes);
|
||||
TFileSearchOptions = set of TFileSearchOption;
|
||||
|
||||
Function FileOpen (Const FileName : string; Mode : Integer) : THandle;
|
||||
Function FileCreate (Const FileName : String) : THandle;
|
||||
Function FileCreate (Const FileName : String; Rights : Integer) : THandle;
|
||||
Function FileCreate (Const FileName : String; ShareMode : Integer; Rights : Integer) : THandle;
|
||||
Function FileOpen (Const FileName : rawbytestring; Mode : Integer) : THandle;
|
||||
Function FileOpen (Const FileName : unicodestring; Mode : Integer) : THandle;
|
||||
Function FileCreate (Const FileName : RawByteString) : THandle;
|
||||
Function FileCreate (Const FileName : RawByteString; Rights : Integer) : THandle;
|
||||
Function FileCreate (Const FileName : RawByteString; ShareMode : Integer; Rights : Integer) : THandle;
|
||||
Function FileCreate (Const FileName : UnicodeString) : THandle;
|
||||
Function FileCreate (Const FileName : UnicodeString; Rights : Integer) : THandle;
|
||||
Function FileCreate (Const FileName : UnicodeString; ShareMode : Integer; Rights : Integer) : THandle;
|
||||
Function FileRead (Handle : THandle; out Buffer; Count : longint) : Longint;
|
||||
Function FileWrite (Handle : THandle; const Buffer; Count : Longint) : Longint;
|
||||
Function FileSeek (Handle : THandle; FOffset, Origin: Longint) : Longint;
|
||||
|
||||
@ -15,6 +15,9 @@
|
||||
{ Read filename handling functions implementation }
|
||||
{$i fina.inc}
|
||||
|
||||
{ Read file utility functions implementation }
|
||||
{$i filutil.inc}
|
||||
|
||||
{ variant error codes }
|
||||
{$i varerror.inc}
|
||||
|
||||
|
||||
@ -41,6 +41,9 @@ type
|
||||
{$DEFINE FPC_FEXPAND_DRIVES} (* Full paths begin with drive specification *)
|
||||
{$DEFINE FPC_FEXPAND_GETENV_PCHAR}
|
||||
|
||||
{ used OS file system APIs use ansistring }
|
||||
{$define SYSUTILS_HAS_ANSISTR_FILEUTIL_IMPL}
|
||||
|
||||
{ Include platform independent implementation part }
|
||||
{$i sysutils.inc}
|
||||
|
||||
@ -61,15 +64,17 @@ const
|
||||
FindResvdMask = $00003737; {Allowed bits in attribute
|
||||
specification for DosFindFirst call.}
|
||||
|
||||
function FileOpen (const FileName: string; Mode: integer): THandle;
|
||||
function FileOpen (const FileName: rawbytestring; Mode: integer): THandle;
|
||||
Var
|
||||
SystemFileName: RawByteString;
|
||||
Handle: THandle;
|
||||
Rc, Action: cardinal;
|
||||
begin
|
||||
SystemFileName:=ToSingleByteFileSystemEncodedFileName(FileName);
|
||||
(* DenyNone if sharing not specified. *)
|
||||
if (Mode and 112 = 0) or (Mode and 112 > 64) then
|
||||
Mode := Mode or 64;
|
||||
Rc:=Sys_DosOpenL(PChar (FileName), Handle, Action, 0, 0, 1, Mode, nil);
|
||||
Rc:=Sys_DosOpenL(PChar (SystemFileName), Handle, Action, 0, 0, 1, Mode, nil);
|
||||
If Rc=0 then
|
||||
FileOpen:=Handle
|
||||
else
|
||||
@ -77,28 +82,30 @@ begin
|
||||
//should return feInvalidHandle(=-1) if fail, other negative returned value are no more errors
|
||||
end;
|
||||
|
||||
function FileCreate (const FileName: string): THandle;
|
||||
function FileCreate (const FileName: RawByteString): THandle;
|
||||
begin
|
||||
FileCreate := FileCreate (FileName, doDenyRW, 777); (* Sharing to DenyAll *)
|
||||
end;
|
||||
|
||||
function FileCreate (const FileName: string; Rights: integer): THandle;
|
||||
function FileCreate (const FileName: RawByteString; Rights: integer): THandle;
|
||||
begin
|
||||
FileCreate := FileCreate (FileName, doDenyRW, Rights);
|
||||
(* Sharing to DenyAll *)
|
||||
end;
|
||||
|
||||
function FileCreate (const FileName: string; ShareMode: integer;
|
||||
function FileCreate (const FileName: RawByteString; ShareMode: integer;
|
||||
Rights: integer): THandle;
|
||||
var
|
||||
SystemFileName: RawByteString;
|
||||
Handle: THandle;
|
||||
RC, Action: cardinal;
|
||||
begin
|
||||
SystemFileName:=ToSingleByteFileSystemEncodedFileName(FileName);
|
||||
ShareMode := ShareMode and 112;
|
||||
(* Sharing to DenyAll as default in case of values not allowed by OS/2. *)
|
||||
if (ShareMode = 0) or (ShareMode > 64) then
|
||||
ShareMode := doDenyRW;
|
||||
RC := Sys_DosOpenL (PChar (FileName), Handle, Action, 0, 0, $12,
|
||||
RC := Sys_DosOpenL (PChar (SystemFileName), Handle, Action, 0, 0, $12,
|
||||
faCreate or ofReadWrite or ShareMode, nil);
|
||||
if RC = 0 then
|
||||
FileCreate := Handle
|
||||
|
||||
@ -264,6 +264,9 @@ procedure UnhookSignal(RtlSigNum: Integer; OnlyIfHooked: Boolean = True);
|
||||
{$DEFINE FPC_FEXPAND_TILDE} { Tilde is expanded to home }
|
||||
{$DEFINE FPC_FEXPAND_GETENVPCHAR} { GetEnv result is a PChar }
|
||||
|
||||
{ used OS file system APIs use ansistring }
|
||||
{$define SYSUTILS_HAS_ANSISTR_FILEUTIL_IMPL}
|
||||
|
||||
{ Include platform independent implementation part }
|
||||
{$i sysutils.inc}
|
||||
|
||||
@ -424,9 +427,10 @@ begin
|
||||
end;
|
||||
|
||||
|
||||
Function FileOpen (Const FileName : string; Mode : Integer) : Longint;
|
||||
Function FileOpen (Const FileName : RawbyteString; Mode : Integer) : Longint;
|
||||
|
||||
Var
|
||||
SystemFileName: RawByteString;
|
||||
LinuxFlags : longint;
|
||||
begin
|
||||
LinuxFlags:=0;
|
||||
@ -436,32 +440,39 @@ begin
|
||||
fmOpenReadWrite : LinuxFlags:=LinuxFlags or O_RdWr;
|
||||
end;
|
||||
|
||||
SystemFileName:=ToSingleByteFileSystemEncodedFileName(FileName);
|
||||
repeat
|
||||
FileOpen:=fpOpen (pointer(FileName),LinuxFlags);
|
||||
FileOpen:=fpOpen (pointer(SystemFileName),LinuxFlags);
|
||||
until (FileOpen<>-1) or (fpgeterrno<>ESysEINTR);
|
||||
|
||||
FileOpen:=DoFileLocking(FileOpen, Mode);
|
||||
end;
|
||||
|
||||
|
||||
Function FileCreate (Const FileName : String) : Longint;
|
||||
Function FileCreate (Const FileName : RawByteString) : Longint;
|
||||
|
||||
Var
|
||||
SystemFileName: RawByteString;
|
||||
begin
|
||||
SystemFileName:=ToSingleByteFileSystemEncodedFileName(FileName);
|
||||
repeat
|
||||
FileCreate:=fpOpen(pointer(FileName),O_RdWr or O_Creat or O_Trunc);
|
||||
FileCreate:=fpOpen(pointer(SystemFileName),O_RdWr or O_Creat or O_Trunc);
|
||||
until (FileCreate<>-1) or (fpgeterrno<>ESysEINTR);
|
||||
end;
|
||||
|
||||
|
||||
Function FileCreate (Const FileName : String;Rights : Longint) : Longint;
|
||||
Function FileCreate (Const FileName : RawByteString;Rights : Longint) : Longint;
|
||||
|
||||
Var
|
||||
SystemFileName: RawByteString;
|
||||
begin
|
||||
SystemFileName:=ToSingleByteFileSystemEncodedFileName(FileName);
|
||||
repeat
|
||||
FileCreate:=fpOpen(pointer(FileName),O_RdWr or O_Creat or O_Trunc,Rights);
|
||||
FileCreate:=fpOpen(pointer(SystemFileName),O_RdWr or O_Creat or O_Trunc,Rights);
|
||||
until (FileCreate<>-1) or (fpgeterrno<>ESysEINTR);
|
||||
end;
|
||||
|
||||
Function FileCreate (Const FileName : String; ShareMode : Longint; Rights:LongInt ) : Longint;
|
||||
Function FileCreate (Const FileName : RawByteString; ShareMode : Longint; Rights:LongInt ) : Longint;
|
||||
|
||||
begin
|
||||
Result:=FileCreate( FileName, Rights );
|
||||
|
||||
@ -40,6 +40,9 @@ implementation
|
||||
{$DEFINE FPC_FEXPAND_UNC} (* UNC paths are supported *)
|
||||
{$DEFINE FPC_FEXPAND_DRIVES} (* Full paths begin with drive specification *)
|
||||
|
||||
{ used OS file system APIs use ansistring }
|
||||
{$define SYSUTILS_HAS_ANSISTR_FILEUTIL_IMPL}
|
||||
|
||||
{ Include platform independent implementation part }
|
||||
{$i sysutils.inc}
|
||||
|
||||
@ -115,32 +118,36 @@ begin
|
||||
end;
|
||||
|
||||
|
||||
Function FileOpen (Const FileName : string; Mode : Integer) : Longint;
|
||||
var
|
||||
Function FileOpen (Const FileName : rawbytestring; Mode : Integer) : Longint;
|
||||
Var
|
||||
SystemFileName: RawByteString;
|
||||
e: integer;
|
||||
Begin
|
||||
e := OpenFile(FileName, result, Mode, faOpen);
|
||||
SystemFileName:=ToSingleByteFileSystemEncodedFileName(FileName);
|
||||
e := OpenFile(SystemFileName, result, Mode, faOpen);
|
||||
if e <> 0 then
|
||||
result := -1;
|
||||
end;
|
||||
|
||||
|
||||
Function FileCreate (Const FileName : String) : Longint;
|
||||
Function FileCreate (Const FileName : RawByteString) : Longint;
|
||||
var
|
||||
SystemFileName: RawByteString;
|
||||
e: integer;
|
||||
begin
|
||||
e := OpenFile(FileName, result, ofReadWrite, faCreate or faOpenReplace);
|
||||
SystemFileName := ToSingleByteFileSystemEncodedFileName(FileName);
|
||||
e := OpenFile(SystemFileName, result, ofReadWrite, faCreate or faOpenReplace);
|
||||
if e <> 0 then
|
||||
result := -1;
|
||||
end;
|
||||
|
||||
|
||||
Function FileCreate (Const FileName : String; Rights:longint) : Longint;
|
||||
Function FileCreate (Const FileName : RawByteString; Rights:longint) : Longint;
|
||||
begin
|
||||
FileCreate:=FileCreate(FileName);
|
||||
end;
|
||||
|
||||
Function FileCreate (Const FileName : String; ShareMode:longint; Rights: Longint) : Longint;
|
||||
Function FileCreate (Const FileName : RawByteString; ShareMode:longint; Rights: Longint) : Longint;
|
||||
begin
|
||||
FileCreate:=FileCreate(FileName);
|
||||
end;
|
||||
|
||||
@ -45,7 +45,7 @@ uses
|
||||
{****************************************************************************
|
||||
File Functions
|
||||
****************************************************************************}
|
||||
function FileOpen(const FileName: string; Mode: Integer): LongInt;
|
||||
function FileOpen(const FileName: rawbytestring; Mode: Integer): LongInt;
|
||||
begin
|
||||
result := -1;
|
||||
end;
|
||||
@ -63,18 +63,18 @@ begin
|
||||
end;
|
||||
|
||||
|
||||
function FileCreate(const FileName: string) : LongInt;
|
||||
function FileCreate(const FileName: RawByteString) : LongInt;
|
||||
begin
|
||||
result := -1;
|
||||
end;
|
||||
|
||||
|
||||
function FileCreate(const FileName: string; Rights: integer): LongInt;
|
||||
function FileCreate(const FileName: RawByteString; Rights: integer): LongInt;
|
||||
begin
|
||||
result := -1;
|
||||
end;
|
||||
|
||||
function FileCreate(const FileName: string; ShareMode: integer; Rights: integer): LongInt;
|
||||
function FileCreate(const FileName: RawByteString; ShareMode: integer; Rights: integer): LongInt;
|
||||
begin
|
||||
result := -1;
|
||||
end;
|
||||
|
||||
@ -151,6 +151,8 @@ function GetFileVersion(const AFileName:string):Cardinal;
|
||||
{$DEFINE FPC_FEXPAND_UNC} (* UNC paths are supported *)
|
||||
{$DEFINE FPC_FEXPAND_DRIVES} (* Full paths begin with drive specification *)
|
||||
|
||||
{ used OS file system APIs use ansistring }
|
||||
{$define SYSUTILS_HAS_ANSISTR_FILEUTIL_IMPL}
|
||||
|
||||
function ConvertEraYearString(Count ,Year,Month,Day : integer) : string; forward;
|
||||
function ConvertEraString(Count ,Year,Month,Day : integer) : string; forward;
|
||||
@ -225,27 +227,33 @@ const
|
||||
FILE_SHARE_WRITE,
|
||||
FILE_SHARE_READ or FILE_SHARE_WRITE);
|
||||
|
||||
Function FileOpen (Const FileName : string; Mode : Integer) : THandle;
|
||||
Function FileOpen (Const FileName : rawbytestring; Mode : Integer) : THandle;
|
||||
Var
|
||||
SystemFileName: RawByteString;
|
||||
begin
|
||||
result := CreateFile(PChar(FileName), dword(AccessMode[Mode and 3]),
|
||||
SystemFileName := ToSingleByteFileSystemEncodedFileName(FileName);
|
||||
result := CreateFile(PChar(SystemFileName), dword(AccessMode[Mode and 3]),
|
||||
dword(ShareModes[(Mode and $F0) shr 4]), nil, OPEN_EXISTING,
|
||||
FILE_ATTRIBUTE_NORMAL, 0);
|
||||
//if fail api return feInvalidHandle (INVALIDE_HANDLE=feInvalidHandle=-1)
|
||||
end;
|
||||
|
||||
Function FileCreate (Const FileName : String) : THandle;
|
||||
Function FileCreate (Const FileName : RawByteString) : THandle;
|
||||
begin
|
||||
FileCreate:=FileCreate(FileName, fmShareExclusive, 0);
|
||||
end;
|
||||
|
||||
Function FileCreate (Const FileName : String; Rights:longint) : THandle;
|
||||
Function FileCreate (Const FileName : RawByteString; Rights:longint) : THandle;
|
||||
begin
|
||||
FileCreate:=FileCreate(FileName, fmShareExclusive, Rights);
|
||||
end;
|
||||
|
||||
Function FileCreate (Const FileName : String; ShareMode : Integer; Rights : Integer) : THandle;
|
||||
Function FileCreate (Const FileName : RawByteString; ShareMode : Integer; Rights : Integer) : THandle;
|
||||
Var
|
||||
SystemFileName: RawByteString;
|
||||
begin
|
||||
Result := CreateFile(PChar(FileName), GENERIC_READ or GENERIC_WRITE,
|
||||
SystemFileName := ToSingleByteFileSystemEncodedFileName(FileName);
|
||||
Result := CreateFile(PChar(SystemFileName), GENERIC_READ or GENERIC_WRITE,
|
||||
dword(ShareModes[(ShareMode and $F0) shr 4]), nil, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, 0);
|
||||
end;
|
||||
|
||||
|
||||
@ -62,6 +62,9 @@ implementation
|
||||
{$DEFINE FPC_FEXPAND_NO_DEFAULT_PATHS}
|
||||
{$DEFINE FPC_FEXPAND_UNC} (* UNC paths are supported *)
|
||||
|
||||
{ used OS file system APIs use unicodestring }
|
||||
{$DEFINE SYSUTILS_HAS_UNICODESTR_FILEUTIL_IMPL}
|
||||
|
||||
{ Include platform independent implementation part }
|
||||
{$i sysutils.inc}
|
||||
|
||||
@ -130,7 +133,7 @@ end;
|
||||
File Functions
|
||||
****************************************************************************}
|
||||
|
||||
Function FileOpen (Const FileName : string; Mode : Integer) : THandle;
|
||||
Function FileOpen (Const FileName : unicodestring; Mode : Integer) : THandle;
|
||||
const
|
||||
AccessMode: array[0..2] of Cardinal = (
|
||||
GENERIC_READ,
|
||||
@ -142,36 +145,28 @@ const
|
||||
FILE_SHARE_READ,
|
||||
FILE_SHARE_WRITE,
|
||||
FILE_SHARE_READ or FILE_SHARE_WRITE);
|
||||
var
|
||||
fn: PWideChar;
|
||||
begin
|
||||
fn:=StringToPWideChar(FileName);
|
||||
result := CreateFile(fn, dword(AccessMode[Mode and 3]),
|
||||
result := CreateFile(PWideChar(FileName), dword(AccessMode[Mode and 3]),
|
||||
dword(ShareMode[(Mode and $F0) shr 4]), nil, OPEN_EXISTING,
|
||||
FILE_ATTRIBUTE_NORMAL, 0);
|
||||
//if fail api return feInvalidHandle (INVALIDE_HANDLE=feInvalidHandle=-1)
|
||||
FreeMem(fn);
|
||||
end;
|
||||
|
||||
|
||||
Function FileCreate (Const FileName : String) : THandle;
|
||||
var
|
||||
fn: PWideChar;
|
||||
Function FileCreate (Const FileName : UnicodeString) : THandle;
|
||||
begin
|
||||
fn:=StringToPWideChar(FileName);
|
||||
Result := CreateFile(fn, GENERIC_READ or GENERIC_WRITE,
|
||||
Result := CreateFile(PWideChar(FileName), GENERIC_READ or GENERIC_WRITE,
|
||||
0, nil, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, 0);
|
||||
FreeMem(fn);
|
||||
end;
|
||||
|
||||
|
||||
Function FileCreate (Const FileName : String; Rights:longint) : THandle;
|
||||
Function FileCreate (Const FileName : UnicodeString; Rights:longint) : THandle;
|
||||
begin
|
||||
FileCreate:=FileCreate(FileName);
|
||||
end;
|
||||
|
||||
|
||||
Function FileCreate (Const FileName : String; ShareMode:longint; Rights:longint) : THandle;
|
||||
Function FileCreate (Const FileName : UnicodeString; ShareMode:longint; Rights:longint) : THandle;
|
||||
begin
|
||||
FileCreate:=FileCreate(FileName);
|
||||
end;
|
||||
|
||||
100
tests/test/units/sysutils/tunifile.pp
Normal file
100
tests/test/units/sysutils/tunifile.pp
Normal file
@ -0,0 +1,100 @@
|
||||
{$codepage utf8}
|
||||
{$mode objfpc}{$h+}
|
||||
|
||||
uses
|
||||
{$ifdef unix}
|
||||
cwstring,
|
||||
{$endif}
|
||||
sysutils;
|
||||
|
||||
type
|
||||
tcpstr866 = type ansistring(866);
|
||||
|
||||
procedure error(const s: string);
|
||||
begin
|
||||
writeln('Error: ',s);
|
||||
halt(1);
|
||||
end;
|
||||
|
||||
|
||||
procedure warn(const s: string);
|
||||
begin
|
||||
writeln('Warning: cannot test '+s+' scenario fully because not all characters are supported by DefaultFileSystemCodePage');
|
||||
end;
|
||||
|
||||
|
||||
procedure testsinglebyte;
|
||||
var
|
||||
u: utf8string;
|
||||
c: tcpstr866;
|
||||
f: THandle;
|
||||
r: rawbytestring;
|
||||
begin
|
||||
{ can't set code page of an empty string }
|
||||
r:=' ';
|
||||
setcodepage(r,DefaultFileSystemCodePage,false);
|
||||
u:='‹≈©◊';
|
||||
r:=u;
|
||||
if r=u then
|
||||
begin
|
||||
f:=FileCreate(u,fmShareDenyNone,(6 shl 6) or (4 shl 3) or 4);
|
||||
if f=-1 then
|
||||
Error('Creating utf8string');
|
||||
FileClose(f);
|
||||
end
|
||||
else
|
||||
warn('utf8string');
|
||||
c:='Русская';
|
||||
setcodepage(rawbytestring(c),866);
|
||||
r:=c;
|
||||
setcodepage(r,DefaultFileSystemCodePage);
|
||||
if r=c then
|
||||
begin
|
||||
f:=FileCreate(c,fmShareDenyNone,(6 shl 6) or (4 shl 3) or 4);
|
||||
if f=-1 then
|
||||
Error('Creating tcpstr866');
|
||||
FileClose(f);
|
||||
end
|
||||
else
|
||||
warn('tcpstr866');
|
||||
end;
|
||||
|
||||
|
||||
procedure testtwobyte;
|
||||
var
|
||||
u: unicodestring;
|
||||
f: THandle;
|
||||
r: rawbytestring;
|
||||
begin
|
||||
{ can't set code page of an empty string }
|
||||
r:=' ';
|
||||
setcodepage(r,DefaultFileSystemCodePage,false);
|
||||
u:='‹≈©◊';
|
||||
r:=u;
|
||||
if r=u then
|
||||
begin
|
||||
f:=FileCreate(u,fmShareDenyNone,(6 shl 6) or (4 shl 3) or 4);
|
||||
if f=-1 then
|
||||
Error('Creating unicodestring 1');
|
||||
FileClose(f);
|
||||
end
|
||||
else
|
||||
warn('random unicodestring');
|
||||
u:='Русская';
|
||||
r:=u;
|
||||
if r=u then
|
||||
begin
|
||||
f:=FileCreate(u,fmShareDenyNone,(6 shl 6) or (4 shl 3) or 4);
|
||||
if f=-1 then
|
||||
Error('Creating unicodestring 2');
|
||||
FileClose(f);
|
||||
end
|
||||
else
|
||||
warn('cp866 unicodestring');
|
||||
end;
|
||||
|
||||
|
||||
begin
|
||||
testsinglebyte;
|
||||
testtwobyte;
|
||||
end.
|
||||
Loading…
Reference in New Issue
Block a user