Portál AbcLinuxu, 22. prosince 2025 13:38
/dev/tty?
#define _GNU_SOURCE
#include <stdlib.h>
#include <stdio.h>
/* tento komentář je věnován Leošovi za všechna <p> navíc */
int
main(void)
{
FILE *terminal;
char *buffer = NULL;
size_t size = 0;
terminal = fopen(ctermid(NULL), "r");
if (!terminal) {
fprintf(stderr, "Cannot open controlling terminal.\n");
return EXIT_FAILURE;
}
getline(&buffer, &size, terminal);
fputs("===== Read from terminal:\n", stderr);
fputs(buffer, stderr);
fputs("===== Read from stdin:\n", stderr);
while (getline(&buffer, &size, stdin) != -1)
fputs(buffer, stderr);
free(buffer);
return EXIT_SUCCESS;
}
Tiskni
Sdílej:
ISSN 1214-1267, (c) 1999-2007 Stickfish s.r.o.