sysdir.inc 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  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(s: pchar;len:sizeuint);[IOCheck, public, alias : 'FPC_SYS_MKDIR'];
  15. var
  16. tmpStr : array[0..255] of char;
  17. tmpLock: LongInt;
  18. begin
  19. checkCTRLC;
  20. if not assigned(s) or (len=0) or (InOutRes<>0) then exit;
  21. tmpStr:=PathConv(strpas(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(s: pchar;len:sizeuint);[IOCheck, public, alias : 'FPC_SYS_RMDIR'];
  30. var
  31. tmpStr : array[0..255] of Char;
  32. begin
  33. checkCTRLC;
  34. if not assigned(s) or (len=0) then exit;
  35. if (s='.') then InOutRes:=16;
  36. If (s='') or (InOutRes<>0) then exit;
  37. tmpStr:=PathConv(strpas(s))+#0;
  38. if not dosDeleteFile(@tmpStr) then
  39. dosError2InOut(IoErr);
  40. end;
  41. Procedure ChDir(s: pchar;len:sizeuint);[IOCheck, public, alias : 'FPC_SYS_CHDIR'];
  42. var
  43. tmpStr : array[0..255] of Char;
  44. tmpLock: LongInt;
  45. FIB : PFileInfoBlock;
  46. begin
  47. checkCTRLC;
  48. if not assigned(s) or (len=0) or (InOutRes<>0) then exit;
  49. tmpStr:=PathConv(strpas(s))+#0;
  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(@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)=True) and (FIB^.fib_DirEntryType>0) then begin
  62. tmpLock:=CurrentDir(tmpLock);
  63. if MOS_OrigDir=0 then begin
  64. MOS_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 GetDir (DriveNr: byte; var Dir: ShortString);
  74. var tmpbuf: array[0..255] of char;
  75. begin
  76. checkCTRLC;
  77. Dir:='';
  78. if not GetCurrentDirName(tmpbuf,256) then
  79. dosError2InOut(IoErr)
  80. else
  81. Dir:=strpas(tmpbuf);
  82. end;