sysdir.inc 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. {
  2. $Id$
  3. This file is part of the Free Pascal run time library.
  4. Copyright (c) 1999-2000 by Florian Klaempfl and Pavel Ozerski
  5. member of the Free Pascal development team.
  6. FPC Pascal system unit for the Win32 API.
  7. See the file COPYING.FPC, included in this distribution,
  8. for details about the copyright.
  9. This program is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  12. **********************************************************************}
  13. {*****************************************************************************
  14. Directory Handling
  15. *****************************************************************************}
  16. procedure mkdir(const s:string);[IOCheck];
  17. var
  18. spec: FSSpec;
  19. createdDirID: Longint;
  20. err: OSErr;
  21. res: Integer;
  22. begin
  23. If (s='') or (InOutRes <> 0) then
  24. exit;
  25. res:= PathArgToFSSpec(s, spec);
  26. if (res = 0) or (res = 2) then
  27. begin
  28. err:= FSpDirCreate(spec, smSystemScript, createdDirID);
  29. OSErr2InOutRes(err);
  30. end
  31. else
  32. InOutRes:=res;
  33. end;
  34. procedure rmdir(const s:string);[IOCheck];
  35. var
  36. spec: FSSpec;
  37. err: OSErr;
  38. res: Integer;
  39. begin
  40. If (s='') or (InOutRes <> 0) then
  41. exit;
  42. res:= PathArgToFSSpec(s, spec);
  43. if (res = 0) then
  44. begin
  45. if IsDirectory(spec) then
  46. begin
  47. err:= FSpDelete(spec);
  48. OSErr2InOutRes(err);
  49. end
  50. else
  51. InOutRes:= 20;
  52. end
  53. else
  54. InOutRes:=res;
  55. end;
  56. procedure chdir(const s:string);[IOCheck];
  57. var
  58. spec, newDirSpec: FSSpec;
  59. err: OSErr;
  60. res: Integer;
  61. begin
  62. if (s='') or (InOutRes <> 0) then
  63. exit;
  64. res:= PathArgToFSSpec(s, spec);
  65. if (res = 0) or (res = 2) then
  66. begin
  67. { The fictive file x is appended to the directory name to make
  68. FSMakeFSSpec return a FSSpec to a file in the directory.
  69. Then by clearing the name, the FSSpec then
  70. points to the directory. It doesn't matter whether x exists or not.}
  71. err:= FSMakeFSSpec (spec.vRefNum, spec.parID, ':'+spec.name+':x', newDirSpec);
  72. if (err = noErr) or (err = fnfErr) then
  73. begin
  74. workingDirectorySpec:= newDirSpec;
  75. workingDirectorySpec.name:='';
  76. InOutRes:= 0;
  77. end
  78. else
  79. begin
  80. {E g if the directory doesn't exist.}
  81. OSErr2InOutRes(err);
  82. end;
  83. end
  84. else
  85. InOutRes:=res;
  86. end;
  87. procedure getDir (DriveNr: byte; var Dir: ShortString);
  88. var
  89. fullPath: AnsiString;
  90. pathHandleSize: Longint;
  91. begin
  92. if FSpGetFullPath(workingDirectorySpec, fullPath, false) <> noErr then
  93. Halt(3); {exit code 3 according to MPW}
  94. if Length(fullPath) <= 255 then {because dir is ShortString}
  95. InOutRes := 0
  96. else
  97. InOutRes := 1; //TODO Exchange to something better
  98. dir:= fullPath;
  99. end;
  100. {
  101. $Log$
  102. Revision 1.2 2005-02-14 17:13:30 peter
  103. * truncate log
  104. Revision 1.1 2005/02/07 21:30:12 peter
  105. * system unit updated
  106. Revision 1.1 2005/02/06 16:57:18 peter
  107. * threads for go32v2,os,emx,netware
  108. Revision 1.1 2005/02/06 13:06:20 peter
  109. * moved file and dir functions to sysfile/sysdir
  110. * win32 thread in systemunit
  111. }