Magellan Linux

Diff of /trunk/mkinitrd-magellan/busybox/libbb/bb_askpass.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 983 by niro, Fri Apr 24 18:33:46 2009 UTC revision 984 by niro, Sun May 30 11:32:42 2010 UTC
# Line 8  Line 8 
8   * Licensed under GPLv2 or later, see file LICENSE in this tarball for details.   * Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
9   */   */
10    
 #include <termios.h>  
   
11  #include "libbb.h"  #include "libbb.h"
12    
13  /* do nothing signal handler */  /* do nothing signal handler */
# Line 17  static void askpass_timeout(int UNUSED_P Line 15  static void askpass_timeout(int UNUSED_P
15  {  {
16  }  }
17    
18  char* FAST_FUNC bb_askpass(int timeout, const char *prompt)  char* FAST_FUNC bb_ask_stdin(const char *prompt)
19    {
20     return bb_ask(STDIN_FILENO, 0, prompt);
21    }
22    char* FAST_FUNC bb_ask(const int fd, int timeout, const char *prompt)
23  {  {
24   /* Was static char[BIGNUM] */   /* Was static char[BIGNUM] */
25   enum { sizeof_passwd = 128 };   enum { sizeof_passwd = 128 };
# Line 32  char* FAST_FUNC bb_askpass(int timeout, Line 34  char* FAST_FUNC bb_askpass(int timeout,
34   passwd = xmalloc(sizeof_passwd);   passwd = xmalloc(sizeof_passwd);
35   memset(passwd, 0, sizeof_passwd);   memset(passwd, 0, sizeof_passwd);
36    
37   tcgetattr(STDIN_FILENO, &oldtio);   tcgetattr(fd, &oldtio);
38   tcflush(STDIN_FILENO, TCIFLUSH);   tcflush(fd, TCIFLUSH);
39   tio = oldtio;   tio = oldtio;
40    #ifndef IUCLC
41    # define IUCLC 0
42    #endif
43   tio.c_iflag &= ~(IUCLC|IXON|IXOFF|IXANY);   tio.c_iflag &= ~(IUCLC|IXON|IXOFF|IXANY);
44   tio.c_lflag &= ~(ECHO|ECHOE|ECHOK|ECHONL|TOSTOP);   tio.c_lflag &= ~(ECHO|ECHOE|ECHOK|ECHONL|TOSTOP);
45   tcsetattr_stdin_TCSANOW(&tio);   tcsetattr_stdin_TCSANOW(&tio);
# Line 50  char* FAST_FUNC bb_askpass(int timeout, Line 55  char* FAST_FUNC bb_askpass(int timeout,
55   }   }
56    
57   fputs(prompt, stdout);   fputs(prompt, stdout);
58   fflush(stdout);   fflush_all();
59   ret = NULL;   ret = NULL;
60   /* On timeout or Ctrl-C, read will hopefully be interrupted,   /* On timeout or Ctrl-C, read will hopefully be interrupted,
61   * and we return NULL */   * and we return NULL */
62   if (read(STDIN_FILENO, passwd, sizeof_passwd - 1) > 0) {   if (read(fd, passwd, sizeof_passwd - 1) > 0) {
63   ret = passwd;   ret = passwd;
64   i = 0;   i = 0;
65   /* Last byte is guaranteed to be 0   /* Last byte is guaranteed to be 0
# Line 72  char* FAST_FUNC bb_askpass(int timeout, Line 77  char* FAST_FUNC bb_askpass(int timeout,
77    
78   tcsetattr_stdin_TCSANOW(&oldtio);   tcsetattr_stdin_TCSANOW(&oldtio);
79   bb_putchar('\n');   bb_putchar('\n');
80   fflush(stdout);   fflush_all();
81   return ret;   return ret;
82  }  }

Legend:
Removed from v.983  
changed lines
  Added in v.984