Not a member of Pastebin yet?
                        Sign Up,
                        it unlocks many cool features!                    
                - #include <stdio.h>
 - #include <io.h>
 - ...
 - if (isatty(fileno(stdin)))
 - printf( "stdin is a terminaln" );
 - else
 - printf( "stdin is a file or a pipen");
 - struct stat stats;
 - fstat(0, &stats);
 - if (S_ISCHR(stats.st_mode)) {
 - // Looks like a tty, so we're in interactive mode.
 - } else if (S_ISFIFO(stats.st_mode)) {
 - // Looks like a pipe, so we're in non-interactive mode.
 - }
 - #include <stdio.h>
 - #include <sys/stat.h>
 - #include <fcntl.h>
 - #include <termios.h>
 - #include <unistd.h>
 - #include <iostream>
 - using namespace std;
 - int main() {
 - char tty[L_ctermid+1] = {0};
 - ctermid(tty);
 - cout << "ID: " << tty << 'n';
 - int fd = ::open(tty, O_RDONLY);
 - if (fd < 0) perror("Could not open terminal");
 - else {
 - cout << "Opened terminaln";
 - struct termios term;
 - int r = tcgetattr(fd, &term);
 - if (r < 0) perror("Could not get attributes");
 - else cout << "Got attributesn";
 - }
 - if (isatty(fileno(stdin))) cout << "Is a terminaln";
 - else cout << "Is not a terminaln";
 - struct stat stats;
 - int r = fstat(fileno(stdin), &stats);
 - if (r < 0) perror("fstat failed");
 - else {
 - if (S_ISCHR(stats.st_mode)) cout << "S_ISCHRn";
 - else if (S_ISFIFO(stats.st_mode)) cout << "S_ISFIFOn";
 - else if (S_ISREG(stats.st_mode)) cout << "S_ISREGn";
 - else cout << "unknown stat moden";
 - }
 - return 0;
 - }
 - #include <stdio.h>
 - #include <sys/stat.h>
 - #include <fcntl.h>
 - #include <termios.h>
 - #include <unistd.h>
 - #include <iostream>
 - using namespace std;
 - int main() {
 - char tty[L_ctermid+1] = {0};
 - ctermid(tty);
 - cout << "ID: " << tty << 'n';
 - int fd = ::open(tty, O_RDONLY);
 - if (fd < 0) perror("Could not open terminal");
 - else {
 - cout << "Opened terminaln";
 - struct termios term;
 - int r = tcgetattr(fd, &term);
 - if (r < 0) perror("Could not get attributes");
 - else cout << "Got attributesn";
 - }
 - if (isatty(fileno(stdin))) cout << "Is a terminaln";
 - else cout << "Is not a terminaln";
 - struct stat stats;
 - int r = fstat(fileno(stdin), &stats);
 - if (r < 0) perror("fstat failed");
 - else {
 - if (S_ISCHR(stats.st_mode)) cout << "S_ISCHRn";
 - else if (S_ISFIFO(stats.st_mode)) cout << "S_ISFIFOn";
 - else if (S_ISREG(stats.st_mode)) cout << "S_ISREGn";
 - else cout << "unknown stat moden";
 - }
 - return 0;
 - }
 - /* Parse input from a file and execute it */
 - int
 - PyRun_AnyFileExFlags(FILE *fp, const char *filename, int closeit,
 - PyCompilerFlags *flags)
 - {
 - if (filename == NULL)
 - filename = "???";
 - if (Py_FdIsInteractive(fp, filename)) {
 - int err = PyRun_InteractiveLoopFlags(fp, filename, flags);
 - /*
 - * The file descriptor fd is considered ``interactive'' if either
 - * a) isatty(fd) is TRUE, or
 - * b) the -i flag was given, and the filename associated with
 - * the descriptor is NULL or "<stdin>" or "???".
 - */
 - int
 - Py_FdIsInteractive(FILE *fp, const char *filename)
 - {
 - if (isatty((int)fileno(fp)))
 - return 1;
 
Advertisement
 
                    Add Comment                
                
                        Please, Sign In to add comment