dos.inc 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  1. {
  2. $Id: dos.inc,v 1.1.2.2 2002/05/01 14:09:49 carl Exp $
  3. This file is part of the Free Pascal run time library.
  4. Copyright (c) 2002 by Carl Eric Codere
  5. Operating system specific calls for DOS unit (part of POSIX interface)
  6. See the file COPYING.FPC, included in this distribution,
  7. for details about the copyright.
  8. This program is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  11. **********************************************************************}
  12. {$i qnx.inc}
  13. {
  14. The Diskfree and Disksize functions need a file on the specified drive, since this
  15. is required for the statfs system call.
  16. These filenames are set in drivestr[0..26], and have been preset to :
  17. 0 - '.' (default drive - hence current dir is ok.)
  18. 1 - '/floppy/.' (either direct or contains dir with volume label of mounted device)
  19. 2 - '/cdrom/.' (either direct or contains dir with volume label of mounted device)
  20. 3 - '/' (C: equivalent of dos is the root partition)
  21. 4..26 (can be set by you're own applications)
  22. ! Use AddDisk() to Add new drives !
  23. They both return -1 when a failure occurs.
  24. The drive names are OS specific
  25. }
  26. Const
  27. FixDriveStr : array[0..3] of pchar=(
  28. '.', { the current directory }
  29. '/floppy/.', { manually mounted floppy }
  30. '/cdrom/.', { manually mounted cdrom }
  31. '/' { root partition }
  32. );
  33. Function DosVersion:Word;
  34. Var
  35. Buffer : Array[0..255] of Char;
  36. Tmp2,
  37. TmpStr : String[40];
  38. TmpPos,
  39. SubRel,
  40. Rel : LongInt;
  41. info : ^utsname;
  42. Begin
  43. new(info);
  44. sys_uname(info^);
  45. Move(info^.release,buffer[0],40);
  46. TmpStr:=StrPas(Buffer);
  47. SubRel:=0;
  48. TmpPos:=Pos('.',TmpStr);
  49. if TmpPos>0 then
  50. begin
  51. Tmp2:=Copy(TmpStr,TmpPos+1,40);
  52. Delete(TmpStr,TmpPos,40);
  53. end;
  54. TmpPos:=Pos('.',Tmp2);
  55. if TmpPos>0 then
  56. Delete(Tmp2,TmpPos,40);
  57. Val(TmpStr,Rel);
  58. Val(Tmp2,SubRel);
  59. DosVersion:=Rel+(SubRel shl 8);
  60. dispose(info);
  61. End;
  62. Function DiskFree(Drive: Byte): int64;
  63. var
  64. info : statvfs_t;
  65. Begin
  66. DiskFree := -1;
  67. if (Drive < 4) and (FixDriveStr[Drive]<>nil) then
  68. begin
  69. if sys_statvfs(FixDriveStr[Drive],info)=0 then
  70. DiskFree := int64(info.f_frsize)*int64(info.f_bavail);
  71. end
  72. else
  73. if (Drive>4) and (Drive<=MAX_DRIVES) and (drivestr[Drive]<>nil) then
  74. begin
  75. if sys_statvfs(DriveStr[Drive],info)=0 then
  76. DiskFree := int64(info.f_frsize)*int64(info.f_bavail);
  77. end
  78. else
  79. begin
  80. exit;
  81. end;
  82. End;
  83. Function DiskSize(Drive: Byte): int64;
  84. var
  85. info : statvfs_t;
  86. Begin
  87. DiskSize:= -1;
  88. if (Drive < 4) and (FixDriveStr[Drive]<>nil) then
  89. begin
  90. if sys_statvfs(FixDriveStr[Drive],info)=0 then
  91. DiskSize := int64(info.f_frsize)*int64(info.f_blocks);
  92. end
  93. else
  94. if (Drive>4) and (Drive<=MAX_DRIVES) and (drivestr[Drive]<>nil) then
  95. begin
  96. if sys_statvfs(DriveStr[Drive],info)=0 then
  97. DiskSize := int64(info.f_frsize)*int64(info.f_blocks);
  98. end
  99. else
  100. begin
  101. exit;
  102. end;
  103. End;
  104. { QNX stores its timezone information, in POSIX format }
  105. { in the /etc/TIMEZONE file. }
  106. function GetTimezoneString: string;
  107. var
  108. s: string;
  109. T: text;
  110. begin
  111. GetTimeZoneString:='';
  112. { first try 'TZ' }
  113. s := GetEnv('TZ');
  114. if s<>'' then
  115. begin
  116. GetTimeZoneString:=s;
  117. exit;
  118. end;
  119. { otherwise try to open the TIMEZONE file }
  120. {$IFOPT I+}
  121. {$DEFINE IOCHECK_ON}
  122. {$ENDIF}
  123. {$I-}
  124. Assign(T, '/etc/TIMEZONE');
  125. Reset(T);
  126. If IOResult <> 0 then
  127. exit;
  128. {$IFDEF IOCHECK_ON}
  129. {$I+}
  130. {$ENDIF}
  131. {$UNDEF IOCHECK_ON}
  132. ReadLn(T,s);
  133. Close(T);
  134. GetTimeZoneString:=s;
  135. end;
  136. { QNX does not use timezone files }
  137. function GetTimezoneFile:string;
  138. begin
  139. GetTimezoneFile:='';
  140. end;
  141. {
  142. $Log: dos.inc,v $
  143. Revision 1.1.2.2 2002/05/01 14:09:49 carl
  144. + TZ is now taken from GetTimezoneSitrng instead of getenv
  145. Revision 1.1.2.1 2001/12/20 02:55:00 carl
  146. + QNX versions (still untested)
  147. }