dos.pp 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832
  1. {
  2. $Id$
  3. This file is part of the Free Pascal run time library.
  4. Copyright (c) 1999-2004 by the Free Pascal development team.
  5. Dos unit for BP7 compatible RTL (novell netware libc)
  6. See the file COPYING.FPC, included in this distribution,
  7. for details about the copyright.
  8. This program is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  11. **********************************************************************}
  12. unit dos;
  13. interface
  14. uses libc;
  15. Const
  16. FileNameLen = 255;
  17. Type
  18. searchrec = packed record
  19. DirP : POINTER; { used for opendir }
  20. EntryP: POINTER; { and readdir }
  21. Magic : WORD;
  22. fill : array[1..11] of byte;
  23. attr : byte;
  24. time : longint;
  25. size : longint;
  26. name : string[255];
  27. { Internals used by netware port only: }
  28. _mask : string[255];
  29. _dir : string[255];
  30. _attr : word;
  31. end;
  32. registers = packed record
  33. case i : integer of
  34. 0 : (ax,f1,bx,f2,cx,f3,dx,f4,bp,f5,si,f51,di,f6,ds,f7,es,f8,flags,fs,gs : word);
  35. 1 : (al,ah,f9,f10,bl,bh,f11,f12,cl,ch,f13,f14,dl,dh : byte);
  36. 2 : (eax, ebx, ecx, edx, ebp, esi, edi : longint);
  37. end;
  38. {$i dosh.inc}
  39. {Extra Utils}
  40. function weekday(y,m,d : longint) : longint;
  41. implementation
  42. uses
  43. strings;
  44. {$ASMMODE ATT}
  45. {*****************************************************************************
  46. --- Info / Date / Time ---
  47. ******************************************************************************}
  48. {$PACKRECORDS 4}
  49. function dosversion : word;
  50. var i : Tutsname;
  51. begin
  52. if uname (i) >= 0 then
  53. dosversion := WORD (i.netware_minor) SHL 8 + i.netware_major
  54. else dosversion := $0005;
  55. end;
  56. function WeekDay (y,m,d:longint):longint;
  57. {
  58. Calculates th day of the week. returns -1 on error
  59. }
  60. var
  61. u,v : longint;
  62. begin
  63. if (m<1) or (m>12) or (y<1600) or (y>4000) or
  64. (d<1) or (d>30+((m+ord(m>7)) and 1)-ord(m=2)) or
  65. ((m*d=58) and (((y mod 4>0) or (y mod 100=0)) and (y mod 400>0))) then
  66. WeekDay:=-1
  67. else
  68. begin
  69. u:=m;
  70. v:=y;
  71. if m<3 then
  72. begin
  73. inc(u,12);
  74. dec(v);
  75. end;
  76. WeekDay:=(d+2*u+((3*(u+1)) div 5)+v+(v div 4)-(v div 100)+(v div 400)+1) mod 7;
  77. end;
  78. end;
  79. procedure getdate(var year,month,mday,wday : word);
  80. var
  81. t : TTime;
  82. tm : Ttm;
  83. begin
  84. time(t); localtime_r(t,tm);
  85. with tm do
  86. begin
  87. year := tm_year+1900;
  88. month := tm_mon+1;
  89. mday := tm_mday;
  90. wday := tm_wday;
  91. end;
  92. end;
  93. procedure setdate(year,month,day : word);
  94. begin
  95. end;
  96. procedure gettime(var hour,minute,second,sec100 : word);
  97. var
  98. t : TTime;
  99. tm : Ttm;
  100. begin
  101. time(t); localtime_r(t,tm);
  102. with tm do
  103. begin
  104. hour := tm_hour;
  105. minute := tm_min;
  106. second := tm_sec;
  107. sec100 := 0;
  108. end;
  109. end;
  110. procedure settime(hour,minute,second,sec100 : word);
  111. begin
  112. end;
  113. Procedure packtime(var t : datetime;var p : longint);
  114. Begin
  115. p:=(t.sec shr 1)+(t.min shl 5)+(t.hour shl 11)+(t.day shl 16)+(t.month shl 21)+((t.year-1980) shl 25);
  116. End;
  117. Procedure unpacktime(p : longint;var t : datetime);
  118. Begin
  119. with t do
  120. begin
  121. sec:=(p and 31) shl 1;
  122. min:=(p shr 5) and 63;
  123. hour:=(p shr 11) and 31;
  124. day:=(p shr 16) and 31;
  125. month:=(p shr 21) and 15;
  126. year:=(p shr 25)+1980;
  127. end;
  128. End;
  129. {******************************************************************************
  130. --- Exec ---
  131. ******************************************************************************}
  132. {$ifdef HASTHREADVAR}
  133. threadvar
  134. {$else HASTHREADVAR}
  135. var
  136. {$endif HASTHREADVAR}
  137. lastdosexitcode : word;
  138. const maxargs=256;
  139. procedure exec(const path : pathstr;const comline : comstr);
  140. var c : comstr;
  141. i : integer;
  142. args : array[0..maxargs] of pchar;
  143. arg0 : pathstr;
  144. numargs,wstat : integer;
  145. Wiring : TWiring;
  146. begin
  147. if pos ('.',path) = 0 then
  148. arg0 := fexpand(path+'.nlm'#0) else
  149. arg0 := fexpand (path)+#0;
  150. //writeln (stderr,'dos.exec (',path,',',comline,') arg0:"',copy(arg0,1,length(arg0)-1),'"');
  151. args[0] := @arg0[1];
  152. numargs := 0;
  153. c:=comline;
  154. i:=1;
  155. while i<=length(c) do
  156. begin
  157. if c[i]<>' ' then
  158. begin
  159. {Commandline argument found. append #0 and set pointer in args }
  160. inc(numargs);
  161. args[numargs]:=@c[i];
  162. while (i<=length(c)) and (c[i]<>' ') do
  163. inc(i);
  164. c[i] := #0;
  165. end;
  166. inc(i);
  167. end;
  168. args[numargs+1] := nil;
  169. // i := spawnvp (P_WAIT,args[0],@args);
  170. Wiring.infd := StdInputHandle; //textrec(Stdin).Handle;
  171. Wiring.outfd:= textrec(stdout).Handle;
  172. Wiring.errfd:= textrec(stderr).Handle;
  173. //writeln (stderr,'calling procve');
  174. i := procve(args[0],
  175. PROC_CURRENT_SPACE+PROC_INHERIT_CWD,
  176. envP, // const char * env[] If passed as NULL, the child process inherits the parent.s environment at the time of the call.
  177. @Wiring, // wiring_t *wiring, Pass NULL to inherit system defaults for wiring.
  178. nil, // struct fd_set *fds, Not currently implemented. Pass in NULL.
  179. nil, // void *appdata, Not currently implemented. Pass in NULL.
  180. 0, // size_t appdata_size, Not currently implemented. Pass in 0
  181. nil, // void *reserved, Reserved. Pass NULL.
  182. @args); // const char *argv[]
  183. //writeln (stderr,'Ok');
  184. if i <> -1 then
  185. begin
  186. waitpid(i,@wstat,0);
  187. doserror := 0;
  188. lastdosexitcode := wstat;
  189. end else
  190. begin
  191. doserror := 8; // for now, what about errno ?
  192. end;
  193. end;
  194. function dosexitcode : word;
  195. begin
  196. dosexitcode:=lastdosexitcode;
  197. end;
  198. procedure getcbreak(var breakvalue : boolean);
  199. begin
  200. end;
  201. procedure setcbreak(breakvalue : boolean);
  202. begin
  203. end;
  204. procedure getverify(var verify : boolean);
  205. begin
  206. verify := true;
  207. end;
  208. procedure setverify(verify : boolean);
  209. begin
  210. end;
  211. {******************************************************************************
  212. --- Disk ---
  213. ******************************************************************************}
  214. function getvolnum (drive : byte) : longint;
  215. var dir : STRING[255];
  216. P,PS,
  217. V : LONGINT;
  218. begin
  219. {if drive = 0 then
  220. begin // get volume name from current directory (i.e. SERVER-NAME/VOL2:TEST)
  221. getdir (0,dir);
  222. p := pos (':', dir);
  223. if p = 0 then
  224. begin
  225. getvolnum := -1;
  226. exit;
  227. end;
  228. byte (dir[0]) := p-1;
  229. dir[p] := #0;
  230. PS := pos ('/', dir);
  231. INC (PS);
  232. if _GetVolumeNumber (@dir[PS], V) <> 0 then
  233. getvolnum := -1
  234. else
  235. getvolnum := V;
  236. end else
  237. getvolnum := drive-1;}
  238. end;
  239. function diskfree(drive : byte) : int64;
  240. VAR Buf : ARRAY [0..255] OF CHAR;
  241. TotalBlocks : WORD;
  242. SectorsPerBlock : WORD;
  243. availableBlocks : WORD;
  244. totalDirectorySlots : WORD;
  245. availableDirSlots : WORD;
  246. volumeisRemovable : WORD;
  247. volumeNumber : LONGINT;
  248. begin
  249. volumeNumber := getvolnum (drive);
  250. (*
  251. if volumeNumber >= 0 then
  252. begin
  253. {i think thats not the right function but for others i need a connection handle}
  254. if _GetVolumeInfoWithNumber (byte(volumeNumber),@Buf,
  255. TotalBlocks,
  256. SectorsPerBlock,
  257. availableBlocks,
  258. totalDirectorySlots,
  259. availableDirSlots,
  260. volumeisRemovable) = 0 THEN
  261. begin
  262. diskfree := int64 (availableBlocks) * int64 (SectorsPerBlock) * 512;
  263. end else
  264. diskfree := 0;
  265. end else*)
  266. diskfree := 0;
  267. end;
  268. function disksize(drive : byte) : int64;
  269. VAR Buf : ARRAY [0..255] OF CHAR;
  270. TotalBlocks : WORD;
  271. SectorsPerBlock : WORD;
  272. availableBlocks : WORD;
  273. totalDirectorySlots : WORD;
  274. availableDirSlots : WORD;
  275. volumeisRemovable : WORD;
  276. volumeNumber : LONGINT;
  277. begin
  278. volumeNumber := getvolnum (drive);
  279. (*
  280. if volumeNumber >= 0 then
  281. begin
  282. {i think thats not the right function but for others i need a connection handle}
  283. if _GetVolumeInfoWithNumber (byte(volumeNumber),@Buf,
  284. TotalBlocks,
  285. SectorsPerBlock,
  286. availableBlocks,
  287. totalDirectorySlots,
  288. availableDirSlots,
  289. volumeisRemovable) = 0 THEN
  290. begin
  291. disksize := int64 (TotalBlocks) * int64 (SectorsPerBlock) * 512;
  292. end else
  293. disksize := 0;
  294. end else*)
  295. disksize := 0;
  296. end;
  297. {******************************************************************************
  298. --- Utils ---
  299. ******************************************************************************}
  300. procedure timet2dostime (timet:longint; var dostime : longint);
  301. var tm : Ttm;
  302. begin
  303. localtime_r(timet,tm);
  304. dostime:=(tm.tm_sec shr 1)+(tm.tm_min shl 5)+(tm.tm_hour shl 11)+(tm.tm_mday shl 16)+((tm.tm_mon+1) shl 21)+((tm.tm_year+1900-1980) shl 25);
  305. end;
  306. function nwattr2dosattr (nwattr : longint) : word;
  307. begin
  308. nwattr2dosattr := 0;
  309. if nwattr and M_A_RDONLY > 0 then nwattr2dosattr := nwattr2dosattr + readonly;
  310. if nwattr and M_A_HIDDEN > 0 then nwattr2dosattr := nwattr2dosattr + hidden;
  311. if nwattr and M_A_SYSTEM > 0 then nwattr2dosattr := nwattr2dosattr + sysfile;
  312. if nwattr and M_A_SUBDIR > 0 then nwattr2dosattr := nwattr2dosattr + directory;
  313. if nwattr and M_A_ARCH > 0 then nwattr2dosattr := nwattr2dosattr + archive;
  314. end;
  315. {******************************************************************************
  316. --- Findfirst FindNext ---
  317. ******************************************************************************}
  318. {returns true if attributes match}
  319. function find_setfields (var f : searchRec) : boolean;
  320. var
  321. StatBuf : TStat;
  322. fname : string[255];
  323. begin
  324. find_setfields := false;
  325. with F do
  326. begin
  327. if Magic = $AD01 then
  328. begin
  329. attr := nwattr2dosattr (Pdirent(EntryP)^.d_mode);
  330. size := Pdirent(EntryP)^.d_size;
  331. name := strpas (Pdirent(EntryP)^.d_name);
  332. doserror := 0;
  333. fname := f._dir + f.name;
  334. if length (fname) = 255 then dec (byte(fname[0]));
  335. fname := fname + #0;
  336. if stat (@fname[1],StatBuf) = 0 then
  337. timet2dostime (StatBuf.st_mtim.tv_sec, time)
  338. else
  339. time := 0;
  340. if (f._attr and hidden) = 0 then
  341. if attr and hidden > 0 then exit;
  342. if (f._attr and Directory) = 0 then
  343. if attr and Directory > 0 then exit;
  344. if (f._attr and SysFile) = 0 then
  345. if attr and SysFile > 0 then exit;
  346. find_setfields := true;
  347. end else
  348. begin
  349. FillChar (f,sizeof(f),0);
  350. doserror := 18;
  351. end;
  352. end;
  353. end;
  354. procedure findfirst(const path : pathstr;attr : word;var f : searchRec);
  355. var
  356. path0 : array[0..256] of char;
  357. p : longint;
  358. begin
  359. IF path = '' then
  360. begin
  361. doserror := 18;
  362. exit;
  363. end;
  364. f._attr := attr;
  365. p := length (path);
  366. while (p > 0) and (not (path[p] in ['\','/'])) do
  367. dec (p);
  368. if p > 0 then
  369. begin
  370. f._mask := copy (path,p+1,255);
  371. f._dir := copy (path,1,p);
  372. strpcopy(path0,f._dir);
  373. end else
  374. begin
  375. f._mask := path;
  376. getdir (0,f._dir);
  377. if (f._dir[length(f._dir)] <> '/') and
  378. (f._dir[length(f._dir)] <> '\') then
  379. f._dir := f._dir + '/';
  380. strpcopy(path0,f._dir);
  381. end;
  382. if f._mask = '*' then f._mask := '';
  383. if f._mask = '*.*' then f._mask := '';
  384. //writeln (stderr,'mask: "',f._mask,'" dir:"',path0,'"');
  385. f._mask := f._mask + #0;
  386. Pdirent(f.DirP) := opendir (path0);
  387. if f.DirP = nil then
  388. doserror := 18
  389. else begin
  390. F.Magic := $AD01;
  391. findnext (f);
  392. end;
  393. end;
  394. procedure findnext(var f : searchRec);
  395. begin
  396. if F.Magic <> $AD01 then
  397. begin
  398. doserror := 18;
  399. exit;
  400. end;
  401. doserror:=0;
  402. repeat
  403. Pdirent(f.EntryP) := readdir (Pdirent(f.DirP));
  404. if F.EntryP = nil then
  405. doserror := 18
  406. else
  407. if find_setfields (f) then
  408. begin
  409. if f._mask = #0 then exit;
  410. if fnmatch(@f._mask[1],Pdirent(f.EntryP)^.d_name,FNM_CASEFOLD) = 0 then
  411. exit;
  412. end;
  413. until doserror <> 0;
  414. end;
  415. Procedure FindClose(Var f: SearchRec);
  416. begin
  417. if F.Magic <> $AD01 then
  418. begin
  419. doserror := 18;
  420. EXIT;
  421. end;
  422. doserror:=0;
  423. closedir (Pdirent(f.DirP));
  424. f.Magic := 0;
  425. f.DirP := NIL;
  426. f.EntryP := NIL;
  427. end;
  428. procedure swapvectors;
  429. begin
  430. end;
  431. {******************************************************************************
  432. --- File ---
  433. ******************************************************************************}
  434. procedure fsplit(path : pathstr;var dir : dirstr;var name : namestr;var ext : extstr);
  435. var
  436. dotpos,p1,i : longint;
  437. begin
  438. { allow backslash as slash }
  439. for i:=1 to length(path) do
  440. if path[i]='\' then path[i]:='/';
  441. { get volume name }
  442. p1:=pos(':',path);
  443. if p1>0 then
  444. begin
  445. dir:=copy(path,1,p1);
  446. delete(path,1,p1);
  447. end
  448. else
  449. dir:='';
  450. { split the path and the name, there are no more path informtions }
  451. { if path contains no backslashes }
  452. while true do
  453. begin
  454. p1:=pos('/',path);
  455. if p1=0 then
  456. break;
  457. dir:=dir+copy(path,1,p1);
  458. delete(path,1,p1);
  459. end;
  460. { try to find out a extension }
  461. //if LFNSupport then
  462. begin
  463. Ext:='';
  464. i:=Length(Path);
  465. DotPos:=256;
  466. While (i>0) Do
  467. Begin
  468. If (Path[i]='.') Then
  469. begin
  470. DotPos:=i;
  471. break;
  472. end;
  473. Dec(i);
  474. end;
  475. Ext:=Copy(Path,DotPos,255);
  476. Name:=Copy(Path,1,DotPos - 1);
  477. end
  478. end;
  479. function GetShortName(var p : String) : boolean;
  480. begin
  481. GetShortName := false;
  482. end;
  483. function GetLongName(var p : String) : boolean;
  484. begin
  485. GetLongName := false;
  486. end;
  487. {$define FPC_FEXPAND_DRIVES}
  488. {$define FPC_FEXPAND_VOLUMES}
  489. {$define FPC_FEXPAND_NO_DEFAULT_PATHS}
  490. {$i fexpand.inc}
  491. Function FSearch(path: pathstr; dirlist: string): pathstr;
  492. var
  493. i,p1 : longint;
  494. s : searchrec;
  495. newdir : pathstr;
  496. begin
  497. system.write ('FSearch ("',path,'","',dirlist,'"');
  498. { check if the file specified exists }
  499. findfirst(path,anyfile,s);
  500. if doserror=0 then
  501. begin
  502. findclose(s);
  503. fsearch:=path;
  504. exit;
  505. end;
  506. { No wildcards allowed in these things }
  507. if (pos('?',path)<>0) or (pos('*',path)<>0) then
  508. fsearch:=''
  509. else
  510. begin
  511. { allow backslash as slash }
  512. for i:=1 to length(dirlist) do
  513. if dirlist[i]='\' then dirlist[i]:='/';
  514. repeat
  515. p1:=pos(';',dirlist);
  516. if p1<>0 then
  517. begin
  518. newdir:=copy(dirlist,1,p1-1);
  519. delete(dirlist,1,p1);
  520. end
  521. else
  522. begin
  523. newdir:=dirlist;
  524. dirlist:='';
  525. end;
  526. if (newdir<>'') and (not (newdir[length(newdir)] in ['/',':'])) then
  527. newdir:=newdir+'/';
  528. findfirst(newdir+path,anyfile,s);
  529. if doserror=0 then
  530. newdir:=newdir+path
  531. else
  532. newdir:='';
  533. until (dirlist='') or (newdir<>'');
  534. fsearch:=newdir;
  535. end;
  536. findclose(s);
  537. end;
  538. {******************************************************************************
  539. --- Get/Set File Time,Attr ---
  540. ******************************************************************************}
  541. procedure getftime(var f;var time : longint);
  542. var
  543. StatBuf : TStat;
  544. begin
  545. doserror := 0;
  546. if fstat (filerec (f).handle, StatBuf) = 0 then
  547. timet2dostime (StatBuf.st_mtim.tv_sec,time)
  548. else begin
  549. time := 0;
  550. doserror := ___errno^;
  551. end;
  552. end;
  553. procedure setftime(var f;time : longint);
  554. Var
  555. utim: utimbuf;
  556. DT: DateTime;
  557. path: pathstr;
  558. tm : TTm;
  559. Begin
  560. doserror:=0;
  561. with utim do
  562. begin
  563. actime:=libc.time(nil); // getepochtime;
  564. UnPackTime(Time,DT);
  565. with tm do
  566. begin
  567. tm_sec := DT.Sec; // seconds after the minute [0..59]
  568. tm_min := DT.Min; // minutes after the hour [0..59]
  569. tm_hour := DT.hour; // hours since midnight [0..23]
  570. tm_mday := DT.Day; // days of the month [1..31]
  571. tm_mon := DT.month-1; // months since January [0..11]
  572. tm_year := DT.year-1900;
  573. tm_wday := -1;
  574. tm_yday := -1;
  575. tm_isdst := -1;
  576. end;
  577. modtime:=mktime(tm);
  578. end;
  579. if utime(@filerec(f).name,utim)<0 then
  580. begin
  581. Time:=0;
  582. doserror:=3;
  583. end;
  584. end;
  585. procedure getfattr(var f;var attr : word);
  586. VAR StatBuf : TStat;
  587. begin
  588. doserror := 0;
  589. if stat (@textrec(f).name, StatBuf) = 0 then
  590. attr := nwattr2dosattr (StatBuf.st_mode)
  591. else
  592. begin
  593. attr := 0;
  594. doserror := ___errno^;
  595. end;
  596. end;
  597. procedure setfattr(var f;attr : word);
  598. var
  599. StatBuf : TStat;
  600. newMode : longint;
  601. begin
  602. if stat (@textrec(f).name,StatBuf) = 0 then
  603. begin
  604. newmode := StatBuf.st_mode and ($FFFF0000 - M_A_RDONLY-M_A_HIDDEN-M_A_SYSTEM-M_A_ARCH); {only this can be set by dos unit}
  605. newmode := newmode or M_A_BITS_SIGNIFICANT; {set netware attributes}
  606. if attr and readonly > 0 then
  607. newmode := newmode or M_A_RDONLY;
  608. if attr and hidden > 0 then
  609. newmode := newmode or M_A_HIDDEN;
  610. if attr and sysfile > 0 then
  611. newmode := newmode or M_A_SYSTEM;
  612. if attr and archive > 0 then
  613. newmode := newmode or M_A_ARCH;
  614. if chmod (@textrec(f).name,newMode) < 0 then
  615. doserror := ___errno^ else
  616. doserror := 0;
  617. end else
  618. doserror := ___errno^;
  619. end;
  620. {******************************************************************************
  621. --- Environment ---
  622. ******************************************************************************}
  623. Function EnvCount: Longint;
  624. var
  625. envcnt : longint;
  626. p : ppchar;
  627. Begin
  628. envcnt:=0;
  629. p:=envp; {defined in system}
  630. while (p^<>nil) do
  631. begin
  632. inc(envcnt);
  633. inc(p);
  634. end;
  635. EnvCount := envcnt
  636. End;
  637. Function EnvStr (Index: longint): String;
  638. Var
  639. i : longint;
  640. p : ppchar;
  641. Begin
  642. if Index <= 0 then
  643. envstr:=''
  644. else
  645. begin
  646. p:=envp; {defined in system}
  647. i:=1;
  648. while (i<Index) and (p^<>nil) do
  649. begin
  650. inc(i);
  651. inc(p);
  652. end;
  653. if p=nil then
  654. envstr:=''
  655. else
  656. envstr:=strpas(p^)
  657. end;
  658. end;
  659. { works fine (at least with netware 6.5) }
  660. Function GetEnv(envvar: string): string;
  661. var envvar0 : array[0..512] of char;
  662. p : pchar;
  663. SearchElement : string[255];
  664. i,isDosPath,res : longint;
  665. begin
  666. if upcase(envvar) = 'PATH' then
  667. begin // netware does not have search paths in the environment var PATH
  668. // return it here (needed for the compiler)
  669. GetEnv := '';
  670. i := 1;
  671. res := GetSearchPathElement (i, isdosPath, @SearchElement[0]);
  672. while res = 0 do
  673. begin
  674. if isDosPath = 0 then
  675. begin
  676. if GetEnv <> '' then GetEnv := GetEnv + ';';
  677. GetEnv := GetEnv + SearchElement;
  678. end;
  679. inc (i);
  680. res := GetSearchPathElement (i, isdosPath, @SearchElement[0]);
  681. end;
  682. for i := 1 to length(GetEnv) do
  683. if GetEnv[i] = '\' then
  684. GetEnv[i] := '/';
  685. end else
  686. begin
  687. strpcopy(envvar0,envvar);
  688. p := libc.getenv (envvar0);
  689. if p = NIL then
  690. GetEnv := ''
  691. else
  692. GetEnv := strpas (p);
  693. end;
  694. end;
  695. {******************************************************************************
  696. --- Not Supported ---
  697. ******************************************************************************}
  698. Procedure keep(exitcode : word);
  699. Begin
  700. { simply wait until nlm will be unloaded }
  701. while true do delay (60000);
  702. End;
  703. Procedure getintvec(intno : byte;var vector : pointer);
  704. Begin
  705. { no netware equivalent }
  706. End;
  707. Procedure setintvec(intno : byte;vector : pointer);
  708. Begin
  709. { no netware equivalent }
  710. End;
  711. procedure intr(intno : byte;var regs : registers);
  712. begin
  713. { no netware equivalent }
  714. end;
  715. procedure msdos(var regs : registers);
  716. begin
  717. { no netware equivalent }
  718. end;
  719. end.
  720. {
  721. $Log$
  722. Revision 1.2 2004-09-12 20:51:22 armin
  723. * added keyboard and video
  724. * a lot of fixes
  725. Revision 1.1 2004/09/05 20:58:47 armin
  726. * first rtl version for netwlibc
  727. }