dos.inc 3.6 KB

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