sysdir.inc 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. Procedure MkDir(Const s: String);[IOCheck];
  2. Var
  3. Buffer: Array[0..255] of Char;
  4. Begin
  5. {$warning TODO BeOS MkDir implementation}
  6. { If (s='') or (InOutRes <> 0) then
  7. exit;
  8. Move(s[1], Buffer, Length(s));
  9. Buffer[Length(s)] := #0;
  10. If Fpmkdir(@buffer, MODE_MKDIR)<0 Then
  11. Errno2Inoutres
  12. Else
  13. InOutRes:=0;
  14. }
  15. End;
  16. Procedure RmDir(Const s: String);[IOCheck];
  17. Var
  18. Buffer: Array[0..255] of Char;
  19. Begin
  20. {$warning TODO BeOS RmDir implementation}
  21. { if (s = '.') then
  22. InOutRes := 16;
  23. If (s='') or (InOutRes <> 0) then
  24. exit;
  25. Move(s[1], Buffer, Length(s));
  26. Buffer[Length(s)] := #0;
  27. If Fprmdir(@buffer)<0 Then
  28. Errno2Inoutres
  29. Else
  30. InOutRes:=0;
  31. }
  32. End;
  33. Procedure ChDir(Const s: String);[IOCheck];
  34. Var
  35. Buffer: Array[0..255] of Char;
  36. Begin
  37. {$warning TODO BeOS ChDir implementation}
  38. { If (s='') or (InOutRes <> 0) then
  39. exit;
  40. Move(s[1], Buffer, Length(s));
  41. Buffer[Length(s)] := #0;
  42. If Fpchdir(@buffer)<0 Then
  43. Errno2Inoutres
  44. Else
  45. InOutRes:=0;
  46. { file not exists is path not found under tp7 }
  47. if InOutRes=2 then
  48. InOutRes:=3;
  49. }
  50. End;
  51. { // $define usegetcwd}
  52. procedure getdir(drivenr : byte;var dir : shortstring);
  53. var
  54. {$ifndef usegetcwd}
  55. cwdinfo : stat;
  56. rootinfo : stat;
  57. thedir,dummy : string[255];
  58. dirstream : pdir;
  59. d : pdirent;
  60. name : string[255];
  61. thisdir : stat;
  62. {$endif}
  63. tmp : string[255];
  64. begin
  65. {$ifdef usegetcwd}
  66. Fpgetcwd(@tmp[1],4096);
  67. dir:=tmp;
  68. {$else}
  69. dir:='';
  70. thedir:='';
  71. dummy:='';
  72. { get root directory information }
  73. tmp := '/'+#0;
  74. if Fpstat(@tmp[1],rootinfo)<0 then
  75. Exit;
  76. repeat
  77. tmp := dummy+'.'+#0;
  78. { get current directory information }
  79. if Fpstat(@tmp[1],cwdinfo)<0 then
  80. Exit;
  81. tmp:=dummy+'..'+#0;
  82. { open directory stream }
  83. { try to find the current inode number of the cwd }
  84. dirstream:=Fpopendir(@tmp[1]);
  85. if dirstream=nil then
  86. exit;
  87. repeat
  88. name:='';
  89. d:=Fpreaddir(dirstream);
  90. { no more entries to read ... }
  91. if not assigned(d) then
  92. break;
  93. tmp:=dummy+'../'+strpas(d^.d_name) + #0;
  94. if (Fpstat(@tmp[1],thisdir)=0) then
  95. begin
  96. { found the entry for this directory name }
  97. if (cwdinfo.dev=thisdir.dev) and (cwdinfo.ino=thisdir.ino) then
  98. begin
  99. { are the filenames of type '.' or '..' ? }
  100. { then do not set the name. }
  101. if (not ((d^.d_name[0]='.') and ((d^.d_name[1]=#0) or
  102. ((d^.d_name[1]='.') and (d^.d_name[2]=#0))))) then
  103. name:='/'+strpas(d^.d_name);
  104. end;
  105. end;
  106. until (name<>'');
  107. if Fpclosedir(dirstream)<0 then
  108. Exit;
  109. thedir:=name+thedir;
  110. dummy:=dummy+'../';
  111. if ((cwdinfo.dev=rootinfo.dev) and (cwdinfo.ino=rootinfo.ino)) then
  112. begin
  113. if thedir='' then
  114. dir:='/'
  115. else
  116. dir:=thedir;
  117. exit;
  118. end;
  119. until false;
  120. {$endif}
  121. end;