dos_beos.inc 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173
  1. {
  2. $Id$
  3. This file is part of the Free Pascal run time library.
  4. Copyright (c) 2001 by members of the Free Pascal
  5. development team
  6. Operating system specific calls for DOS unit (part of POSIX interface)
  7. See the file COPYING.FPC, included in this distribution,
  8. for details about the copyright.
  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.
  12. **********************************************************************}
  13. {$i syscall.inc}
  14. {$i beos.inc}
  15. {$define DOS_HAS_EXEC}
  16. {
  17. The Diskfree and Disksize functions need a file on the specified drive, since this
  18. is required for the statfs system call.
  19. These filenames are set in drivestr[0..26], and have been preset to :
  20. 0 - '.' (default drive - hence current dir is ok.)
  21. 1 - '/fd0/.' (floppy drive 1 - should be adapted to local system )
  22. 2 - '/fd1/.' (floppy drive 2 - should be adapted to local system )
  23. 3 - '/' (C: equivalent of dos is the root partition)
  24. 4..26 (can be set by you're own applications)
  25. ! Use AddDisk() to Add new drives !
  26. They both return -1 when a failure occurs.
  27. The drive names are OS specific
  28. }
  29. Const
  30. FixDriveStr : array[0..3] of pchar=(
  31. '.', { the current directory }
  32. '/disk 0/.', { mounted floppy 1 }
  33. '/disk 1/.', { mounted floppy 2 }
  34. '/boot/.' { the boot up disk }
  35. );
  36. Function DosVersion:Word;
  37. Begin
  38. DosVersion := 0;
  39. End;
  40. Function DiskFree(Drive: Byte): int64;
  41. var
  42. info: fs_info;
  43. device : dev_t;
  44. Begin
  45. device := 0;
  46. DiskFree := -1;
  47. if (Drive < 4) and (FixDriveStr[Drive]<>nil) then
  48. begin
  49. device:= dev_for_path(FixDriveStr[Drive]);
  50. end
  51. else
  52. if (Drive>4) and (Drive<=MAX_DRIVES) and (drivestr[Drive]<>nil) then
  53. device := dev_for_path(driveStr[drive])
  54. else
  55. begin
  56. exit;
  57. end;
  58. if fs_Stat_dev(device,info)=0 then
  59. DiskFree := int64(info.block_size)*int64(info.free_blocks);
  60. End;
  61. Function DiskSize(Drive: Byte): int64;
  62. var
  63. info: fs_info;
  64. device : dev_t;
  65. Begin
  66. device := 0;
  67. DiskSize:= -1;
  68. if (Drive < 4) and (FixDriveStr[Drive]<>nil) then
  69. begin
  70. device:= dev_for_path(FixDriveStr[Drive]);
  71. end
  72. else
  73. if (Drive>4) and (Drive<=MAX_DRIVES) and (drivestr[Drive]<>nil) then
  74. device := dev_for_path(driveStr[drive])
  75. else
  76. begin
  77. exit;
  78. end;
  79. if fs_Stat_dev(device,info)=0 then
  80. DiskSize := int64(info.block_size)*int64(info.total_blocks);
  81. End;
  82. {******************************************************************************
  83. --- Exec ---
  84. ******************************************************************************}
  85. Procedure Exec(const path: pathstr; const comline: comstr);
  86. var p:string;
  87. argv:ppchar;
  88. argc:longint;
  89. th:thread_id;
  90. status : status_t;
  91. begin
  92. LastDosExitCode:=0;
  93. DosError:= 0;
  94. p:=path+' '+comline;
  95. argv:=StringToPPChar(p,argc);
  96. th:=load_image(argc,argv,system.envp);
  97. if th<0 then begin
  98. DosError:=5; { lets emulate an error }
  99. exit;
  100. end;
  101. wait_for_thread(th,status);
  102. LastDosExitCode:=status and $FF; { only keep the lower 8-bits }
  103. end;
  104. function GetTimeZoneString : string;
  105. begin
  106. GetTimeZoneString:=getenv('TZ');
  107. end;
  108. function GetTimezoneFile:string;
  109. var
  110. f,len : longint;
  111. s : string;
  112. info : stat;
  113. buffer : array[0..MAXPATHLEN+1] of char;
  114. begin
  115. GetTimezoneFile:='';
  116. if kget_tzfilename(pchar(@buffer))=0 then
  117. begin
  118. GetTimeZoneFile := strpas(pchar(@buffer));
  119. end;
  120. end;
  121. {
  122. $Log$
  123. Revision 1.1 2004-12-05 16:43:40 hajny
  124. * dos.inc renamed to dos_beos.inc
  125. Revision 1.2 2003/01/08 22:32:28 marco
  126. * Small fixes and quick merge with 1.0.x. At least the compiler builds now,
  127. but it could crash hard, since there are lots of unimplemented funcs.
  128. Revision 1.1.2.6 2002/05/01 14:08:53 carl
  129. + TZ is now taken from GetTimezoneSitrng instead of getenv
  130. Revision 1.1.2.5 2001/12/17 02:14:50 carl
  131. * bugfix for more than default drives
  132. Revision 1.1.2.4 2001/08/15 01:01:29 carl
  133. + added missing file include
  134. Revision 1.1.2.3 2001/08/13 05:57:01 carl
  135. * renamed routine names (names are same as documented in the Be Book)
  136. Revision 1.1.2.2 2001/08/12 15:14:54 carl
  137. + GetTimeZoneFileName()
  138. Revision 1.1.2.1 2001/08/04 05:26:08 carl
  139. + Exec() works
  140. + DiskFree() / DiskSize() works
  141. }