sysdir.inc 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. {
  2. This file is part of the Free Pascal run time library.
  3. Copyright (c) 1999-2005 by Florian Klaempfl and Pavel Ozerski
  4. member of the Free Pascal development team.
  5. Low level directory functions for MacOS
  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. {*****************************************************************************
  13. Directory Handling
  14. *****************************************************************************}
  15. procedure do_mkdir(const s: rawbytestring);
  16. var
  17. spec: FSSpec;
  18. createdDirID: Longint;
  19. err: OSErr;
  20. res: Integer;
  21. begin
  22. { TODO: convert PathArgToFSSpec (and the routines it calls) to rawbytestring }
  23. res:= PathArgToFSSpec(s, spec);
  24. if (res = 0) or (res = 2) then
  25. begin
  26. err:= FSpDirCreate(spec, smSystemScript, createdDirID);
  27. OSErr2InOutRes(err);
  28. end
  29. else
  30. InOutRes:=res;
  31. end;
  32. procedure do_rmdir(const s: rawbytestring);
  33. var
  34. spec: FSSpec;
  35. err: OSErr;
  36. res: Integer;
  37. begin
  38. res:= PathArgToFSSpec(s, spec);
  39. if (res = 0) then
  40. begin
  41. if IsDirectory(spec) then
  42. begin
  43. err:= FSpDelete(spec);
  44. OSErr2InOutRes(err);
  45. end
  46. else
  47. InOutRes:= 20;
  48. end
  49. else
  50. InOutRes:=res;
  51. end;
  52. procedure do_chdir(const s: rawbytestring);
  53. var
  54. spec, newDirSpec: FSSpec;
  55. err: OSErr;
  56. res: Integer;
  57. begin
  58. res:= PathArgToFSSpec(s, spec);
  59. if (res = 0) or (res = 2) then
  60. begin
  61. { The fictive file x is appended to the directory name to make
  62. FSMakeFSSpec return a FSSpec to a file in the directory.
  63. Then by clearing the name, the FSSpec then
  64. points to the directory. It doesn't matter whether x exists or not.}
  65. err:= FSMakeFSSpec (spec.vRefNum, spec.parID, ':'+spec.name+':x', newDirSpec);
  66. if (err = noErr) or (err = fnfErr) then
  67. begin
  68. workingDirectorySpec:= newDirSpec;
  69. workingDirectorySpec.name:='';
  70. InOutRes:= 0;
  71. end
  72. else
  73. begin
  74. {E g if the directory doesn't exist.}
  75. OSErr2InOutRes(err);
  76. end;
  77. end
  78. else
  79. InOutRes:=res;
  80. end;
  81. procedure do_getDir (DriveNr: byte; var Dir: RawByteString);
  82. var
  83. pathHandleSize: Longint;
  84. begin
  85. if FSpGetFullPath(workingDirectorySpec, Dir, false) <> noErr then
  86. Halt(3); {exit code 3 according to MPW}
  87. SetCodePage(Dir,DefaultFileSystemCodePage,false);
  88. end;