sysdir.inc 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  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. If (s='') or (InOutRes <> 0) then
  45. exit;
  46. dirfn(TDirFnType(@RemoveDirectory),s);
  47. end;
  48. procedure chdir(const s:string);[IOCHECK];
  49. begin
  50. If (s='') or (InOutRes <> 0) then
  51. exit;
  52. dirfn(TDirFnType(@SetCurrentDirectory),s);
  53. if Inoutres=2 then
  54. Inoutres:=3;
  55. end;
  56. procedure GetDir (DriveNr: byte; var Dir: ShortString);
  57. const
  58. Drive:array[0..3]of char=(#0,':',#0,#0);
  59. var
  60. defaultdrive:boolean;
  61. DirBuf,SaveBuf:array[0..259] of Char;
  62. begin
  63. defaultdrive:=drivenr=0;
  64. if not defaultdrive then
  65. begin
  66. byte(Drive[0]):=Drivenr+64;
  67. GetCurrentDirectory(SizeOf(SaveBuf),SaveBuf);
  68. if not SetCurrentDirectory(@Drive) then
  69. begin
  70. errno := word (GetLastError);
  71. Errno2InoutRes;
  72. Dir := char (DriveNr + 64) + ':\';
  73. SetCurrentDirectory(@SaveBuf);
  74. Exit;
  75. end;
  76. end;
  77. GetCurrentDirectory(SizeOf(DirBuf),DirBuf);
  78. if not defaultdrive then
  79. SetCurrentDirectory(@SaveBuf);
  80. dir:=strpas(DirBuf);
  81. if not FileNameCaseSensitive then
  82. dir:=upcase(dir);
  83. end;