summaryrefslogtreecommitdiff
path: root/fpcsrc/rtl/qnx/dos.inc
blob: f37239e89814f7e41d87778540cb00eca806f4cc (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
{
    $Id: dos.inc,v 1.1.2.2 2002/05/01 14:09:49 carl Exp $
    This file is part of the Free Pascal run time library.
    Copyright (c) 2002 by Carl Eric Codere

    Operating system specific calls for DOS unit (part of POSIX interface)

    See the file COPYING.FPC, included in this distribution,
    for details about the copyright.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

 **********************************************************************}

{$i qnx.inc}


{
  The Diskfree and Disksize functions need a file on the specified drive, since this
  is required for the statfs system call.
  These filenames are set in drivestr[0..26], and have been preset to :
   0 - '.'      (default drive - hence current dir is ok.)
   1 - '/floppy/.'  (either direct or contains dir with volume label of mounted device)
   2 - '/cdrom/.'   (either direct or contains dir with volume label of mounted device)
   3 - '/'       (C: equivalent of dos is the root partition)
   4..26          (can be set by you're own applications)
  ! Use AddDisk() to Add new drives !
  They both return -1 when a failure occurs.
  The drive names are OS specific
}
Const
  FixDriveStr : array[0..3] of pchar=(
    '.',            { the current directory    }
    '/floppy/.',    { manually mounted floppy  }
    '/cdrom/.',     { manually mounted cdrom   }
    '/'             { root partition           }
    );



Function DosVersion:Word;
Var
  Buffer : Array[0..255] of Char;
  Tmp2,
  TmpStr : String[40];
  TmpPos,
  SubRel,
  Rel    : LongInt;
  info   : ^utsname;
Begin
  new(info);
  sys_uname(info^);
  Move(info^.release,buffer[0],40);
  TmpStr:=StrPas(Buffer);
  SubRel:=0;
  TmpPos:=Pos('.',TmpStr);
  if TmpPos>0 then
   begin
     Tmp2:=Copy(TmpStr,TmpPos+1,40);
     Delete(TmpStr,TmpPos,40);
   end;
  TmpPos:=Pos('.',Tmp2);
  if TmpPos>0 then
   Delete(Tmp2,TmpPos,40);
  Val(TmpStr,Rel);
  Val(Tmp2,SubRel);
  DosVersion:=Rel+(SubRel shl 8);
  dispose(info);
End;

Function DiskFree(Drive: Byte): int64;
var
  info : statvfs_t;
Begin
  DiskFree := -1;
  if (Drive < 4) and (FixDriveStr[Drive]<>nil) then
    begin
     if sys_statvfs(FixDriveStr[Drive],info)=0 then
        DiskFree := int64(info.f_frsize)*int64(info.f_bavail);
    end
  else
  if (Drive>4) and (Drive<=MAX_DRIVES) and (drivestr[Drive]<>nil) then
    begin
     if sys_statvfs(DriveStr[Drive],info)=0 then
        DiskFree := int64(info.f_frsize)*int64(info.f_bavail);
    end
  else
    begin
      exit;
    end;
End;



Function DiskSize(Drive: Byte): int64;
var
  info : statvfs_t;
Begin
  DiskSize:= -1;
  if (Drive < 4) and (FixDriveStr[Drive]<>nil) then
    begin
     if sys_statvfs(FixDriveStr[Drive],info)=0 then
        DiskSize := int64(info.f_frsize)*int64(info.f_blocks);
    end
  else
  if (Drive>4) and (Drive<=MAX_DRIVES) and (drivestr[Drive]<>nil) then
    begin
     if sys_statvfs(DriveStr[Drive],info)=0 then
        DiskSize := int64(info.f_frsize)*int64(info.f_blocks);
    end
  else
    begin
      exit;
    end;
End;

{ QNX stores its timezone information, in POSIX format }
{ in the /etc/TIMEZONE file.                           }
function GetTimezoneString: string;
var
 s: string;
 T: text;
begin
 GetTimeZoneString:=''; 
 { first try 'TZ' }
 s := GetEnv('TZ');
 if s<>'' then
  begin
   GetTimeZoneString:=s;   
   exit;
  end;
{ otherwise try to open the TIMEZONE file }
{$IFOPT I+}
{$DEFINE IOCHECK_ON}
{$ENDIF}
{$I-}
 Assign(T, '/etc/TIMEZONE');
 Reset(T);
 If IOResult <> 0 then
  exit;
{$IFDEF IOCHECK_ON}
{$I+}
{$ENDIF}
{$UNDEF IOCHECK_ON}
 ReadLn(T,s);
 Close(T);
 GetTimeZoneString:=s;
end;

{ QNX does not use timezone files }  
function GetTimezoneFile:string;
begin
  GetTimezoneFile:='';
end;


{
 $Log: dos.inc,v $
 Revision 1.1.2.2  2002/05/01 14:09:49  carl
 + TZ is now taken from GetTimezoneSitrng instead of getenv

 Revision 1.1.2.1  2001/12/20 02:55:00  carl
 + QNX versions (still untested)

}