sysdir.inc 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  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. {$ifdef WINCE}
  45. if (s ='..') then
  46. InOutRes := 5;
  47. {$endif WINCE}
  48. If (s='') or (InOutRes <> 0) then
  49. exit;
  50. dirfn(TDirFnType(@RemoveDirectory),s);
  51. end;
  52. procedure chdir(const s:string);[IOCHECK];
  53. begin
  54. {$ifndef WINCE}
  55. If (s='') or (InOutRes <> 0) then
  56. exit;
  57. dirfn(TDirFnType(@SetCurrentDirectory),s);
  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;
  98. {
  99. $Log: sysdir.inc,v $
  100. Revision 1.2 2005/02/14 17:13:32 peter
  101. * truncate log
  102. Revision 1.1 2005/02/06 13:06:20 peter
  103. * moved file and dir functions to sysfile/sysdir
  104. * win32 thread in systemunit
  105. }