/** * @brief 初始化终端 * * @return 成功返回0 否则返回-1 **/ si_t terminal_init() { struct termios new_term = term; si_t fd = open((char*)ctermid(NULL), O_RDONLY); if(fd < 0) { EGUI_PRINT_SYS_ERROR("failed to open termios. open()"); return -1; } if(tcgetattr(fd, &term) < 0) { EGUI_PRINT_SYS_ERROR("failed to get termios attribute. tcgetattr()"); return -1; } new_term.c_lflag = term.c_lflag & ~( ECHO | ECHOE | ECHOK | ECHONL); if(tcsetattr(fd, TCSAFLUSH, &new_term) < 0) { EGUI_PRINT_SYS_ERROR("failed to set termios attribute. tcgetattr()"); return -1; } return 0; }
String f_posix_ctermid() { String s = String(L_ctermid, ReserveString); char *buffer = s.bufferSlice().ptr; ctermid(buffer); s.setSize(strlen(buffer)); return s; }
int main(int argc, char *argv[]) { char *buf, line[BUFSIZ + 1]; if (argc > 1 && strcmp(argv[1], "-v") == 0) { fprintf(stderr, "::Stack dumps enabled::\n"); verbose = 2; } stackptr = &opstack[0]; /* initialize stack */ /* If stdin has data, hit it and quit it */ if (!isatty(fileno(stdin))) { fgets(line, BUFSIZ, stdin); parse_expression(line); freopen(ctermid(NULL), "r", stdin); return 0; } /* going interactive. fire up readline */ using_history(); while ((buf = readline("> ")) != NULL) { add_history(buf); strcpy(line, buf); parse_expression(line); stack_reset(); free(buf); } putchar('\n'); clear_history(); return 0; }
int main (void) { if (isatty (STDIN_FILENO)) fprintf (stdout, "stdin : %s\n", ttyname (STDIN_FILENO)); else fprintf (stdout, "stdin : Pas un terminal ! \n"); fprintf (stdout, "Terminal de contrôle : %s\n", ctermid (NULL)); return (0); }
/* * TermInfo.ctermid * * TermInfo.ctermid returns a pathname for the current controling terminal, * such as "/dev/tty". */ static VALUE rt_ctermid(VALUE self) { #ifdef HAVE_CTERMID char buf[L_ctermid]; return rb_str_new2(ctermid(buf)); #else return rb_str_new2("/dev/tty"); #endif }
CAMLprim value netsys_ctermid (value unit) { #ifdef HAVE_POSIX_TTY char *s; s = NULL; return copy_string(ctermid(s)); /* ctermid is always successful; however it can return an empty string */ #else invalid_argument("Netsys.ctermid not available"); #endif }
/* * pk_readline_unbuffered: **/ static GString * pk_readline_unbuffered (const gchar *prompt) { const gchar *tty_name; FILE *tty; GString *str = NULL; struct termios ts, ots; tty_name = ctermid (NULL); if (tty_name == NULL) { g_warning ("Cannot get terminal: %s", strerror (errno)); goto out; } tty = fopen (tty_name, "r+"); if (tty == NULL) { g_warning ("Error opening terminal for the process (`%s'): %s", tty_name, strerror (errno)); goto out; } fprintf (tty, "%s", prompt); fflush (tty); setbuf (tty, NULL); /* taken from polkitagenttextlistener.c */ tcgetattr (fileno (tty), &ts); ots = ts; ts.c_lflag &= ~(ECHONL); tcsetattr (fileno (tty), TCSAFLUSH, &ts); str = g_string_new (NULL); while (TRUE) { gint c; c = getc (tty); if (c == '\n') { /* ok, done */ break; } else if (c == EOF) { g_warning ("Got unexpected EOF."); break; } else { gchar c_safe = (gchar) c; g_string_append_len (str, (const gchar *) &c_safe, 1); } } tcsetattr (fileno (tty), TCSAFLUSH, &ots); putc ('\n', tty); fclose (tty); out: return str; }
String REG_POLY_FUN_HDR(sml_ctermid, Region r) { String rs; char *s; s = malloc(L_ctermid+1); if (!s) return NULL; ctermid(s); rs = REG_POLY_CALL(convertStringToML, r, s); free(s); return rs; }
char *getpasswd(char *prompt) { FILE *fp=NULL; if(NULL==(fp=fopen(ctermid(NULL),"r+"))) { perror("fopen");exit(EXIT_FAILURE); } printf("%s\n",ctermid(NULL)); setvbuf(fp, (char *) NULL, _IONBF, 0); sigset_t myset,setsave; sigemptyset(&myset); sigaddset(&myset,SIGINT); sigaddset(&myset,SIGTSTP); sigprocmask(SIG_BLOCK,&myset,&setsave); struct termios termnew,termsave; tcgetattr(fileno(fp),&termsave); termnew=termsave; termnew.c_lflag=termnew.c_lflag &~(ECHO|ECHOCTL|ECHOE|ECHOK); tcsetattr(fileno(fp),TCSAFLUSH,&termnew); fputs(prompt,fp); static char buf[PASSWD_LEN+1]; int c; char *ptr=buf; while((c=getc(fp))!=EOF&&c!='\0'&&c!='\n'&&c!='\r') { if(ptr<&buf[PASSWD_LEN]) *ptr++=c; fflush(fp); } *ptr='\0'; putc('\n',fp); tcsetattr(fileno(fp),TCSAFLUSH,&termsave); sigprocmask(SIG_BLOCK,&setsave,NULL); return buf; }
/** * @brief 清理终端 **/ void terminal_exit() { si_t fd = open((char*)ctermid(NULL), O_RDONLY); if(fd < 0) { EGUI_PRINT_SYS_ERROR("failed to open termios. open()"); } if(tcsetattr(fd, TCSAFLUSH, &term) < 0) { EGUI_PRINT_SYS_ERROR("failed to set termios attribute. tcgetattr()"); } }
int main() { char buffer[256]; int d = open("/device", O_RDWR); int f = open("/", O_RDONLY); char* result; result = ctermid(buffer); if (result) { printf("ctermid: %s\n", result); } else { printf("ctermid errno: %d\n", errno); errno = 0; } if (ttyname_r(d, buffer, 256) == 0) { printf("ttyname_r(d, ..., 256): %s\n", buffer); } else { printf("ttyname_r(d, ..., 256) errno: %d\n", errno); errno = 0; } if (ttyname_r(d, buffer, 2) == 0) { printf("ttyname_r(d, ..., 2): %s\n", buffer); } else { printf("ttyname_r(d, ..., 2) errno: %d\n", errno); errno = 0; } result = ttyname(d); if (result) { printf("ttyname(d): %s\n", result); } else { printf("ttyname(d) errno: %d\n", errno); errno = 0; } result = ttyname(f); if (result) { printf("ttyname(f): %s\n", result); } else { printf("ttyname(f) errno: %d\n", errno); errno = 0; } return 0; }
int main(){ char term[L_ctermid]; char my_term[L_ctermid]; char *ptr; struct termios tos; printf("cfgetispeed = 0x%x, cfgetospeed = 0x%x\n", cfgetispeed(&tos), cfgetospeed(&tos)); ptr = ctermid(term); printf("L_ctermid = 0x%x, ptr = %s\n", L_ctermid, ptr); ptr = my_ctermid(my_term); printf("L_ctermid = 0x%x, ptr = %s\n", L_ctermid, ptr); printf("isatty(STDIN_FILENO) = %d, ttyname(STDIN_FILENO) = %s\n", isatty(STDIN_FILENO), ttyname(STDIN_FILENO)); return 0; }
char* getpass(const char *prompt) { static char buf[MAX_PASS_LEN+1]; char *ptr; sigset_t sig, osig; struct termios ts, ots; FILE *fp; int c; if (NULL == (fp = fopen(ctermid(NULL), "r+"))) { perror("fopen"); return NULL; } setbuf(fp, buf); sigemptyset(&sig); sigaddset(&sig, SIGINT); sigaddset(&sig, SIGTSTP); sigprocmask(SIG_BLOCK, &sig, &osig); tcgetattr(fileno(fp), &ts); ots = ts; ts.c_lflag &= ~(ECHO | ECHOE | ECHOK | ECHONL); tcsetattr(fileno(fp), TCSAFLUSH, &ts); fputs(prompt, fp); ptr = buf; while ((EOF != (c = getc(fp))) && (c != '\n')) { if (ptr < &buf[MAX_PASS_LEN]) { *ptr++ = c; } } *ptr = 0; putc('\n', fp); tcsetattr(fileno(fp), TCSAFLUSH, &ots); sigprocmask(SIG_SETMASK, &osig, NULL); fclose(fp); return buf; }
char * getpass(const char *prompt) { static char buf[MAX_PASS_LEN + 1]; /* null byte at end */ char *ptr; sigset_t sig, sigsave; struct termios term, termsave; FILE *fp; int c; if ( (fp = fopen(ctermid(NULL), "r+")) == NULL) return(NULL); setbuf(fp, NULL); sigemptyset(&sig); /* block SIGINT & SIGTSTP, save signal mask */ sigaddset(&sig, SIGINT); sigaddset(&sig, SIGTSTP); sigprocmask(SIG_BLOCK, &sig, &sigsave); tcgetattr(fileno(fp), &termsave); /* save tty state */ term = termsave; /* structure copy */ term.c_lflag &= ~(ECHO | ECHOE | ECHOK | ECHONL); tcsetattr(fileno(fp), TCSAFLUSH, &term); fputs(prompt, fp); ptr = buf; while ( (c = getc(fp)) != EOF && c != '\n') { if (ptr < &buf[MAX_PASS_LEN]) *ptr++ = c; } *ptr = 0; /* null terminate */ putc('\n', fp); /* we echo a newline */ /* restore tty state */ tcsetattr(fileno(fp), TCSAFLUSH, &termsave); /* restore signal mask */ sigprocmask(SIG_SETMASK, &sigsave, NULL); fclose(fp); /* done with /dev/tty */ return(buf); }
static void dump_pgrps(void) { char terminal[L_ctermid]; int pid = getpid(); int sid = getsid(0); int pgrp = getpgrp(); int ppid = getppid(); int ppgid = getpgid(ppid); int pgid = getpgid(0); int psid = getsid(ppid); printf("CPID = %5d; CSID = %5d; CPGID = %5d; CPGRP = %5d\n", pid,sid, pgid, pgrp); printf("PPID = %5d; PSID = %5d; PPGID = %5d\n", ppid, psid, ppgid); printf("CTERMID = %s\n", ctermid(terminal)); int fd = open(terminal, O_RDONLY|O_NOCTTY); if (fd < 0) err_sysrem("Failed to open controlling terminal (%s)\n", terminal); else close(fd); }
/************************************************************************************************** PASSINPUT Prompts user to input password. Truncates all characters beyond PASS_MAX **************************************************************************************************/ char * passinput(const char *prompt) { static char buf[PASS_MAX + 1]; char *ptr; sigset_t sig, sigsave; struct termios term, termsave; FILE *fp; int c; buf[0] = '\0'; if (!isatty(STDIN_FILENO)) return (buf); if (!(fp = fopen(ctermid(NULL), "r+"))) return (buf); setbuf(fp, NULL); sigemptyset(&sig); sigaddset(&sig, SIGINT); sigaddset(&sig, SIGTSTP); sigprocmask(SIG_BLOCK, &sig, &sigsave); tcgetattr(fileno(fp), &termsave); term = termsave; term.c_lflag &= ~(ECHO | ECHOE | ECHOK | ECHONL); tcsetattr(fileno(fp), TCSAFLUSH, &term); fputs(prompt, stdout); fputs(": ", stdout); ptr = buf; while ((c = getc(fp)) != EOF && c != '\n') { if (ptr < &buf[PASS_MAX]) *ptr++ = c; } *ptr = 0; putc('\n', fp); tcsetattr(fileno(fp), TCSAFLUSH, &termsave); sigprocmask(SIG_SETMASK, &sigsave, NULL); fclose(fp); return (buf); }
int gettermios(struct termios *termp) { int fd; int firsterrno = 0; char termbuf[L_ctermid]; if (ctermid(termbuf) == NULL) { /* find the terminal name */ errno = ENODEV; return -1; } if ((fd = r_open2(termbuf, O_RDONLY)) == -1) /* open the terminal */ return -1; if (tcgetattr(fd, termp) == -1) /* get its termios */ firsterrno = errno; if ((r_close(fd) == -1) && !firsterrno) firsterrno = errno; if (firsterrno) { errno = firsterrno; return -1; } return 0; }
char* getpass(const char* prompt) { static char buf[MAX_PASS_LEN + 1]; /* null byte at end */ char *ptr; sigset_t sig, osig; struct termios ts, ots; FILE *fp; int c; if((fp = fopen(ctermid(NULL), "r+")) == NULL) return NULL; setbuf(fp, NULL); sigemptyset(&sig); sigaddset(&sig, SIGINT); /* block SIGINT */ sigaddset(&sig, SIGTSTP); /* block SIGTSTP */ sigprocmask(SIG_BLOCK, &sig, &osig); /* and save mask */ tcgetattr(fileno(fp), &ts); /* save tty state */ ots = ts; /* structure copy */ ts.c_lflag &= ~(ECHO | ECHOE | ECHOK | ECHONL); tcsetattr(fileno(fp), TCSAFLUSH, &ts); fputs(prompt, fp); ptr = buf; while((c = getc(fp)) != EOF && c != '\n') if(ptr < &buf[MAX_PASS_LEN]) *ptr++ = c; *ptr = 0; /* null terminate */ putc('\n', fp); /* we echo a newline */ tcsetattr(fileno(fp), TCSAFLUSH, &ots); /* restore TTY state */ sigprocmask(SIG_SETMASK, &osig, NULL); /* restore mask */ fclose(fp); /* done with /dev/tty */ return buf; }
int settermios(struct termios *termp) { int error; int fd; int firsterrno = 0; char termbuf[L_ctermid]; if (ctermid(termbuf) == NULL) { /* find the terminal name */ errno = ENODEV; return -1; } if ((fd = r_open2(termbuf, O_RDONLY)) == -1) /* open the terminal */ return -1; while (((error = tcsetattr(fd, TCSAFLUSH, termp)) == -1) && (errno == EINTR)) ; if (error) firsterrno = errno; if ((r_close(fd) == -1) && !firsterrno) firsterrno = errno; if (firsterrno) { errno = firsterrno; return -1; } return 0; }
int main(void) { char ctermid_name[L_ctermid]; ctermid(ctermid_name); /* * Most UNIX systems use /dev/tty as the ame of the controlling terminal, so * this function is intended to aid portability to other operating systems. */ printf("The name of the controller terminal is: \"%s\" " "(max len = %d)\n\n", ctermid_name, L_ctermid); printf("Testing to see which file descriptors refer to a terminal:\n"); printf("fd 0: %s\n", get_tty_name(STDIN_FILENO)); printf("fd 1: %s\n", get_tty_name(STDOUT_FILENO)); printf("fd 2: %s\n", get_tty_name(STDERR_FILENO)); printf("\nUse redirection (e.g. ./ttyinfo.o < /etc/passwd 2> /dev/null)\n" "to see how the results may change\n"); return 0; }
char * ctermid_r(char *s) { return (s) ? ctermid(s) : NULL; }
/** * @brief Function for accepting password input from users * * The functions reads chars from a buffered stream and store them in a buffer of * chars. If a file descriptor is supplied then, the password is read from * the associated stream, otherwise a new buffered stream is created and a * prompt is displayed to the user. * * @param prompt String displayed on the terminal to prompt the user for a * password or an encryption key * @param fd File descriptor to use to read the pasword from. If fd is set * to FD_INVALID, then a new stream is opened. * * @return NULL if a problem occured or the user killed the terminal (Ctrl-C)\n * otherwise the password - empty password is accepted. */ char* getpasswd(const char *prompt, int fd) { char *ptr; #ifndef WIN32 sigset_t sig, old_sig; struct termios ts, old_ts; FILE *fp; /* If a valid file descriptor is supplied, we try to open a stream from it */ if (FD_IS_VALID(fd)) { fp = fdopen(fd, "r"); if (fp == NULL) { log_msg(LOG_VERBOSITY_ERROR, "getpasswd() - " "Unable to create a stream from the file descriptor : %s", strerror(errno)); exit(EXIT_FAILURE); } } /* Otherwise we are going to open a new stream */ else { if((fp = fopen(ctermid(NULL), "r+")) == NULL) return(NULL); setbuf(fp, NULL); /* Setup blocks for SIGINT and SIGTSTP and save the original signal * mask. */ sigemptyset(&sig); sigaddset(&sig, SIGINT); sigaddset(&sig, SIGTSTP); sigprocmask(SIG_BLOCK, &sig, &old_sig); /* * Save current tty state for later restoration after we : * - disable echo of characters to the tty * - disable signal generation * - disable cannonical mode (input read line by line mode) */ tcgetattr(fileno(fp), &ts); old_ts = ts; ts.c_lflag &= ~(ECHO | ICANON | ISIG); tcsetattr(fileno(fp), TCSAFLUSH, &ts); fputs(prompt, fp); } #else _cputs(prompt); #endif /* Read the password */ ptr = read_passwd_from_stream(fp); #ifndef WIN32 /* If we used a new buffered stream */ if (FD_IS_VALID(fd) == 0) { /* we can go ahead and echo out a newline. */ putc(PW_LF_CHAR, fp); /* Restore our tty state and signal handlers. */ tcsetattr(fileno(fp), TCSAFLUSH, &old_ts); sigprocmask(SIG_BLOCK, &old_sig, NULL); } fclose(fp); #else /* In Windows, it would be a CR-LF */ _putch(PW_CR_CHAR); _putch(PW_LF_CHAR); #endif return (ptr); }
char * ctermid_r(char *s) { return (s != NULL ? ctermid(s) : NULL); }
static int Pctermid(lua_State *L) /** ctermid() */ { char b[L_ctermid]; lua_pushstring(L, ctermid(b)); return 1; }
rtems_task Init( rtems_task_argument ignored ) { int sc; pid_t pid; char *term_name_p; char term_name[32]; puts( "\n\n*** TERMIOS 02 TEST ***" ); puts( "tcdrain(12) - EBADF" ); sc = tcdrain(12); rtems_test_assert( sc == -1 ); rtems_test_assert( errno == EBADF ); puts( "tcdrain(stdin) - OK" ); sc = tcdrain(0); rtems_test_assert( !sc ); puts( "tcdrain(stdout) - OK" ); tcdrain(1); rtems_test_assert( !sc ); puts( "tcdrain(stderr) - OK" ); tcdrain(2); rtems_test_assert( !sc ); puts( "" ); /***** TEST TCFLOW *****/ puts( "tcflow(stdin, TCOOFF) - ENOTSUP" ); sc = tcflow( 0, TCOOFF ); rtems_test_assert( sc == -1 ); rtems_test_assert( errno = ENOTSUP ); puts( "tcflow(stdin, TCOON) - ENOTSUP" ); sc = tcflow( 0, TCOON ); rtems_test_assert( sc == -1 ); rtems_test_assert( errno = ENOTSUP ); puts( "tcflow(stdin, TCIOFF) - ENOTSUP" ); sc = tcflow( 0, TCIOFF ); rtems_test_assert( sc == -1 ); rtems_test_assert( errno = ENOTSUP ); puts( "tcflow(stdin, TCION) - ENOTSUP" ); sc = tcflow( 0, TCION ); rtems_test_assert( sc == -1 ); rtems_test_assert( errno = ENOTSUP ); puts( "tcflow(stdin, 22) - EINVAL" ); sc = tcflow( 0, 22 ); rtems_test_assert( sc == -1 ); rtems_test_assert( errno = EINVAL ); puts( "" ); /***** TEST TCFLUSH *****/ puts( "tcflush(stdin, TCIFLUSH) - ENOTSUP" ); sc = tcflush( 0, TCIFLUSH ); rtems_test_assert( sc == -1 ); rtems_test_assert( errno = ENOTSUP ); puts( "tcflush(stdin, TCOFLUSH) - ENOTSUP" ); sc = tcflush( 0, TCOFLUSH ); rtems_test_assert( sc == -1 ); rtems_test_assert( errno = ENOTSUP ); puts( "tcflush(stdin, TCIOFLUSH) - ENOTSUP" ); sc = tcflush( 0, TCIOFLUSH ); rtems_test_assert( sc == -1 ); rtems_test_assert( errno = ENOTSUP ); puts( "tcflush(stdin, 22) - EINVAL" ); sc = tcflush( 0, 22 ); rtems_test_assert( sc == -1 ); rtems_test_assert( errno = EINVAL ); puts( "" ); /***** TEST TCGETPGRP *****/ puts( "tcgetpgrp( 1 ) - OK" ); pid = tcgetpgrp(1); rtems_test_assert( pid == getpid() ); puts( "tcsetpgrp( 1, 3 ) - OK" ); sc = tcsetpgrp( 1, 3 ); rtems_test_assert( !sc ); puts( "" ); /***** TEST TCSENDBREAK *****/ puts( "tcsendbreak( 1, 0 ) - OK" ); sc = tcsendbreak( 1, 0 ); rtems_test_assert( !sc ); puts( "" ); /***** TEST CTERMID *****/ puts( "ctermid( NULL ) - OK" ); term_name_p = ctermid( NULL ); rtems_test_assert( term_name_p ); printf( "ctermid ==> %s\n", term_name_p ); puts( "ctermid( term_name ) - OK" ); term_name_p = ctermid( term_name ); rtems_test_assert( term_name_p == term_name ); printf( "ctermid ==> %s\n", term_name_p ); puts( "*** END OF TERMIOS 02 TEST ***" ); exit( 0 ); }
s48_ref_t scm_ctermid(s48_call_t call) { char* ret = ctermid(0); if (ret == NULL) s48_os_error_2(call, "scm_ctermid", errno, 0); return s48_enter_byte_string_2(call, ret); }
INT XargsPrompt ( VOID ) /*++ Routine Description: This routine prompts the user to enter Y or N. Arguments: None. Return Value: 0 if the command should proceed. Non-zero if the command should not proceed. --*/ { ssize_t BytesRead; CHAR Character; INT Result; int Terminal; CHAR TerminalName[L_ctermid]; fprintf(stderr, "?..."); fflush(NULL); if (ctermid(TerminalName) == NULL) { return 1; } Terminal = open(TerminalName, O_RDONLY); if (Terminal < 0) { return 1; } Result = 1; do { BytesRead = read(Terminal, &Character, 1); } while ((BytesRead == -1) && (errno == EINTR)); if (BytesRead <= 1) { close(Terminal); return 1; } if ((Character == 'y') || (Character == 'Y')) { Result = 0; } // // Read until the next newline. // while ((Character != '\n') && (BytesRead == 1)) { do { BytesRead = read(Terminal, &Character, 1); } while ((BytesRead == -1) && (errno == EINTR)); } close(Terminal); return Result; }
/* * Test the sigio operations by creating a child and registering that process * for SIGIO signals for the terminal. The main process forces a SIGIO * on the terminal by sending a charcter to that device. */ int main(int argc, char **argv) { int fd; int rc; int flags; pid_t pid; char key = '\r'; fd = open(ctermid(NULL), O_RDWR, 0); if (fd == -1) { perror("selinux_sigiotask:open"); exit(2); } /* * Spawn off the child process to handle the information protocol. */ if ((pid = fork()) < 0) { perror("selinux_sigiotask:fork"); exit(2); } /* * child process */ if (pid == 0) { /* Create the path to the executable the child will run */ char exname[FILENAME_MAX+1]; snprintf(exname, sizeof(exname), "%s/selinux_wait_io", dirname(argv[0])); printf("exname is %s\n", exname); if (execl(exname, "selinux_wait_io", (char *) 0) < 0) { perror("selinux_sigiotask:execl"); exit(2); } } /* * parent process */ rc = fcntl(fd, F_SETSIG, 0); if (rc == -1) { perror("selinux_sigiotask:F_SETSIG"); exit(2); } rc = fcntl(fd, F_SETOWN, pid); if (rc == -1) { perror("selinux_sigiotask:F_SETOWN"); exit(2); } flags = fcntl(fd, F_GETFL, 0); if (flags < 0) { perror("selinux_sigiotask:F_GETFL"); exit(2); } flags |= O_ASYNC; rc = fcntl(fd, F_SETFL, flags); if (rc == -1) { perror("selinux_sigiotask:F_SETFL"); exit(2); } sleep(1); /* Allow the child time to start up */ rc = ioctl(fd, TIOCSTI, &key); /* Send a key to the tty device */ if (rc == -1) { perror("selinux_sigiotask:write"); exit(2); } close(fd); wait(&rc); if (WIFEXITED(rc)) { /* exit status from child is normal? */ exit(WEXITSTATUS(rc)); } else { exit(1); } }
void UnistdCtermid(struct ParseState *Parser, struct Value *ReturnValue, struct Value **Param, int NumArgs) { ReturnValue->Val->Pointer = ctermid(Param[0]->Val->Pointer); }
int main() { if (0) { setvbuf(stdout, (char *)NULL, _IOLBF, 0); setvbuf(stderr, (char *)NULL, _IOLBF, 0); } if (1) { printf("ctermid(): %s\n", ctermid(0)); } if (1) { terminfo(0); terminfo(1); terminfo(2); } if (1) { fprintf(stdout, "0.1 stdout\n"); sleep(1); fprintf(stderr, "0.2 stderr\n"); sleep(1); fprintf(stdout, "0.3 stdout\n"); fflush(stdout); fflush(stderr); sleep(3); fprintf(stdout, "1.1 stdout\n"); fprintf(stderr, "1.2 stderr\n"); fprintf(stdout, "1.3 stdout\n"); sleep(1); } /* \r test */ if (1) { fprintf(stdout, "Progress: wait..."); fflush(stdout); sleep(1); fprintf(stdout, "\rProgress: done \n"); } /* stdin test */ if (1) { int nana; printf("Give me an integer: "); fflush(stdout); scanf("%d", &nana); printf("Value: %d\n", nana); } if (0) { char buf[1024]; int n; printf("reading from stdin...\n"); fflush(stdout); n = read(0, buf, sizeof(buf)); printf("done (%d)...\n", n); fflush(stdout); } if (0) { printf("Closing stdin...\n"); fflush(stdout); close(0); printf("done...\n"); fflush(stdout); } return 0; }