dos.tex 31 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013
  1. %
  2. % $Id$
  3. % This file is part of the FPC documentation.
  4. % Copyright (C) 1997, by Michael Van Canneyt
  5. %
  6. % The FPC documentation is free text; you can redistribute it and/or
  7. % modify it under the terms of the GNU Library General Public License as
  8. % published by the Free Software Foundation; either version 2 of the
  9. % License, or (at your option) any later version.
  10. %
  11. % The FPC Documentation is distributed in the hope that it will be useful,
  12. % but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  14. % Library General Public License for more details.
  15. %
  16. % You should have received a copy of the GNU Library General Public
  17. % License along with the FPC documentation; see the file COPYING.LIB. If not,
  18. % write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
  19. % Boston, MA 02111-1307, USA.
  20. %
  21. \chapter{The DOS unit.}
  22. \FPCexampledir{dosex}
  23. This chapter describes the \var{DOS} unit for Free pascal. The \var{DOS}
  24. unit gives access to some operating system calls related to files, the
  25. file system, date and time. Except for the \palmos target, this unit is
  26. available to all supported platforms.
  27. The unit was first written for \dos by Florian kl\"ampfl. It was ported to
  28. \linux by Mark May\footnote{Current e-mail address \textsf{[email protected]}},
  29. and enhanced by Micha\"el Van Canneyt. The \amiga version was ported by
  30. Nils Sjoholm.
  31. Under non-\dos systems, some of the functionality is lost, as it is either impossible
  32. or meaningless to implement it. Other than that, the functionality for all
  33. operating systems is the same.
  34. This chapter is divided in three sections:
  35. \begin{itemize}
  36. \item The first section lists the pre-defined constants, types and variables.
  37. \item The second section gives an overview of all functions available,
  38. grouped by category.
  39. \item The third section describes the functions which appear in the
  40. interface part of the DOS unit.
  41. \end{itemize}
  42. \section{Types, Variables, Constants}
  43. \subsection {Constants}
  44. The DOS unit implements the following constants:
  45. \subsubsection{File attributes}
  46. The File Attribute constants are used in \seep{FindFirst}, \seep{FindNext} to
  47. determine what type of special file to search for in addition to normal files.
  48. These flags are also used in the \seep{SetFAttr} and \seep{GetFAttr} routines to
  49. set and retrieve attributes of files. For their definitions consult
  50. \seet{fileattributes}.
  51. \begin{FPCltable}{lll}{Possible file attributes}{fileattributes}
  52. \hline
  53. Constant & Description & Value\\ \hline
  54. \var{readonly} & Read only file & \$01\\
  55. \var{hidden} & Hidden file & \$02 \\
  56. \var{sysfile} & System file & \$04\\
  57. \var{volumeid} & Volume label & \$08\\
  58. \var{directory} & Directory & \$10\\
  59. \var{archive} & Archive & \$20\\
  60. \var{anyfile} & Any of the above special files & \$3F\\
  61. \hline
  62. \end{FPCltable}
  63. \subsubsection{fmXXXX}
  64. These constants are used in the \var{Mode} field of the \var{TextRec}
  65. record. Gives information on the filemode of the text I/O. For their
  66. definitions consult \seet{fmxxxconstants}.
  67. \begin{FPCltable}{lll}{Possible mode constants}{fmxxxconstants}
  68. \hline
  69. Constant & Description & Value\\ \hline
  70. \var{fmclosed} & File is closed & \$D7B0\\
  71. \var{fminput} & File is read only & \$D7B1 \\
  72. \var{fmoutput} & File is write only & \$D7B2\\
  73. \var{fminout} & File is read and write & \$D7B3\\
  74. \hline
  75. \end{FPCltable}
  76. \subsubsection{Other}
  77. The following constants are not portable, and should not be used. They
  78. are present for compatibility only.
  79. \begin{verbatim}
  80. {Bitmasks for CPU Flags}
  81. fcarry = $0001;
  82. fparity = $0004;
  83. fauxiliary = $0010;
  84. fzero = $0040;
  85. fsign = $0080;
  86. foverflow = $0800;
  87. \end{verbatim}
  88. \subsection{Types}
  89. The following string types are defined for easy handling of
  90. filenames :
  91. \begin{verbatim}
  92. ComStr = String[255]; { For command-lines }
  93. PathStr = String[255]; { For full path for file names }
  94. DirStr = String[255]; { For Directory and (DOS) drive string }
  95. NameStr = String[255]; { For Name of file }
  96. ExtStr = String[255]; { For Extension of file }
  97. \end{verbatim}
  98. \begin{verbatim}
  99. SearchRec = Packed Record
  100. Fill : array[1..21] of byte;
  101. { Fill replaced with declarations below, for Linux}
  102. Attr : Byte; {attribute of found file}
  103. Time : LongInt; {last modify date of found file}
  104. Size : LongInt; {file size of found file}
  105. Reserved : Word; {future use}
  106. Name : String[255]; {name of found file}
  107. SearchSpec: String[255]; {search pattern}
  108. NamePos: Word; {end of path, start of name position}
  109. End;
  110. \end{verbatim}
  111. Under \linux, the \var{Fill} array is replaced with the following:
  112. \begin{verbatim}
  113. SearchNum: LongInt; {to track which search this is}
  114. SearchPos: LongInt; {directory position}
  115. DirPtr: LongInt; {directory pointer for reading directory}
  116. SearchType: Byte; {0=normal, 1=open will close}
  117. SearchAttr: Byte; {attribute we are searching for}
  118. Fill: Array[1..07] of Byte; {future use}
  119. \end{verbatim}
  120. This is because the searching meachanism on Unix systems is substantially
  121. different from \dos's, and the calls have to be mimicked.
  122. \begin{verbatim}
  123. const
  124. filerecnamelength = 255;
  125. type
  126. FileRec = Packed Record
  127. Handle,
  128. Mode,
  129. RecSize : longint;
  130. _private : array[1..32] of byte;
  131. UserData : array[1..16] of byte;
  132. name : array[0..filerecnamelength] of char;
  133. End;
  134. \end{verbatim}
  135. \var{FileRec} is used for internal representation of typed and untyped files.
  136. Text files are handled by the following types :
  137. \begin{verbatim}
  138. const
  139. TextRecNameLength = 256;
  140. TextRecBufSize = 256;
  141. type
  142. TextBuf = array[0..TextRecBufSize-1] of char;
  143. TextRec = Packed Record
  144. Handle,
  145. Mode,
  146. bufsize,
  147. _private,
  148. bufpos,
  149. bufend : longint;
  150. bufptr : ^textbuf;
  151. openfunc,
  152. inoutfunc,
  153. flushfunc,
  154. closefunc : pointer;
  155. UserData : array[1..16] of byte;
  156. name : array[0..textrecnamelength-1] of char;
  157. buffer : textbuf;
  158. End;
  159. \end{verbatim}
  160. Remark that this is not binary compatible with the Turbo Pascal definition
  161. of \var{TextRec}, since the sizes of the different fields are different.
  162. \begin{verbatim}
  163. Registers = record
  164. case i : integer of
  165. 0 : (ax,f1,bx,f2,cx,f3,dx,f4,bp,f5,si,
  166. f51,di,f6,ds,f7,es,f8,flags,fs,gs : word);
  167. 1 : (al,ah,f9,f10,bl,bh,f11,f12,
  168. cl,ch,f13,f14,dl,dh : byte);
  169. 2 : (eax, ebx, ecx, edx, ebp, esi, edi : longint);
  170. End;
  171. \end{verbatim}
  172. The \var{registers} type is used in the \var{MSDos} call.
  173. \begin{verbatim}
  174. DateTime = record
  175. Year: Word;
  176. Month: Word;
  177. Day: Word;
  178. Hour: Word;
  179. Min: Word;
  180. Sec: word;
  181. End;
  182. \end{verbatim}
  183. The \var{DateTime} type is used in \seep{PackTime} and \seep{UnPackTime} for
  184. setting/reading file times with \seep{GetFTime} and \seep{SetFTime}.
  185. \subsection{Variables}
  186. \begin{verbatim}
  187. DosError : integer;
  188. \end{verbatim}
  189. The \var{DosError} variable is used by the procedures in the \dos unit to
  190. report errors. It can have the following values :
  191. \begin{center}
  192. \begin{tabular}{cl}
  193. 2 & File not found. \\
  194. 3 & path not found. \\
  195. 5 & Access denied. \\
  196. 6 & Invalid handle. \\
  197. 8 & Not enough memory. \\
  198. 10 & Invalid environment. \\
  199. 11 & Invalid format. \\
  200. 18 & No more files.
  201. \end{tabular}
  202. \end{center}
  203. Other values are possible, but are not documented.
  204. %\begin{verbatim}
  205. % drivestr : array [0..26] of pchar;
  206. %\end{verbatim}
  207. %This variable is defined in the \linux version of the \dos unit. It is used
  208. %in the \seef{DiskFree} and \seef{DiskSize} calls.
  209. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  210. % Functions and procedures by category
  211. \section{Function list by category}
  212. What follows is a listing of the available functions, grouped by category.
  213. For each function there is a reference to the page where you can find the
  214. function.
  215. \subsection{File handling}
  216. Routines to handle files on disk.
  217. \begin{funclist}
  218. \funcrefl{FExpand}{Dos:FExpand}{Expand filename to full path}
  219. \procref{FindClose}{Close finfirst/findnext session}
  220. \procref{FindFirst}{Start find of file}
  221. \procref{FindNext}{Find next file}
  222. \funcrefl{FSearch}{Dos:FSearch}{Search for file in a path}
  223. \procref{FSplit}{Split filename in parts}
  224. \procref{GetFAttr}{Return file attributes}
  225. \procref{GetFTime}{Return file time}
  226. \funcref{GetLongName}{Convert short filename to long filename (DOS only)}
  227. \funcref{GetShortName}{Convert long filename to short filename (DOS only)}
  228. \procref{SetFAttr}{Set file attributes}
  229. \procref{SetFTime}{Set file time}
  230. \end{funclist}
  231. \subsection{Directory and disk handling}
  232. Routines to handle disk information.
  233. \begin{funclist}
  234. \procref{AddDisk}{Add disk to list of disks (UNIX only)}
  235. \funcref{DiskFree}{Return size of free disk space}
  236. \funcref{DiskSize}{Return total disk size}
  237. \end{funclist}
  238. \subsection{Process handling}
  239. Functions to handle process information and starting new processes.
  240. \begin{funclist}
  241. \funcref{DosExitCode}{Exit code of last executed program}
  242. \funcref{EnvCount}{Return number of environment variables}
  243. \funcref{EnvStr}{Return environment string pair}
  244. \procref{Exec}{Execute program}
  245. \funcrefl{GetEnv}{Dos:GetEnv}{Return specified environment string}
  246. \end{funclist}
  247. \subsection{System information}
  248. Functions for retrieving and setting general system information such as date
  249. and time.
  250. \begin{funclist}
  251. \funcref{DosVersion}{Get OS version}
  252. \procref{GetCBreak}{Get setting of control-break handling flag}
  253. \procrefl{GetDate}{Dos:GetDate}{Get system date}
  254. \procref{GetIntVec}{Get interrupt vector status}
  255. \procrefl{GetTime}{Dos:GetTime}{Get system time}
  256. \procref{GetVerify}{Get verify flag}
  257. \procref{Intr}{Execute an interrupt}
  258. \procref{Keep}{Keep process in memory and exit}
  259. \procref{MSDos}{Execute MS-dos function call}
  260. \procref{PackTime}{Pack time for file time}
  261. \procref{SetCBreak}{Set control-break handling flag}
  262. \procref{SetDate}{Set system date}
  263. \procref{SetIntVec}{Set interrupt vectors}
  264. \procref{SetTime}{Set system time}
  265. \procref{SetVerify}{Set verify flag}
  266. \procref{SwapVectors}{Swap interrupt vectors}
  267. \procref{UnPackTime}{Unpack file time}
  268. \end{funclist}
  269. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  270. % Functions and procedures
  271. \section{Functions and Procedures}
  272. \begin{procedure}{AddDisk}
  273. \Declaration
  274. Procedure AddDisk (Const S : String);
  275. \Description
  276. \var{AddDisk} adds a filename \var{S} to the internal list of disks. It is
  277. implemented for systems which do not use DOS type drive letters.
  278. This list is used to determine which disks to use in the \seef{DiskFree}
  279. and \seef{DiskSize} calls.
  280. The \seef{DiskFree} and \seef{DiskSize} functions need a file on the
  281. specified drive, since this is required for the \var{statfs} system call.
  282. The names are added sequentially. The dos
  283. initialization code presets the first three disks to:
  284. \begin{itemize}
  285. \item \var{'.'} for the current drive,
  286. \item \var{'/fd0/.'} for the first floppy-drive (linux only).
  287. \item \var{'/fd1/.'} for the second floppy-drive (linux only).
  288. \item \var{'/'} for the first hard disk.
  289. \end{itemize}
  290. The first call to \var{AddDisk} will therefore add a name for the second
  291. harddisk, The second call for the third drive, and so on until 23 drives
  292. have been added (corresponding to drives \var{'D:'} to \var{'Z:'})
  293. \Errors
  294. None
  295. \SeeAlso
  296. \seef{DiskFree}, \seef{DiskSize}
  297. \end{procedure}
  298. \begin{function}{DiskFree}
  299. \Declaration
  300. Function DiskFree (Drive: byte) : int64;
  301. \Description
  302. \var{DiskFree} returns the number of free bytes on a disk. The parameter
  303. \var{Drive} indicates which disk should be checked. This parameter is 1 for
  304. floppy \var{a:}, 2 for floppy \var{b:}, etc. A value of 0 returns the free
  305. space on the current drive.
  306. \textbf{For \unix only:}\\
  307. The \var{diskfree} and \var{disksize} functions need a file on the
  308. specified drive, since this is required for the \var{statfs} system call.
  309. These filenames are set in the initialization of the dos unit, and have
  310. been preset to :
  311. \begin{itemize}
  312. \item \var{'.'} for the current drive,
  313. \item \var{'/fd0/.'} for the first floppy-drive (linux only).
  314. \item \var{'/fd1/.'} for the second floppy-drive (linux only).
  315. \item \var{'/'} for the first hard disk.
  316. \end{itemize}
  317. There is room for 1-26 drives. You can add a drive with the
  318. \seep{AddDisk} procedure.
  319. These settings can be coded in \var{dos.pp}, in the initialization part.
  320. \Errors
  321. -1 when a failure occurs, or an invalid drive number is given.
  322. \SeeAlso
  323. \seef{DiskSize}, \seep{AddDisk}
  324. \end{function}
  325. \FPCexample{ex6}
  326. \begin{function}{DiskSize}
  327. \Declaration
  328. Function DiskSize (Drive: byte) : int64;
  329. \Description
  330. \var{DiskSize} returns the total size (in bytes) of a disk. The parameter
  331. \var{Drive} indicates which disk should be checked. This parameter is 1 for
  332. floppy \var{a:}, 2 for floppy \var{b:}, etc. A value of 0 returns the size
  333. of the current drive.
  334. \textbf{For \unix only:}\\
  335. The \var{diskfree} and \var{disksize} functions need a file on the specified drive, since this
  336. is required for the \var{statfs} system call.
  337. These filenames are set in the initialization of the dos unit, and have
  338. been preset to :
  339. \begin{itemize}
  340. \item \var{'.'} for the current drive,
  341. \item \var{'/fd0/.'} for the first floppy-drive (linux only).
  342. \item \var{'/fd1/.'} for the second floppy-drive (linux only).
  343. \item \var{'/'} for the first hard disk.
  344. \end{itemize}
  345. There is room for 1-26 drives. You can add a drive with the
  346. \seep{AddDisk} procedure.
  347. These settings can be coded in \var{dos.pp}, in the initialization part.
  348. \Errors
  349. -1 when a failure occurs, or an invalid drive number is given.
  350. \SeeAlso
  351. \seef{DiskFree}, \seep{AddDisk}
  352. \end{function}
  353. For an example, see \seef{DiskFree}.
  354. \begin{function}{DosExitCode}
  355. \Declaration
  356. Function DosExitCode : Word;
  357. \Description
  358. \var{DosExitCode} contains (in the low byte) the exit-code of a program
  359. executed with the \var{Exec} call.
  360. \Errors
  361. None.
  362. \SeeAlso
  363. \seep{Exec}
  364. \end{function}
  365. \FPCexample{ex5}
  366. \begin{function}{DosVersion}
  367. \Declaration
  368. Function DosVersion : Word;
  369. \Description
  370. \var{DosVersion} returns the operating system or kernel version. The
  371. low byte contains the major version number, while the high byte
  372. contains the minor version number.
  373. \Portability
  374. On systems where versions consists of more then two numbers,
  375. only the first two numbers will be returned. For example Linux version 2.1.76
  376. will give you DosVersion 2.1. Some operating systems, such as \freebsd, do not
  377. have system calls to return the kernel version, in that case a value of 0 will
  378. be returned.
  379. \Errors
  380. None.
  381. \SeeAlso
  382. \end{function}
  383. \FPCexample{ex1}
  384. \begin{function}{EnvCount}
  385. \Declaration
  386. Function EnvCount : longint;\Description
  387. \var{EnvCount} returns the number of environment variables.
  388. \Errors
  389. None.
  390. \SeeAlso
  391. \seef{EnvStr}, \seef{Dos:GetEnv}
  392. \end{function}
  393. \begin{function}{EnvStr}
  394. \Declaration
  395. Function EnvStr (Index: integer) : string;\Description
  396. \var{EnvStr} returns the \var{Index}-th \var{Name=Value} pair from the list
  397. of environment variables.
  398. The index of the first pair is zero.
  399. \Errors
  400. The length is limited to 255 characters.
  401. \SeeAlso
  402. \seef{EnvCount}, \seef{Dos:GetEnv}
  403. \end{function}
  404. \FPCexample{ex13}
  405. \begin{procedure}{Exec}
  406. \Declaration
  407. Procedure Exec (const Path: pathstr; const ComLine: comstr);
  408. \Description
  409. \var{Exec} executes the program in \var{Path}, with the options given by
  410. \var{ComLine}.
  411. After the program has terminated, the procedure returns. The Exit value of
  412. the program can be consulted with the \var{DosExitCode} function.
  413. \Errors
  414. Errors are reported in \var{DosError}.
  415. \SeeAlso
  416. \seef{DosExitCode}
  417. \end{procedure}
  418. For an example, see \seef{DosExitCode}
  419. \begin{functionl}{FExpand}{Dos:FExpand}
  420. \Declaration
  421. Function FExpand (const path: pathstr) : pathstr;
  422. \Description
  423. \var{FExpand} takes its argument and expands it to a complete filename, i.e.
  424. a filename starting from the root directory of the current drive, prepended
  425. with the drive-letter or volume name (when supported).
  426. \Portability
  427. On case sensitive file systems (such as \unix and \linux), the resulting
  428. name is left as it is, otherwise it is converted to uppercase.
  429. \Errors
  430. \seep{FSplit}
  431. \SeeAlso
  432. \lstinputlisting{dosex/ex5.pp}
  433. \end{functionl}
  434. \begin{procedure}{FindClose}
  435. \Declaration
  436. Procedure FindClose (Var F: SearchRec);
  437. \Description
  438. \var{FindClose} frees any resources associated with the search record
  439. \var{F}.
  440. This call is needed to free any internal resources allocated by the
  441. \seef{FindFirst} or \seef{FindNext} calls.
  442. The \linux implementation of the \dos unit therefore keeps a table of open
  443. directories, and when the table is full, closes one of the directories, and
  444. reopens another. This system is adequate but slow if you use a lot of
  445. \var{searchrecs}.
  446. So, to speed up the findfirst/findnext system, the \var{FindClose} call was
  447. implemented. When you don't need a \var{searchrec} any more, you can tell
  448. this to the \dos unit by issuing a \var{FindClose} call. The directory
  449. which is kept open for this \var{searchrec} is then closed, and the table slot
  450. freed.
  451. \Portability
  452. It is recommended to use the \linux call \var{Glob} when looking for files
  453. on \linux.
  454. \Errors
  455. Errors are reported in DosError.
  456. \SeeAlso
  457. \seef{Glob}.
  458. \end{procedure}
  459. \begin{procedure}{FindFirst}
  460. \Declaration
  461. Procedure FindFirst (const Path: pathstr; Attr: word; var F: SearchRec);
  462. \Description
  463. \var{FindFirst} searches the file specified in \var{Path}. Normal files,
  464. as well as all special files which have the attributes specified in
  465. \var{Attr} will be returned.
  466. It returns a \var{SearchRec} record for further searching in \var{F}.
  467. \var{Path} can contain the wildcard characters \var{?} (matches any single
  468. character) and \var{*} (matches 0 ore more arbitrary characters). In this
  469. case \var{FindFirst} will return the first file which matches the specified
  470. criteria.
  471. If \var{DosError} is different from zero, no file(s) matching the criteria
  472. was(were) found.
  473. \Portability
  474. On \ostwo, you cannot issue two different \var{FindFirst} calls. That is,
  475. you must close any previous search operation with \seep{FindClose} before
  476. starting a new one. Failure to do so will end in a Run-Time Error 6
  477. (Invalid file handle)
  478. \Errors
  479. Errors are reported in DosError.
  480. \SeeAlso
  481. \seep{FindNext},
  482. \seep{FindClose}
  483. \end{procedure}
  484. \FPCexample{ex7}
  485. \begin{procedure}{FindNext}
  486. \Declaration
  487. Procedure FindNext (var f: searchRec);
  488. \Description
  489. \var{FindNext} takes as an argument a \var{SearchRec} from a previous
  490. \var{FindNext} call, or a \var{FindFirst} call, and tries to find another
  491. file which matches the criteria, specified in the \var{FindFirst} call.
  492. If \var{DosError} is different from zero, no more files matching the
  493. criteria were found.
  494. \Errors
  495. \var{DosError} is used to report errors.
  496. \SeeAlso
  497. \seep{FindFirst}, \seep{FindClose}
  498. \end{procedure}
  499. For an example, see \seep{FindFirst}.
  500. \begin{functionl}{FSearch}{Dos:FSearch}
  501. \Declaration
  502. Function FSearch (Path: pathstr; DirList: string) : pathstr;
  503. \Description
  504. \var{FSearch} searches the file \var{Path} in all directories listed in
  505. \var{DirList}. The full name of the found file is returned.
  506. \var{DirList} must be a list of directories, separated by semi-colons.
  507. When no file is found, an empty string is returned.
  508. \Portability
  509. On \unix systems, \var{DirList} can also be separated by colons, as is
  510. customary on those environments.
  511. \Errors
  512. None.
  513. \SeeAlso
  514. \seefl{FExpand}{Dos:FExpand}
  515. \end{functionl}
  516. \FPCexample{ex10}
  517. \begin{procedure}{FSplit}
  518. \Declaration
  519. Procedure FSplit (path: pathstr; \\ var dir: dirstr; var name: namestr;
  520. var ext: extstr);
  521. \Description
  522. \var{FSplit} splits a full file name into 3 parts : A \var{Path}, a
  523. \var{Name} and an extension (in \var{ext}.)
  524. The extension is taken to be all letters after the {\em last} dot (.). For
  525. \dos, however, an exception is made when \var{LFNSupport=False}, then
  526. the extension is defined as all characters after the {\em first} dot.
  527. \Errors
  528. None.
  529. \SeeAlso
  530. \seefl{FSearch}{Dos:FSearch}
  531. \end{procedure}
  532. \FPCexample{ex12}
  533. \begin{procedure}{GetCBreak}
  534. \Declaration
  535. Procedure GetCBreak (var breakvalue: boolean);
  536. \Description
  537. \var{GetCBreak} gets the status of CTRL-Break checking under \dos and \amiga.
  538. When \var{BreakValue} is \var{false}, then \dos only checks for the
  539. CTRL-Break key-press when I/O is performed. When it is set to \var{True},
  540. then a check is done at every system call.
  541. \Portability
  542. Under non-\dos and non-\amiga operating systems, \var{BreakValue} always returns
  543. \var{True}.
  544. \Errors
  545. None
  546. \SeeAlso
  547. \seep{SetCBreak}
  548. \end{procedure}
  549. \begin{procedurel}{GetDate}{Dos:GetDate}
  550. \Declaration
  551. Procedure GetDate (var year, month, mday, wday: word);\Description
  552. \var{GetDate} returns the system's date. \var{Year} is a number in the range
  553. 1980..2099.\var{mday} is the day of the month,
  554. \var{wday} is the day of the week, starting with Sunday as day 0.
  555. \Errors
  556. None.
  557. \SeeAlso
  558. \seepl{GetTime}{Dos:GetTime},\seep{SetDate}
  559. \end{procedurel}
  560. \FPCexample{ex2}
  561. \begin{functionl}{GetEnv}{Dos:GetEnv}
  562. \Declaration
  563. Function GetEnv (EnvVar: String) : String;
  564. \Description
  565. \var{Getenv} returns the value of the environment variable \var{EnvVar}.
  566. When there is no environment variable \var{EnvVar} defined, an empty
  567. string is returned.
  568. \Portability
  569. Under some operating systems (such as \unix), case is important when looking
  570. for \var{EnvVar}.
  571. \Errors
  572. None.
  573. \SeeAlso
  574. \seef{EnvCount}, \seef{EnvStr}
  575. \end{functionl}
  576. \FPCexample{ex14}
  577. \begin{procedure}{GetFAttr}
  578. \Declaration
  579. Procedure GetFAttr (var F; var Attr: word);
  580. \Description
  581. \var{GetFAttr} returns the file attributes of the file-variable \var{f}.
  582. \var{F} can be a untyped or typed file, or of type \var{Text}. \var{f} must
  583. have been assigned, but not opened. The attributes can be examined with the
  584. following constants :
  585. \begin{itemize}
  586. \item \var{ReadOnly}
  587. \item \var{Hidden}
  588. \item \var{SysFile}
  589. \item \var{VolumeId}
  590. \item \var{Directory}
  591. \item \var{Archive}
  592. \end{itemize}
  593. Under \linux, supported attributes are:
  594. \begin{itemize}
  595. \item \var{Directory}
  596. \item \var{ReadOnly} if the current process doesn't have access to the file.
  597. \item \var{Hidden} for files whose name starts with a dot \var{('.')}.
  598. \end{itemize}
  599. \Errors
  600. Errors are reported in \var{DosError}
  601. \SeeAlso
  602. \seep{SetFAttr}
  603. \end{procedure}
  604. \FPCexample{ex8}
  605. \begin{procedure}{GetFTime}
  606. \Declaration
  607. Procedure GetFTime (var F; var Time: longint);
  608. \Description
  609. \var{GetFTime} returns the modification time of a file.
  610. This time is encoded and must be decoded with \var{UnPackTime}.
  611. \var{F} must be a file type, which has been assigned, and
  612. opened.
  613. \Errors
  614. Errors are reported in \var{DosError}
  615. \SeeAlso
  616. \seep{SetFTime}, \seep{PackTime},\seep{UnPackTime}
  617. \end{procedure}
  618. \FPCexample{ex9}
  619. \begin{procedure}{GetIntVec}
  620. \Declaration
  621. Procedure GetIntVec (IntNo: byte; var Vector: pointer);
  622. \Description
  623. \var{GetIntVec} returns the address of interrupt vector
  624. \var{IntNo}.
  625. \Portability
  626. This call does nothing, it is present for compatibility only.
  627. \Errors
  628. None.
  629. \SeeAlso
  630. \seep{SetIntVec}
  631. \end{procedure}
  632. \begin{function}{GetLongName}
  633. \Declaration
  634. function GetLongName(var p : String) : boolean;\Description
  635. This function is only implemented in the GO32V2 version of \fpc.
  636. \var{GetLongName} changes the filename \var{p} to a long filename
  637. if the \dos call to do this is successful. The resulting string
  638. is the long file name corresponding to the short filename \var{p}.
  639. The function returns \var{True} if the \dos call was successful,
  640. \var{False} otherwise.
  641. This function should only be necessary when using the DOS extender
  642. under Windows 95 and higher.
  643. \Errors
  644. If the \dos call was not succesfull, \var{False} is returned.
  645. \SeeAlso
  646. \seef{GetShortName}
  647. \end{function}
  648. \begin{function}{GetShortName}
  649. \Declaration
  650. function GetShortName(var p : String) : boolean;\Description
  651. This function is only implemented in the GO32V2 version of \fpc.
  652. \var{GetShortName} changes the filename \var{p} to a short filename
  653. if the \dos call to do this is successful. The resulting string
  654. is the short file name corresponding to the long filename \var{p}.
  655. The function returns \var{True} if the \dos call was successful,
  656. \var{False} otherwise.
  657. This function should only be necessary when using the DOS extender
  658. under Windows 95 and higher.
  659. \Errors
  660. If the \dos call was not successful, \var{False} is returned.
  661. \SeeAlso
  662. \seef{GetLongName}
  663. \end{function}
  664. \begin{procedurel}{GetTime}{Dos:GetTime}
  665. \Declaration
  666. Procedure GetTime (var hour, minute, second, sec100: word);
  667. \Description
  668. \var{GetTime} returns the system's time. \var{Hour} is a on a 24-hour time
  669. scale. \var{sec100} is in hundredth of a
  670. second.
  671. \Portability
  672. Certain operating systems (such as \amiga), always set the \var{sec100} field
  673. to zero.
  674. \Errors
  675. None.
  676. \SeeAlso
  677. \seepl{GetDate}{Dos:GetDate},
  678. \seep{SetTime}
  679. \end{procedurel}
  680. \FPCexample{ex3}
  681. \begin{procedure}{GetVerify}
  682. \Declaration
  683. Procedure GetVerify (var verify: boolean);
  684. \Description
  685. \var{GetVerify} returns the status of the verify flag under \dos. When
  686. \var{Verify} is \var{True}, then \dos checks data which are written to disk,
  687. by reading them after writing. If \var{Verify} is \var{False}, then data
  688. written to disk are not verified.
  689. \Portability
  690. Under non-\dos systems (excluding \ostwo applications running under vanilla DOS),
  691. Verify is always \var{True}.
  692. \Errors
  693. None.
  694. \SeeAlso
  695. \seep{SetVerify}
  696. \end{procedure}
  697. \begin{procedure}{Intr}
  698. \Declaration
  699. Procedure Intr (IntNo: byte; var Regs: registers);
  700. \Description
  701. \var{Intr} executes a software interrupt number \var{IntNo} (must be between
  702. 0 and 255), with processor registers set to \var{Regs}. After the interrupt call
  703. returned, the processor registers are saved in \var{Regs}.
  704. \Portability
  705. Under non-\dos operating systems, this call does nothing.
  706. \Errors
  707. None.
  708. \SeeAlso
  709. \seep{MSDos}, see the \linux unit.
  710. \end{procedure}
  711. \begin{procedure}{Keep}
  712. \Declaration
  713. Procedure Keep (ExitCode: word);
  714. \Description
  715. \var{Keep} terminates the program, but stays in memory. This is used for TSR
  716. (Terminate Stay Resident) programs which catch some interrupt.
  717. \var{ExitCode} is the same parameter as the \var{Halt} function takes.
  718. \Portability
  719. This call does nothing, it is present for compatibility only.
  720. \Errors
  721. None.
  722. \SeeAlso
  723. \seem{Halt}{}
  724. \end{procedure}
  725. \begin{procedure}{MSDos}
  726. \Declaration
  727. Procedure MSDos (var regs: registers);
  728. \Description
  729. \var{MSDos} executes an operating system. This is the same as doing a
  730. \var{Intr} call with the interrupt number for an os call.
  731. \Portability
  732. Under non-\dos operating systems, this call does nothing. On \dos systems,
  733. this calls interrupt \$21.
  734. \Errors
  735. None.
  736. \SeeAlso
  737. \seep{Intr}
  738. \end{procedure}
  739. \begin{procedure}{PackTime}
  740. \Declaration
  741. Procedure PackTime (var T: datetime; var P: longint);
  742. \Description
  743. \var{UnPackTime} converts the date and time specified in \var{T}
  744. to a packed-time format which can be fed to \var{SetFTime}.
  745. \Errors
  746. None.
  747. \SeeAlso
  748. \seep{SetFTime}, \seep{FindFirst}, \seep{FindNext}, \seep{UnPackTime}
  749. \end{procedure}
  750. \FPCexample{ex4}
  751. \begin{procedure}{SetCBreak}
  752. \Declaration
  753. Procedure SetCBreak (breakvalue: boolean);
  754. \Description
  755. \var{SetCBreak} sets the status of CTRL-Break checking. When
  756. \var{BreakValue} is \var{false}, then \dos only checks for the CTRL-Break
  757. key-press when I/O is performed. When it is set to \var{True}, then a
  758. check is done at every system call.
  759. \Portability
  760. Under non-\dos and non-\amiga operating systems, this call does nothing.
  761. \Errors
  762. None.
  763. \SeeAlso
  764. \seep{GetCBreak}
  765. \end{procedure}
  766. \begin{procedure}{SetDate}
  767. \Declaration
  768. Procedure SetDate (year,month,day: word);
  769. \Description
  770. \var{SetDate} sets the system's internal date. \var{Year} is a number
  771. between 1980 and 2099.
  772. \Portability
  773. On a \linux machine, there must be root privileges, otherwise this
  774. routine will do nothing. On other \unix systems, this call currently
  775. does nothing.
  776. \Errors
  777. None.
  778. \SeeAlso
  779. \seep{Dos:GetDate},
  780. \seep{SetTime}
  781. \end{procedure}
  782. \begin{procedure}{SetFAttr}
  783. \Declaration
  784. Procedure SetFAttr (var F; Attr: word);
  785. \Description
  786. \var{SetFAttr} sets the file attributes of the file-variable \var{F}.
  787. \var{F} can be a untyped or typed file, or of type \var{Text}. \var{F} must
  788. have been assigned, but not opened. The attributes can be a sum of the
  789. following constants:
  790. \begin{itemize}
  791. \item \var{ReadOnly}
  792. \item \var{Hidden}
  793. \item \var{SysFile}
  794. \item \var{VolumeId}
  795. \item \var{Directory}
  796. \item \var{Archive}
  797. \end{itemize}
  798. \Portability
  799. Under \unix like systems (such as \linux and \beos) the call exists, but is not implemented,
  800. i.e. it does nothing.
  801. \Errors
  802. Errors are reported in \var{DosError}.
  803. \SeeAlso
  804. \seep{GetFAttr}
  805. \end{procedure}
  806. \begin{procedure}{SetFTime}
  807. \Declaration
  808. Procedure SetFTime (var F; Time: longint);
  809. \Description
  810. \var{SetFTime} sets the modification time of a file,
  811. this time is encoded and must be encoded with \var{PackTime}.
  812. \var{F} must be a file type, which has been assigned, and
  813. opened.
  814. \Portability
  815. Under \unix like systems (such as \linux and \beos) the call exists, but is not implemented,
  816. i.e. it does nothing.
  817. \Errors
  818. Errors are reported in \var{DosError}
  819. \SeeAlso
  820. \seep{GetFTime}, \seep{PackTime},\seep{UnPackTime}
  821. \end{procedure}
  822. \begin{procedure}{SetIntVec}
  823. \Declaration
  824. Procedure SetIntVec (IntNo: byte; Vector: pointer);
  825. \Description
  826. \var{SetIntVec} sets interrupt vector \var{IntNo} to \var{Vector}.
  827. \var{Vector} should point to an interrupt procedure.
  828. \Portability
  829. This call does nothing, it is present for compatibility only.
  830. \Errors
  831. None.
  832. \SeeAlso
  833. \seep{GetIntVec}
  834. \end{procedure}
  835. \begin{procedure}{SetTime}
  836. \Declaration
  837. Procedure SetTime (hour,minute,second,sec100: word);
  838. \Description
  839. \var{SetTime} sets the system's internal clock. The \var{Hour} parameter is
  840. on a 24-hour time scale.
  841. \Portability
  842. On a \linux machine, there must be root privileges, otherwise this
  843. routine will do nothing. On other \unix systems, this call currently
  844. does nothing.
  845. \Errors
  846. None.
  847. \SeeAlso
  848. \seep{Dos:GetTime}, \seep{SetDate}
  849. \end{procedure}
  850. \begin{procedure}{SetVerify}
  851. \Declaration
  852. Procedure SetVerify (verify: boolean);
  853. \Description
  854. \var{SetVerify} sets the status of the verify flag under \dos. When
  855. \var{Verify} is \var{True}, then \dos checks data which are written to disk,
  856. by reading them after writing. If \var{Verify} is \var{False}, then data
  857. written to disk are not verified.
  858. \Portability
  859. Under non-\dos operating systems (excluding \ostwo applications running
  860. under vanilla dos), Verify is always \var{True}.
  861. \Errors
  862. None.
  863. \SeeAlso
  864. \seep{SetVerify}
  865. \end{procedure}
  866. \begin{procedure}{SwapVectors}
  867. \Declaration
  868. Procedure SwapVectors ;
  869. \Description
  870. \var{SwapVectors} swaps the contents of the internal table of interrupt
  871. vectors with the current contents of the interrupt vectors.
  872. This is called typically in before and after an \var{Exec} call.
  873. \Portability
  874. Under certain operating systems, this routine may be implemented
  875. as an empty stub.
  876. \Errors
  877. None.
  878. \SeeAlso
  879. \seep{Exec}, \seep{SetIntVec}
  880. \end{procedure}
  881. \begin{procedure}{UnPackTime}
  882. \Declaration
  883. Procedure UnPackTime (p: longint; var T: datetime);
  884. \Description
  885. \var{UnPackTime} converts the file-modification time in \var{p}
  886. to a \var{DateTime} record. The file-modification time can be
  887. returned by \var{GetFTime}, \var{FindFirst} or \var{FindNext} calls.
  888. \Errors
  889. None.
  890. \SeeAlso
  891. \seep{GetFTime}, \seep{FindFirst}, \seep{FindNext}, \seep{PackTime}
  892. \end{procedure}
  893. For an example, see \seep{PackTime}.