sysdir.inc 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. {
  2. This file is part of the Free Pascal run time library.
  3. Copyright (c) 1999-2000 by Florian Klaempfl and Pavel Ozerski
  4. member of the Free Pascal development team.
  5. FPC Pascal system unit for the Win32 API.
  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. type
  16. TDirFnType=function(name:PRtlChar):longbool;stdcall;
  17. procedure dirfn(afunc : TDirFnType;const s:RtlString);
  18. var
  19. buffer : RtlString;
  20. begin
  21. buffer:=s;
  22. DoDirSeparators(PRtlChar(buffer));
  23. if not aFunc(PRtlChar(buffer)) then
  24. begin
  25. errno:=GetLastError;
  26. Errno2InoutRes;
  27. end;
  28. end;
  29. function CreateDirectoryTrunc(name:PRtlChar):longbool;stdcall;
  30. begin
  31. CreateDirectoryTrunc:=CreateDirectory(_W(name),nil);
  32. end;
  33. procedure mkdir(const s:RtlString);[IOCHECK];
  34. begin
  35. If (s='') or (InOutRes <> 0) then
  36. exit;
  37. dirfn(TDirFnType(@CreateDirectoryTrunc),s);
  38. end;
  39. procedure rmdir(const s:RtlString);[IOCHECK];
  40. begin
  41. if (s ='.') then
  42. InOutRes := 16;
  43. {$ifdef WINCE}
  44. if (s ='..') then
  45. InOutRes := 5;
  46. {$endif WINCE}
  47. If (s='') or (InOutRes <> 0) then
  48. exit;
  49. dirfn(TDirFnType(@RemoveDirectory),s);
  50. {$ifdef WINCE}
  51. if (Inoutres=3) and (Pos(DirectorySeparator, s)<2) then
  52. Inoutres:=2;
  53. {$endif WINCE}
  54. end;
  55. procedure chdir(const s:RtlString);[IOCHECK];
  56. begin
  57. {$ifndef WINCE}
  58. If (s='') or (InOutRes <> 0) then
  59. exit;
  60. dirfn(TDirFnType(@SetCurrentDirectory),s);
  61. if Inoutres=2 then
  62. Inoutres:=3;
  63. {$else WINCE}
  64. InOutRes:=3;
  65. {$endif WINCE}
  66. end;
  67. procedure GetDir (DriveNr: byte; var Dir: RtlString);
  68. {$ifndef WINCE}
  69. const
  70. Drive:array[0..3]of RtlChar=(#0,':',#0,#0);
  71. var
  72. defaultdrive:boolean;
  73. DirBuf,SaveBuf:array[0..259] of WideChar;
  74. {$endif WINCE}
  75. begin
  76. {$ifndef WINCE}
  77. defaultdrive:=drivenr=0;
  78. if not defaultdrive then
  79. begin
  80. Drive[0]:=RtlChar(Drivenr+64);
  81. GetCurrentDirectory(High(SaveBuf)+1,SaveBuf);
  82. if not SetCurrentDirectory(@Drive) then
  83. begin
  84. errno := word (GetLastError);
  85. Errno2InoutRes;
  86. Dir := RtlChar (DriveNr + 64) + ':\';
  87. SetCurrentDirectory(@SaveBuf);
  88. Exit;
  89. end;
  90. end;
  91. GetCurrentDirectory(High(SaveBuf)+1,DirBuf);
  92. if not defaultdrive then
  93. SetCurrentDirectory(@SaveBuf);
  94. dir:=DirBuf;
  95. if not FileNameCaseSensitive then
  96. dir:=upcase(dir);
  97. {$else WINCE}
  98. Dir:='\';
  99. {$endif WINCE}
  100. end;