blob: 39ef7d86bc60c133d0649b49104f097ae62360a7 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
|
unit gfx_utils;
{$mode objfpc}{$H+}
interface
uses
Classes, SysUtils;
{$I gfx_utils_intf.inc}
implementation
uses
baseunix;
// File utils
function ExtractTargetSymLinkPath(ALink: string): string;
begin
Result := fpReadLink(ALink);
// The code below requires the libc unit.
{
var
info : _stat;
.....
fullname := FDirectoryName + e.Name;
if lstat(PChar(fullname),info) = 0 then
begin
e.IsLink := ((sr.Mode and $F000) = $A000);
if e.IsLink then
begin
SetLength(e.LinkTarget, MAX_PATH); // length was 256
r := libc.readlink(PChar(fullname),@(e.LinkTarget[1]), sizeof(e.LinkTarget));
if r > 0 then
SetLength(e.LinkTarget, r)
else
e.LinkTarget := '';
libc.stat(PChar(fullname), info);
end;
}
end;
function FileIsSymlink(const AFilename: string): boolean;
begin
Result := (FpReadLink(AFilename) <> '');
end;
end.
|