objinc.inc 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. {
  2. $Id$
  3. Copyright (c) 2001 by the Freepascal development team
  4. Objects unit OS specific implementation
  5. This program is free software; you can redistribute it and/or modify
  6. it under the terms of the GNU General Public License as published by
  7. the Free Software Foundation; either version 2 of the License, or
  8. (at your option) any later version.
  9. This program is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. GNU General Public License for more details.
  13. You should have received a copy of the GNU General Public License
  14. along with this program; if not, write to the Free Software
  15. Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  16. ****************************************************************************
  17. }
  18. {$i errno.inc}
  19. {$i osposixh.inc}
  20. {$i osposix.inc}
  21. const
  22. { read/write permission for everyone }
  23. MODE_OPEN = S_IWUSR OR S_IRUSR OR
  24. S_IWGRP OR S_IRGRP OR
  25. S_IWOTH OR S_IROTH;
  26. FUNCTION FileOpen (Var FileName: AsciiZ; Mode: Word): THandle;
  27. Var FileMode : cint;
  28. BEGIN
  29. FileMode:=0;
  30. if Mode=stCreate then
  31. Begin
  32. FileMode:=O_CREAT;
  33. FileMode:=FileMode or O_RDWR;
  34. end
  35. else
  36. Begin
  37. Case (Mode and 3) of
  38. 0 : FileMode:=FileMode or O_RDONLY;
  39. 1 : FileMode:=FileMode or O_WRONLY;
  40. 2 : FileMode:=FileMode or O_RDWR;
  41. end;
  42. end;
  43. FileOpen:=sys_open (pchar(@FileName[0]),FileMode,MODE_OPEN);
  44. if (ErrNo=Sys_EROFS) and ((FileMode and O_RDWR)<>0) then
  45. begin
  46. FileMode:=FileMode and not(O_RDWR);
  47. FileOpen:=sys_open(pchar(@FileName[0]),Filemode,MODE_OPEN);
  48. end;
  49. If FileOpen=-1 then
  50. FileOpen:=0;
  51. DosStreamError:=Errno;
  52. END;
  53. FUNCTION FileRead (Handle: THandle; Var BufferArea; BufferLength: Sw_Word;
  54. Var BytesMoved: Sw_Word): word;
  55. var result : cint;
  56. BEGIN
  57. repeat
  58. result:=Sys_read (Handle,pchar(@BufferArea),BufferLength);
  59. until errno<>Sys_EINTR;
  60. if result = -1 then
  61. BytesMoved := 0
  62. else
  63. BytesMoved := result;
  64. DosStreamError:=Errno;
  65. FileRead:=Errno;
  66. END;
  67. FUNCTION FileWrite (Handle: THandle; Var BufferArea; BufferLength: Sw_Word;
  68. Var BytesMoved: Sw_Word): Word;
  69. var result: cint;
  70. BEGIN
  71. repeat
  72. result:=Sys_Write (Handle,pchar(@BufferArea),BufferLength);
  73. until errno<>Sys_EINTR;
  74. if result = -1 then
  75. BytesMoved := 0
  76. else
  77. BytesMoved := result;
  78. FileWrite:=Errno;
  79. DosStreamError:=Errno;
  80. END;
  81. FUNCTION SetFilePos (Handle: THandle; Pos: LongInt; MoveType: Word;
  82. VAR NewPos: LongInt): Word;
  83. var
  84. whence : cint;
  85. BEGIN
  86. whence := SEEK_SET;
  87. case MoveType of
  88. 1 : whence := SEEK_CUR;
  89. 2 : whence := SEEK_END;
  90. end;
  91. NewPos:=Sys_LSeek (Handle,Pos,whence);
  92. SetFilePos:=Errno;
  93. END;
  94. FUNCTION FileClose (Handle: THandle): Word;
  95. BEGIN
  96. Sys_Close (Handle);
  97. DosStreamError:=Errno;
  98. FileClose := Errno;
  99. END;
  100. FUNCTION SetFileSize (Handle: THandle; FileSize: LongInt): Word;
  101. var
  102. Actual : longint;
  103. BEGIN
  104. SetFilePos(Handle,FileSize,0,Actual);
  105. If (Actual = FileSize) Then
  106. Begin
  107. if (Sys_FTruncate(Handle,Filesize)=-1) then
  108. SetFileSize:=103
  109. else
  110. SetFileSize:=0;
  111. end;
  112. END;
  113. {
  114. $Log$
  115. Revision 1.3 2002-09-07 16:01:26 peter
  116. * old logs removed and tabs fixed
  117. Revision 1.2 2002/08/10 13:42:36 marco
  118. * Fixes Posix dir copied to devel branch
  119. }