notatty.c

来自「unix环境高级编程的源代码」· C语言 代码 · 共 26 行

C
26
字号
#include    <stdio.h>
#include    <unistd.h>
#include    <sys/types.h>
#include	<sys/stat.h>
#include	<fcntl.h>
#include	<stdlib.h>

/*
 * The following prints errno=25 (ENOTTY) under 4.3BSD and SVR2,
 * when stdout is redirected to a file.
 * Under SVR4 and 44BSD it works OK.
 */

int
main(void)
{
    int           fd;
    extern int    errno;

    if ( (fd = open("/no/such/file", 0)) < 0) {
        printf("open error: ");
        printf("errno = %d\n", errno);
    }
    exit(0);
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?