sysdir.inc 2.8 KB

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