dos_beos.inc 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  1. {
  2. This file is part of the Free Pascal run time library.
  3. Copyright (c) 2001 by members of the Free Pascal
  4. development team
  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 syscall.inc}
  13. {$i beos.inc}
  14. {$define DOS_HAS_EXEC}
  15. {
  16. The Diskfree and Disksize functions need a file on the specified drive, since this
  17. is required for the statfs system call.
  18. These filenames are set in drivestr[0..26], and have been preset to :
  19. 0 - '.' (default drive - hence current dir is ok.)
  20. 1 - '/fd0/.' (floppy drive 1 - should be adapted to local system )
  21. 2 - '/fd1/.' (floppy drive 2 - should be adapted to local system )
  22. 3 - '/' (C: equivalent of dos is the root partition)
  23. 4..26 (can be set by you're own applications)
  24. ! Use AddDisk() to Add new drives !
  25. They both return -1 when a failure occurs.
  26. The drive names are OS specific
  27. }
  28. Const
  29. FixDriveStr : array[0..3] of pchar=(
  30. '.', { the current directory }
  31. '/disk 0/.', { mounted floppy 1 }
  32. '/disk 1/.', { mounted floppy 2 }
  33. '/boot/.' { the boot up disk }
  34. );
  35. Function DosVersion:Word;
  36. Begin
  37. DosVersion := 0;
  38. End;
  39. Function DiskFree(Drive: Byte): int64;
  40. var
  41. info: fs_info;
  42. device : dev_t;
  43. Begin
  44. device := 0;
  45. DiskFree := -1;
  46. if (Drive < 4) and (FixDriveStr[Drive]<>nil) then
  47. begin
  48. device:= dev_for_path(FixDriveStr[Drive]);
  49. end
  50. else
  51. if (Drive>4) and (Drive<=MAX_DRIVES) and (drivestr[Drive]<>nil) then
  52. device := dev_for_path(driveStr[drive])
  53. else
  54. begin
  55. exit;
  56. end;
  57. if fs_Stat_dev(device,info)=0 then
  58. DiskFree := int64(info.block_size)*int64(info.free_blocks);
  59. End;
  60. Function DiskSize(Drive: Byte): int64;
  61. var
  62. info: fs_info;
  63. device : dev_t;
  64. Begin
  65. device := 0;
  66. DiskSize:= -1;
  67. if (Drive < 4) and (FixDriveStr[Drive]<>nil) then
  68. begin
  69. device:= dev_for_path(FixDriveStr[Drive]);
  70. end
  71. else
  72. if (Drive>4) and (Drive<=MAX_DRIVES) and (drivestr[Drive]<>nil) then
  73. device := dev_for_path(driveStr[drive])
  74. else
  75. begin
  76. exit;
  77. end;
  78. if fs_Stat_dev(device,info)=0 then
  79. DiskSize := int64(info.block_size)*int64(info.total_blocks);
  80. End;
  81. {******************************************************************************
  82. --- Exec ---
  83. ******************************************************************************}
  84. Procedure Exec(const path: pathstr; const comline: comstr);
  85. var p:string;
  86. argv:ppchar;
  87. argc:longint;
  88. th:thread_id;
  89. status : status_t;
  90. begin
  91. LastDosExitCode:=0;
  92. DosError:= 0;
  93. p:=path+' '+comline;
  94. argv:=StringToPPChar(p,argc);
  95. th:=load_image(argc,argv,system.envp);
  96. if th<0 then begin
  97. DosError:=5; { lets emulate an error }
  98. exit;
  99. end;
  100. wait_for_thread(th,status);
  101. LastDosExitCode:=status and $FF; { only keep the lower 8-bits }
  102. end;
  103. function GetTimeZoneString : string;
  104. begin
  105. GetTimeZoneString:=getenv('TZ');
  106. end;
  107. function GetTimezoneFile:string;
  108. var
  109. f,len : longint;
  110. s : string;
  111. info : stat;
  112. buffer : array[0..MAXPATHLEN+1] of char;
  113. begin
  114. GetTimezoneFile:='';
  115. if kget_tzfilename(pchar(@buffer))=0 then
  116. begin
  117. GetTimeZoneFile := strpas(pchar(@buffer));
  118. end;
  119. end;