| 1 |
{%MainUnit ../castleutils.pas} |
| 2 |
{ |
| 3 |
Copyright 2002-2018 Michalis Kamburelis. |
| 4 |
|
| 5 |
This file is part of "Castle Game Engine". |
| 6 |
|
| 7 |
"Castle Game Engine" is free software; see the file COPYING.txt, |
| 8 |
included in this distribution, for details about the copyright. |
| 9 |
|
| 10 |
"Castle Game Engine" is distributed in the hope that it will be useful, |
| 11 |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
| 13 |
|
| 14 |
---------------------------------------------------------------------------- |
| 15 |
} |
| 16 |
|
| 17 |
{ Some UNIX helpers } |
| 18 |
|
| 19 |
{$ifdef read_interface} |
| 20 |
|
| 21 |
{ Return the symlink target path. Like Libc.ReadLink or FpReadLink, |
| 22 |
but more comfortable, it returns a normal Pascal string. |
| 23 |
@raises EOSError In case of any failure (non-existing FileName etc.) } |
| 24 |
function CastleReadLink(const FileName: string): string; |
| 25 |
|
| 26 |
{$endif read_interface} |
| 27 |
|
| 28 |
{$ifdef read_implementation} |
| 29 |
|
| 30 |
function CastleReadLink(const FileName: string): string; |
| 31 |
var |
| 32 |
ReadLinkResult, NewLength: Integer; |
| 33 |
FileNameAnsi: AnsiString; |
| 34 |
begin |
| 35 |
NewLength := 100; |
| 36 |
repeat |
| 37 |
SetLength(Result, NewLength); |
| 38 |
FileNameAnsi := FileName; |
| 39 |
ReadLinkResult := {$ifdef FPC} FpReadlink {$else} ReadLink {$endif} |
| 40 |
(PAnsiChar(FileNameAnsi), Pointer(Result), NewLength); |
| 41 |
|
| 42 |
OSCheck( ReadLinkResult <> -1, 'readlink' ); |
| 43 |
|
| 44 |
if ReadLinkResult < NewLength then |
| 45 |
begin |
| 46 |
SetLength(Result, ReadLinkResult); |
| 47 |
Exit; |
| 48 |
end; |
| 49 |
|
| 50 |
NewLength := NewLength * 2; |
| 51 |
until false; |
| 52 |
end; |
| 53 |
|
| 54 |
procedure InitializationOSSpecific; |
| 55 |
begin |
| 56 |
end; |
| 57 |
|
| 58 |
procedure FinalizationOSSpecific; |
| 59 |
begin |
| 60 |
end; |
| 61 |
|
| 62 |
{$endif read_implementation} |