sysdir.inc 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. {
  2. This file is part of the Free Pascal run time library.
  3. Copyright (c) 2006 by Free Pascal development team
  4. Low level directory functions
  5. See the file COPYING.FPC, included in this distribution,
  6. for details about the copyright.
  7. This program is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  10. **********************************************************************}
  11. {*****************************************************************************
  12. Directory Handling
  13. *****************************************************************************}
  14. procedure mkdir(const s : string);[IOCheck];
  15. var
  16. tmpStr : array[0..255] of char;
  17. tmpLock: LongInt;
  18. begin
  19. checkCTRLC;
  20. if (s='') or (InOutRes<>0) then exit;
  21. tmpStr:=PathConv(s)+#0;
  22. tmpLock:=dosCreateDir(@tmpStr);
  23. if tmpLock=0 then begin
  24. dosError2InOut(IoErr);
  25. exit;
  26. end;
  27. UnLock(tmpLock);
  28. end;
  29. procedure rmdir(const s : string);[IOCheck];
  30. var
  31. tmpStr : array[0..255] of Char;
  32. begin
  33. checkCTRLC;
  34. if (s='.') then InOutRes:=16;
  35. If (s='') or (InOutRes<>0) then exit;
  36. tmpStr:=PathConv(s)+#0;
  37. if not dosDeleteFile(@tmpStr) then
  38. dosError2InOut(IoErr);
  39. end;
  40. procedure chdir(const s : string);[IOCheck];
  41. var
  42. tmpStr : array[0..255] of Char;
  43. tmpLock: LongInt;
  44. FIB : PFileInfoBlock;
  45. begin
  46. checkCTRLC;
  47. If (s='') or (InOutRes<>0) then exit;
  48. tmpStr:=PathConv(s)+#0;
  49. tmpLock:=0;
  50. { Changing the directory is a pretty complicated affair }
  51. { 1) Obtain a lock on the directory }
  52. { 2) CurrentDir the lock }
  53. tmpLock:=Lock(@tmpStr,SHARED_LOCK);
  54. if tmpLock=0 then begin
  55. dosError2InOut(IoErr);
  56. exit;
  57. end;
  58. FIB:=nil;
  59. new(FIB);
  60. if (Examine(tmpLock,FIB)=True) and (FIB^.fib_DirEntryType>0) then begin
  61. tmpLock:=CurrentDir(tmpLock);
  62. if MOS_OrigDir=0 then begin
  63. MOS_OrigDir:=tmpLock;
  64. tmpLock:=0;
  65. end;
  66. end else begin
  67. dosError2InOut(ERROR_DIR_NOT_FOUND);
  68. end;
  69. if tmpLock<>0 then Unlock(tmpLock);
  70. if assigned(FIB) then dispose(FIB);
  71. end;
  72. procedure GetDir (DriveNr: byte; var Dir: ShortString);
  73. var tmpbuf: array[0..255] of char;
  74. begin
  75. checkCTRLC;
  76. Dir:='';
  77. if not GetCurrentDirName(tmpbuf,256) then
  78. dosError2InOut(IoErr)
  79. else
  80. Dir:=strpas(tmpbuf);
  81. end;