sysdir.inc 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  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. {$ifndef WINCE}
  51. If (s='') or (InOutRes <> 0) then
  52. exit;
  53. dirfn(TDirFnType(@SetCurrentDirectory),s);
  54. if Inoutres=2 then
  55. Inoutres:=3;
  56. {$else WINCE}
  57. InOutRes:=1;
  58. {$endif WINCE}
  59. end;
  60. procedure GetDir (DriveNr: byte; var Dir: ShortString);
  61. {$ifndef WINCE}
  62. const
  63. Drive:array[0..3]of char=(#0,':',#0,#0);
  64. {$endif WINCE}
  65. var
  66. defaultdrive:boolean;
  67. DirBuf,SaveBuf:array[0..259] of Char;
  68. begin
  69. {$ifndef WINCE}
  70. defaultdrive:=drivenr=0;
  71. if not defaultdrive then
  72. begin
  73. byte(Drive[0]):=Drivenr+64;
  74. GetCurrentDirectory(SizeOf(SaveBuf),SaveBuf);
  75. if not SetCurrentDirectory(@Drive) then
  76. begin
  77. errno := word (GetLastError);
  78. Errno2InoutRes;
  79. Dir := char (DriveNr + 64) + ':\';
  80. SetCurrentDirectory(@SaveBuf);
  81. Exit;
  82. end;
  83. end;
  84. GetCurrentDirectory(SizeOf(DirBuf),DirBuf);
  85. if not defaultdrive then
  86. SetCurrentDirectory(@SaveBuf);
  87. dir:=strpas(DirBuf);
  88. if not FileNameCaseSensitive then
  89. dir:=upcase(dir);
  90. {$else WINCE}
  91. Dir:='\';
  92. {$endif WINCE}
  93. end;
  94. {
  95. $Log: sysdir.inc,v $
  96. Revision 1.2 2005/02/14 17:13:32 peter
  97. * truncate log
  98. Revision 1.1 2005/02/06 13:06:20 peter
  99. * moved file and dir functions to sysfile/sysdir
  100. * win32 thread in systemunit
  101. }