Next: , Previous: CRT, Up: GPC Units

6.15.2 BP compatibility: Dos

The following listing contains the interface of the Dos unit.

This is a portable implementation of most routines from BP's Dos unit. A few routines that are Dos – or even IA32 real mode – specific, are only available if __BP_UNPORTABLE_ROUTINES__ is defined, BP Incompatibilities.

The same functionality and much more is available in the Run Time System, Run Time System. In some cases, the RTS routines have the same interface as the routines in this unit (e.g. GetEnv, FSplit, FExpand, FSearch), in other cases, they have different names and/or easier and less limiting interfaces (e.g. ReadDir etc. vs. FindFirst etc.), and are often more efficient.

Therefore, using this unit is not recommended in newly written programs.

     { Portable BP compatible Dos unit
       This unit supports most of the routines and declarations of BP's
       Dos unit.
       - The procedures Keep, GetIntVec, SetIntVec are not supported
         since they make only sense for Dos real-mode programs (and GPC
         compiled programs do not run in real-mode, even on IA32 under
         Dos). The procedures Intr and MsDos are only supported under
         DJGPP if __BP_UNPORTABLE_ROUTINES__ is defined (with the
         -D__BP_UNPORTABLE_ROUTINES__ option). A few other routines are
         also only supported with this define, but on all platforms (but
         they are crude hacks, that's why they are not supported without
         this define).
       - The internal structure of file variables (FileRec and TextRec)
         is different in GPC. However, as far as TFDDs are concerned,
         there are other ways to achieve the same in GPC, see the GPC
       Copyright (C) 1998-2005 Free Software Foundation, Inc.
       Authors: Frank Heckenbach <>
                Prof. Abimbola A. Olowofoyeku <>
       This file is part of GNU Pascal.
       GNU Pascal is free software; you can redistribute it and/or modify
       it under the terms of the GNU General Public License as published
       by the Free Software Foundation; either version 2, or (at your
       option) any later version.
       GNU Pascal is distributed in the hope that it will be useful, but
       WITHOUT ANY WARRANTY; without even the implied warranty of
       General Public License for more details.
       You should have received a copy of the GNU General Public License
       along with GNU Pascal; see the file COPYING. If not, write to the
       Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA
       02111-1307, USA.
       As a special exception, if you link this file with files compiled
       with a GNU compiler to produce an executable, this does not cause
       the resulting executable to be covered by the GNU General Public
       License. This exception does not however invalidate any other
       reasons why the executable file might be covered by the GNU
       General Public License. }
     {$gnu-pascal,I-,maximum-field-alignment 0}
     {$if __GPC_RELEASE__ < 20030412}
     {$error This unit requires GPC release 20030412 or newer.}
     module Dos;
     { GPC and this unit use AnyFile for different meanings. Export
       renaming helps us to avoid a conflict here. If you use both units,
       the meaning of the latter one will be effective, but you always
       get the built-in meaning by using GPC_AnyFile. }
     export Dos = all (DosAnyFile => AnyFile, FSearch, FExpand, FSplit,
     import GPC (MaxLongInt => GPC_Orig_MaxLongInt); System;
       GPC_AnyFile = AnyFile;
       Byte8 = Cardinal attribute (Size = 8);
       Word16 = Cardinal attribute (Size = 16);
       Word32 = Cardinal attribute (Size = 32);
       TDosAttr = Word;
       { File attribute constants }
       ReadOnly   = $01;
       Hidden     = $02;  { set for dot files except '.' and '..' }
       SysFile    = $04;  { not supported }
       VolumeID   = $08;  { not supported }
       Directory  = $10;
       Archive    = $20;  { means: not executable }
       DosAnyFile = $3f;
       { Flag bit masks -- only used by the unportable Dos routines }
       FCarry     = 1;
       FParity    = 4;
       FAuxiliary = $10;
       FZero      = $40;
       FSign      = $80;
       FOverflow  = $800;
       { DosError codes }
       DosError_FileNotFound = 2;
       DosError_PathNotFound = 3;
       DosError_AccessDenied = 5;
       DosError_InvalidMem   = 9;
       DosErorr_InvalidEnv   = 10;
       DosError_NoMoreFiles  = 18;
       DosError_IOError      = 29;
       DosError_ReadFault    = 30;
       { String types. Not used in this unit, but declared for
         compatibility. }
       ComStr  = String [127];  { Command line string }
       PathStr = String [79];   { File pathname string }
       DirStr  = String [67];   { Drive and directory string }
       NameStr = String [8];    { File name string }
       ExtStr  = String [4];    { File extension string }
       TextBuf = array [0 .. 127] of Char;
       { Search record used by FindFirst and FindNext }
       SearchRecFill = packed array [1 .. 21] of Byte8;
       SearchRec = record
         Fill: SearchRecFill;
         Attr: Byte8;
         Size: LongInt;
         Name: {$ifdef __BP_TYPE_SIZES__}
               String [12]
       { Date and time record used by PackTime and UnpackTime }
       DateTime = record
         Year, Month, Day, Hour, Min, Sec: Word
       { 8086 CPU registers -- only used by the unportable Dos routines }
       Registers = record
       case Boolean of
         False: (ax, bx, cx, dx, bp, si, di, ds, es, Flags: Word16);
         True : (al, ah, bl, bh, cl, ch, dl, dh: Byte8)
       { Error status variable }
       DosError: Integer = 0;
     procedure GetDate (var Year, Month, Day, DayOfWeek: Word);
     procedure GetTime (var Hour, Minute, Second, Sec100: Word);
     procedure GetCBreak (var BreakOn: Boolean);
     procedure SetCBreak (BreakOn: Boolean);
     { GetVerify and SetVerify are dummies except for DJGPP (in the
       assumption that any real OS knows by itself when and how to verify
       its disks). }
     procedure GetVerify (var VerifyOn: Boolean);
     procedure SetVerify (VerifyOn: Boolean);
     function  DiskFree (Drive: Byte): LongInt;
     function  DiskSize (Drive: Byte): LongInt;
     procedure GetFAttr (var f: GPC_AnyFile; var Attr: TDosAttr);
     procedure SetFAttr (var f: GPC_AnyFile; Attr: TDosAttr);
     procedure GetFTime (var f: GPC_AnyFile; var MTime: LongInt);
     procedure SetFTime (var f: GPC_AnyFile; MTime: LongInt);
     { FindFirst and FindNext are quite inefficient since they emulate
       all the brain-dead Dos stuff. If at all possible, the standard
       routines OpenDir, ReadDir and CloseDir (in the GPC unit) should be
       used instead. }
     procedure FindFirst (const Path: String; Attr: TDosAttr; var SR:
     procedure FindNext  (var SR: SearchRec);
     procedure FindClose (var SR: SearchRec);
     procedure UnpackTime (p: LongInt; var t: DateTime);
     procedure PackTime (const t: DateTime; var p: LongInt);
     function  EnvCount: Integer;
     function  EnvStr (EnvIndex: Integer): TString;
     procedure SwapVectors;
     { Exec executes a process via Execute, so RestoreTerminal is called
       with the argument True before and False after executing the
       process. }
     procedure Exec (const Path, Params: String);
     function  DosExitCode: Word;
     { Unportable Dos-only routines and declarations }
     {$ifdef __BP_UNPORTABLE_ROUTINES__}
     {$ifdef __GO32__}
     { These are unportable Dos-only declarations and routines, since
       interrupts are Dos and CPU specific (and have no place in a
       high-level program, anyway). }
     procedure Intr (IntNo: Byte; var Regs: Registers);
     procedure MsDos (var Regs: Registers);
     { Though probably all non-Dos systems have versions numbers as well,
       returning them here would usually not do what is expected, e.g.
       testing if certain Dos features are present by comparing the
       version number. Therefore, this routine always returns 7 (i.e.,
       version 7.0) on non-Dos systems, in the assumption that any real
       OS has at least the features of Dos 7. }
     function  DosVersion: Word;
     { Changing the system date and time is a system administration task,
       not allowed to a normal process. On non-Dos systems, these
       routines emulate the changed date/time, but only for GetTime and
       GetDate (not the RTS date/time routines), and only for this
       process, not for child processes or even the parent process or
       system-wide. }
     procedure SetDate (Year, Month, Day: Word);
     procedure SetTime (Hour, Minute, Second, Sec100: Word);