sysdir.inc 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  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 mkdir(const s:string);[IOCheck];
  16. var
  17. spec: FSSpec;
  18. createdDirID: Longint;
  19. err: OSErr;
  20. res: Integer;
  21. begin
  22. If (s='') or (InOutRes <> 0) then
  23. exit;
  24. res:= PathArgToFSSpec(s, spec);
  25. if (res = 0) or (res = 2) then
  26. begin
  27. err:= FSpDirCreate(spec, smSystemScript, createdDirID);
  28. OSErr2InOutRes(err);
  29. end
  30. else
  31. InOutRes:=res;
  32. end;
  33. procedure rmdir(const s:string);[IOCheck];
  34. var
  35. spec: FSSpec;
  36. err: OSErr;
  37. res: Integer;
  38. begin
  39. If (s='') or (InOutRes <> 0) then
  40. exit;
  41. res:= PathArgToFSSpec(s, spec);
  42. if (res = 0) then
  43. begin
  44. if IsDirectory(spec) then
  45. begin
  46. err:= FSpDelete(spec);
  47. OSErr2InOutRes(err);
  48. end
  49. else
  50. InOutRes:= 20;
  51. end
  52. else
  53. InOutRes:=res;
  54. end;
  55. procedure chdir(const s:string);[IOCheck];
  56. var
  57. spec, newDirSpec: FSSpec;
  58. err: OSErr;
  59. res: Integer;
  60. begin
  61. if (s='') or (InOutRes <> 0) then
  62. exit;
  63. res:= PathArgToFSSpec(s, spec);
  64. if (res = 0) or (res = 2) then
  65. begin
  66. { The fictive file x is appended to the directory name to make
  67. FSMakeFSSpec return a FSSpec to a file in the directory.
  68. Then by clearing the name, the FSSpec then
  69. points to the directory. It doesn't matter whether x exists or not.}
  70. err:= FSMakeFSSpec (spec.vRefNum, spec.parID, ':'+spec.name+':x', newDirSpec);
  71. if (err = noErr) or (err = fnfErr) then
  72. begin
  73. workingDirectorySpec:= newDirSpec;
  74. workingDirectorySpec.name:='';
  75. InOutRes:= 0;
  76. end
  77. else
  78. begin
  79. {E g if the directory doesn't exist.}
  80. OSErr2InOutRes(err);
  81. end;
  82. end
  83. else
  84. InOutRes:=res;
  85. end;
  86. procedure getDir (DriveNr: byte; var Dir: ShortString);
  87. var
  88. fullPath: AnsiString;
  89. pathHandleSize: Longint;
  90. begin
  91. if FSpGetFullPath(workingDirectorySpec, fullPath, false) <> noErr then
  92. Halt(3); {exit code 3 according to MPW}
  93. if Length(fullPath) <= 255 then {because dir is ShortString}
  94. InOutRes := 0
  95. else
  96. InOutRes := 1; //TODO Exchange to something better
  97. dir:= fullPath;
  98. end;