sysdir.inc 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  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. type
  17. TDirFnType=function(name:pointer):longbool;stdcall;
  18. procedure dirfn(afunc : TDirFnType;const s:string);
  19. var
  20. buffer : array[0..255] of char;
  21. begin
  22. move(s[1],buffer,length(s));
  23. buffer[length(s)]:=#0;
  24. AllowSlash(pchar(@buffer));
  25. if not aFunc(@buffer) then
  26. begin
  27. errno:=GetLastError;
  28. Errno2InoutRes;
  29. end;
  30. end;
  31. function CreateDirectoryTrunc(name:pointer):longbool;stdcall;
  32. begin
  33. CreateDirectoryTrunc:=CreateDirectory(name,nil);
  34. end;
  35. procedure mkdir(const s:string);[IOCHECK];
  36. begin
  37. If (s='') or (InOutRes <> 0) then
  38. exit;
  39. dirfn(TDirFnType(@CreateDirectoryTrunc),s);
  40. end;
  41. procedure rmdir(const s:string);[IOCHECK];
  42. begin
  43. if (s ='.') then
  44. InOutRes := 16;
  45. If (s='') or (InOutRes <> 0) then
  46. exit;
  47. dirfn(TDirFnType(@RemoveDirectory),s);
  48. end;
  49. procedure chdir(const s:string);[IOCHECK];
  50. begin
  51. If (s='') or (InOutRes <> 0) then
  52. exit;
  53. dirfn(TDirFnType(@SetCurrentDirectory),s);
  54. if Inoutres=2 then
  55. Inoutres:=3;
  56. end;
  57. procedure GetDir (DriveNr: byte; var Dir: ShortString);
  58. const
  59. Drive:array[0..3]of char=(#0,':',#0,#0);
  60. var
  61. defaultdrive:boolean;
  62. DirBuf,SaveBuf:array[0..259] of Char;
  63. begin
  64. defaultdrive:=drivenr=0;
  65. if not defaultdrive then
  66. begin
  67. byte(Drive[0]):=Drivenr+64;
  68. GetCurrentDirectory(SizeOf(SaveBuf),SaveBuf);
  69. if not SetCurrentDirectory(@Drive) then
  70. begin
  71. errno := word (GetLastError);
  72. Errno2InoutRes;
  73. Dir := char (DriveNr + 64) + ':\';
  74. SetCurrentDirectory(@SaveBuf);
  75. Exit;
  76. end;
  77. end;
  78. GetCurrentDirectory(SizeOf(DirBuf),DirBuf);
  79. if not defaultdrive then
  80. SetCurrentDirectory(@SaveBuf);
  81. dir:=strpas(DirBuf);
  82. if not FileNameCaseSensitive then
  83. dir:=upcase(dir);
  84. end;
  85. {
  86. $Log$
  87. Revision 1.2 2005-02-14 17:13:32 peter
  88. * truncate log
  89. Revision 1.1 2005/02/06 13:06:20 peter
  90. * moved file and dir functions to sysfile/sysdir
  91. * win32 thread in systemunit
  92. }