Declarations of p/invoke for file io and pseudo terminal

别等时光非礼了梦想. 提交于 2019-12-24 06:57:43

问题


i want to use the file io functions (open, read, write) and the pseudo-terminal(http://linux.die.net/man/4/pts) functions (grantpt, unlockpt, ptsname) from mono.

translating the arguments and return values is trivial (still, i would appreciate it if you could verify them) but i can't find the corresponding librarys.

My linux distribution is Arch Linux on ARM (Raspberry PI). As the ARM Platform is only 32-Bit, i can just use int32 for int/size_t, etc

Thank you very much.

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);
}

回答1:


The functions appear to be in glibc, so the dllimport would look something like this:

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


来源:https://stackoverflow.com/questions/15900110/declarations-of-p-invoke-for-file-io-and-pseudo-terminal

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!