【问题标题】:Declarations of p/invoke for file io and pseudo terminal文件 io 和伪终端的 p/invoke 声明
【发布时间】:2013-04-09 11:01:01
【问题描述】:

我想使用来自 mono 的文件 io 函数(打开、读取、写入)和伪终端(http://linux.die.net/man/4/pts)函数(grantpt、unlockpt、ptsname)。

翻译参数和返回值是微不足道的(不过,如果你能验证它们,我将不胜感激)但我找不到相应的库。

我的 Linux 发行版是 Arch Linux on ARM (Raspberry PI)。 由于 ARM 平台只有 32 位,我可以将 int32 用于 int/size_t 等

非常感谢。

internal class LinuxNativeMethods
{
    //int open(const char *pathname, int flags);
    [DllImport("??.so")]
    internal extern int open(string name, int flags);

    //ssize_t read(int fd, void *buf, size_t count);
    [DllImport("??.so")]
    internal extern int read(int fd, byte[] buffer, int length);

    //ssize_t write(int fd, const void *buf, size_t count); 
    [DllImport("??.so")]
    internal extern int write(int fd, byte[] buffer, int length);

    //int grantpt(int fd);
    [DllImport("??.so")]
    internal extern int grantpt(int fd);

    //int unlockpt(int fd);
    [DllImport("??.so")]
    internal extern int unlockpt(int fd);

    //i later marshall the pointer to a string
    //char *ptsname(int fd);
    [DllImport("??.so")]
    internal extern IntPtr ptsname(int fd);
}

【问题讨论】:

  • 您的问题与 pinvoke 有什么关系?您只是无法弄清楚库名称,这与 P/Invoke 无关。

标签: c# linux mono pinvoke


【解决方案1】:

函数似乎在 glibc 中,因此 dllimport 看起来像这样:

[DllImport("libc.so.6")]

【讨论】:

  • 谢谢。据我所知,libc.so 应该符号链接到 libc.so.6,对吗?
  • @LukasRieger 我也是这么想的,但是在我的电脑上没有找到。
猜你喜欢
  • 2011-04-20
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-03-22
  • 1970-01-01
  • 1970-01-01
  • 2011-03-23
相关资源
最近更新 更多