2017-08-22 18:05:18 +01:00
|
|
|
|
using System;
|
|
|
|
|
|
using System.Runtime.InteropServices;
|
|
|
|
|
|
using System.Text;
|
|
|
|
|
|
|
|
|
|
|
|
namespace osrepodbmgr.Core
|
|
|
|
|
|
{
|
|
|
|
|
|
public static class Symlinks
|
|
|
|
|
|
{
|
|
|
|
|
|
[DllImport("libc", CharSet = CharSet.Ansi, SetLastError = true)]
|
2017-12-30 00:32:21 +00:00
|
|
|
|
static extern int readlink(string path, IntPtr buf, int bufsize);
|
2017-08-22 18:05:18 +01:00
|
|
|
|
|
|
|
|
|
|
public static string ReadLink(string path)
|
|
|
|
|
|
{
|
|
|
|
|
|
IntPtr buf = Marshal.AllocHGlobal(16384);
|
|
|
|
|
|
|
|
|
|
|
|
int ret = readlink(path, buf, 16384);
|
|
|
|
|
|
|
2017-12-30 00:32:21 +00:00
|
|
|
|
if(ret < 0) return null;
|
2017-08-22 18:05:18 +01:00
|
|
|
|
|
|
|
|
|
|
byte[] target = new byte[ret];
|
|
|
|
|
|
Marshal.Copy(buf, target, 0, ret);
|
|
|
|
|
|
|
|
|
|
|
|
return Encoding.UTF8.GetString(target);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
[DllImport("libc", CharSet = CharSet.Ansi, SetLastError = true)]
|
2017-12-30 00:32:21 +00:00
|
|
|
|
static extern int symlink(string target, string path);
|
2017-08-22 18:05:18 +01:00
|
|
|
|
|
|
|
|
|
|
public static int Symlink(string target, string path)
|
|
|
|
|
|
{
|
|
|
|
|
|
return symlink(target, path);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|