mirror of
https://github.com/claunia/osrepodbmgr.git
synced 2025-12-16 19:14:25 +00:00
35 lines
952 B
C#
35 lines
952 B
C#
|
|
using System;
|
|||
|
|
using System.Runtime.InteropServices;
|
|||
|
|
using System.Text;
|
|||
|
|
|
|||
|
|
namespace osrepodbmgr.Core
|
|||
|
|
{
|
|||
|
|
public static class Symlinks
|
|||
|
|
{
|
|||
|
|
[DllImport("libc", CharSet = CharSet.Ansi, SetLastError = true)]
|
|||
|
|
internal static extern int readlink(string path, IntPtr buf, int bufsize);
|
|||
|
|
|
|||
|
|
public static string ReadLink(string path)
|
|||
|
|
{
|
|||
|
|
IntPtr buf = Marshal.AllocHGlobal(16384);
|
|||
|
|
|
|||
|
|
int ret = readlink(path, buf, 16384);
|
|||
|
|
|
|||
|
|
if(ret < 0)
|
|||
|
|
return null;
|
|||
|
|
|
|||
|
|
byte[] target = new byte[ret];
|
|||
|
|
Marshal.Copy(buf, target, 0, ret);
|
|||
|
|
|
|||
|
|
return Encoding.UTF8.GetString(target);
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
[DllImport("libc", CharSet = CharSet.Ansi, SetLastError = true)]
|
|||
|
|
internal static extern int symlink(string target, string path);
|
|||
|
|
|
|||
|
|
public static int Symlink(string target, string path)
|
|||
|
|
{
|
|||
|
|
return symlink(target, path);
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
}
|