sysdir.inc 2.9 KB

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