小编gbe*_*ber的帖子

从 pty 读取

我想在 Linux 上使用(Unix 98 风格的)伪 tty接收(以及以后的处理)write(1)wall(1)消息。我已经有了以下最小实现:

#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#include <unistd.h>
#include <errno.h>
#include <fcntl.h>
#include <signal.h>
#include <utempter.h>

#define BUF_LENGTH 1024

int
main (void)
{
    FILE *lf;
    int masterfd, slavefd;
    char *slave_name = NULL;
    char buf[BUF_LENGTH];
    size_t nbytes = sizeof(buf);
    ssize_t bytes_read;
    int exit_code = EXIT_SUCESS;

    if ((masterfd = posix_openpt (O_RDWR | O_NOCTTY)) == -1 
            || grantpt (masterfd) == -1
            || unlockpt (masterfd) == -1
            || (slave_name = ptsname (masterfd)) == NULL) …
Run Code Online (Sandbox Code Playgroud)

c pty

5
推荐指数
1
解决办法
2121
查看次数

标签 统计

c ×1

pty ×1