sysdir.inc 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. {
  2. This file is part of the Free Pascal run time library.
  3. Copyright (c) 2014 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 do_mkdir(const s : rawbytestring);
  15. var
  16. tmpStr : rawbytestring;
  17. tmpLock: BPTR;
  18. begin
  19. checkCTRLC;
  20. tmpStr:=PathConv(s);
  21. tmpLock:=dosCreateDir(pchar(tmpStr));
  22. if tmpLock=0 then begin
  23. dosError2InOut(IoErr);
  24. exit;
  25. end;
  26. UnLock(tmpLock);
  27. end;
  28. procedure do_rmdir(const s : rawbytestring);
  29. var
  30. tmpStr : rawbytestring;
  31. begin
  32. checkCTRLC;
  33. if (s='.') then
  34. begin
  35. InOutRes:=16;
  36. exit;
  37. end;
  38. tmpStr:=PathConv(s);
  39. if not dosDeleteFile(pchar(tmpStr)) then
  40. dosError2InOut(IoErr);
  41. end;
  42. procedure do_ChDir(const s: rawbytestring);
  43. var
  44. tmpStr : rawbytestring;
  45. tmpLock: BPTR;
  46. FIB : PFileInfoBlock;
  47. begin
  48. checkCTRLC;
  49. tmpStr:=PathConv(s);
  50. tmpLock:=0;
  51. { Changing the directory is a pretty complicated affair }
  52. { 1) Obtain a lock on the directory }
  53. { 2) CurrentDir the lock }
  54. tmpLock:=Lock(pchar(tmpStr),SHARED_LOCK);
  55. if tmpLock=0 then begin
  56. dosError2InOut(IoErr);
  57. exit;
  58. end;
  59. FIB:=nil;
  60. new(FIB);
  61. if (Examine(tmpLock,FIB)<>0) and (FIB^.fib_DirEntryType>0) then begin
  62. tmpLock:=CurrentDir(tmpLock);
  63. if ASYS_OrigDir=0 then begin
  64. ASYS_OrigDir:=tmpLock;
  65. tmpLock:=0;
  66. end;
  67. end else begin
  68. dosError2InOut(ERROR_DIR_NOT_FOUND);
  69. end;
  70. if tmpLock<>0 then Unlock(tmpLock);
  71. if assigned(FIB) then dispose(FIB);
  72. end;
  73. procedure do_GetDir (DriveNr: byte; var Dir: RawByteString);
  74. var
  75. tmpbuf: array[0..255] of char;
  76. lockDir: BPTR;
  77. begin
  78. checkCTRLC;
  79. Dir := '';
  80. { dos.library's GetCurrentDirName() doesn't work when called from
  81. Workbench (ie. when the process has no CLI sructure) }
  82. { it also doesn't seem to work when invoked from make on AROS }
  83. LockDir := CurrentDir(0);
  84. NameFromLock(LockDir, tmpBuf, 256);
  85. CurrentDir(LockDir);
  86. Dir := tmpBuf;
  87. SetCodePage(Dir,DefaultSystemCodePage,false);
  88. end;