2
0

sysdir.inc 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  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:pointer):longbool;stdcall;
  17. procedure dirfn(afunc : TDirFnType;const s:string);
  18. var
  19. buffer : array[0..255] of char;
  20. begin
  21. move(s[1],buffer,length(s));
  22. buffer[length(s)]:=#0;
  23. AllowSlash(pchar(@buffer));
  24. if not aFunc(@buffer) then
  25. begin
  26. errno:=GetLastError;
  27. Errno2InoutRes;
  28. end;
  29. end;
  30. function CreateDirectoryTrunc(name:pointer):longbool;stdcall;
  31. begin
  32. CreateDirectoryTrunc:=CreateDirectory(name,nil);
  33. end;
  34. procedure mkdir(const s:string);[IOCHECK];
  35. begin
  36. If (s='') or (InOutRes <> 0) then
  37. exit;
  38. dirfn(TDirFnType(@CreateDirectoryTrunc),s);
  39. end;
  40. procedure rmdir(const s:string);[IOCHECK];
  41. begin
  42. if (s ='.') then
  43. InOutRes := 16;
  44. {$ifdef WINCE}
  45. if (s ='..') then
  46. InOutRes := 5;
  47. {$endif WINCE}
  48. If (s='') or (InOutRes <> 0) then
  49. exit;
  50. dirfn(TDirFnType(@RemoveDirectory),s);
  51. {$ifdef WINCE}
  52. if (Inoutres=3) and (Pos(DirectorySeparator, s)<2) then
  53. Inoutres:=2;
  54. {$endif WINCE}
  55. end;
  56. procedure chdir(const s:string);[IOCHECK];
  57. begin
  58. {$ifndef WINCE}
  59. If (s='') or (InOutRes <> 0) then
  60. exit;
  61. dirfn(TDirFnType(@SetCurrentDirectory),s);
  62. if Inoutres=2 then
  63. Inoutres:=3;
  64. {$else WINCE}
  65. InOutRes:=3;
  66. {$endif WINCE}
  67. end;
  68. procedure GetDir (DriveNr: byte; var Dir: ShortString);
  69. {$ifndef WINCE}
  70. const
  71. Drive:array[0..3]of char=(#0,':',#0,#0);
  72. var
  73. defaultdrive:boolean;
  74. DirBuf,SaveBuf:array[0..259] of Char;
  75. {$endif WINCE}
  76. begin
  77. {$ifndef WINCE}
  78. defaultdrive:=drivenr=0;
  79. if not defaultdrive then
  80. begin
  81. byte(Drive[0]):=Drivenr+64;
  82. GetCurrentDirectory(SizeOf(SaveBuf),SaveBuf);
  83. if not SetCurrentDirectory(@Drive) then
  84. begin
  85. errno := word (GetLastError);
  86. Errno2InoutRes;
  87. Dir := char (DriveNr + 64) + ':\';
  88. SetCurrentDirectory(@SaveBuf);
  89. Exit;
  90. end;
  91. end;
  92. GetCurrentDirectory(SizeOf(DirBuf),DirBuf);
  93. if not defaultdrive then
  94. SetCurrentDirectory(@SaveBuf);
  95. dir:=strpas(DirBuf);
  96. if not FileNameCaseSensitive then
  97. dir:=upcase(dir);
  98. {$else WINCE}
  99. Dir:='\';
  100. {$endif WINCE}
  101. end;