dos.inc 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178
  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. var
  86. LastDosExitCode: word;
  87. Procedure Exec(const path: pathstr; const comline: comstr);
  88. var p:string;
  89. argv:ppchar;
  90. argc:longint;
  91. th:thread_id;
  92. status : status_t;
  93. begin
  94. LastDosExitCode:=0;
  95. DosError:= 0;
  96. p:=path+' '+comline;
  97. argv:=StringToPPChar(p,argc);
  98. th:=load_image(argc,argv,system.envp);
  99. if th<0 then begin
  100. DosError:=5; { lets emulate an error }
  101. exit;
  102. end;
  103. wait_for_thread(th,status);
  104. LastDosExitCode:=status and $FF; { only keep the lower 8-bits }
  105. end;
  106. Function DosExitCode: Word;
  107. Begin
  108. DosExitCode:=LastDosExitCode;
  109. End;
  110. function GetTimeZoneString : string;
  111. begin
  112. GetTimeZoneString:=getenv('TZ');
  113. end;
  114. function GetTimezoneFile:string;
  115. var
  116. f,len : longint;
  117. s : string;
  118. info : stat;
  119. buffer : array[0..MAXPATHLEN+1] of char;
  120. begin
  121. GetTimezoneFile:='';
  122. if kget_tzfilename(pchar(@buffer))=0 then
  123. begin
  124. GetTimeZoneFile := strpas(pchar(@buffer));
  125. end;
  126. end;
  127. {
  128. $Log$
  129. Revision 1.2 2003-01-08 22:32:28 marco
  130. * Small fixes and quick merge with 1.0.x. At least the compiler builds now,
  131. but it could crash hard, since there are lots of unimplemented funcs.
  132. Revision 1.1.2.6 2002/05/01 14:08:53 carl
  133. + TZ is now taken from GetTimezoneSitrng instead of getenv
  134. Revision 1.1.2.5 2001/12/17 02:14:50 carl
  135. * bugfix for more than default drives
  136. Revision 1.1.2.4 2001/08/15 01:01:29 carl
  137. + added missing file include
  138. Revision 1.1.2.3 2001/08/13 05:57:01 carl
  139. * renamed routine names (names are same as documented in the Be Book)
  140. Revision 1.1.2.2 2001/08/12 15:14:54 carl
  141. + GetTimeZoneFileName()
  142. Revision 1.1.2.1 2001/08/04 05:26:08 carl
  143. + Exec() works
  144. + DiskFree() / DiskSize() works
  145. }