Some pre-POSIX systems don't have unistd.h (but e.g. lib.c).
[openssl.git] / crypto / des / read_pwd.c
index edfa456a43905ae5a20f8a4546041fec8edb1d90..7639fc0c3bedbbe2f0c8324d643adf9015817a1f 100644 (file)
  * [including the GNU Public Licence.]
  */
 
+#if !defined(MSDOS) && !defined(VMS) && !defined(WIN32)
+#include <openssl/opensslconf.h>
+#include OPENSSL_UNISTD
+/* If unistd.h defines _POSIX_VERSION, we conclude that we
+ * are on a POSIX system and have sigaction and termios. */
+#if defined(_POSIX_VERSION)
+
+# define SIGACTION
+# if !defined(TERMIOS) && !defined(TERMIO) && !defined(SGTTY)
+# define TERMIOS
+# endif
+
+#endif
+#endif
+
 /* #define SIGACTION */ /* Define this if you have sigaction() */
+
 #ifdef WIN16TTY
 #undef WIN16
 #undef _WINDOWS
 #include <graph.h>
 #endif
 
-#if defined(WIN32) && !defined(WINNT)
-#define WIN_CONSOLE_BUG
-#endif
-
-
 /* 06-Apr-92 Luke Brennan    Support for VMS */
 #include "des_locl.h"
+#include "cryptlib.h"
 #include <signal.h>
+#include <stdio.h>
 #include <string.h>
 #include <setjmp.h>
 #include <errno.h>
 
+#ifdef VMS                     /* prototypes for sys$whatever */
+#include <starlet.h>
+#ifdef __DECC
+#pragma message disable DOLLARID
+#endif
+#endif
+
 #ifdef WIN_CONSOLE_BUG
 #include <windows.h>
 #include <wincon.h>
@@ -158,7 +178,6 @@ struct IOSB {
 #define NX509_SIG 32
 #endif
 
-#ifndef NOPROTO
 static void read_till_nl(FILE *);
 static void recsig(int);
 static void pushsig(void);
@@ -166,16 +185,6 @@ static void popsig(void);
 #if defined(MSDOS) && !defined(WIN16)
 static int noecho_fgets(char *buf, int size, FILE *tty);
 #endif
-#else
-static void read_till_nl();
-static void recsig();
-static void pushsig();
-static void popsig();
-#if defined(MSDOS) && !defined(WIN16)
-static int noecho_fgets();
-#endif
-#endif
-
 #ifdef SIGACTION
  static struct sigaction savsig[NX509_SIG];
 #else
@@ -187,11 +196,8 @@ static int noecho_fgets();
 #endif
 static jmp_buf save;
 
-int des_read_pw_string(buf, length, prompt, verify)
-char *buf;
-int length;
-const char *prompt;
-int verify;
+int des_read_pw_string(char *buf, int length, const char *prompt,
+            int verify)
        {
        char buff[BUFSIZ];
        int ret;
@@ -203,8 +209,7 @@ int verify;
 
 #ifndef WIN16
 
-static void read_till_nl(in)
-FILE *in;
+static void read_till_nl(FILE *in)
        {
 #define SIZE 4
        char buf[SIZE+1];
@@ -216,12 +221,8 @@ FILE *in;
 
 
 /* return 0 if ok, 1 (or -1) otherwise */
-int des_read_pw(buf, buff, size, prompt, verify)
-char *buf;
-char *buff;
-int size;
-const char *prompt;
-int verify;
+int des_read_pw(char *buf, char *buff, int size, const char *prompt,
+            int verify)
        {
 #ifdef VMS
        struct IOSB iosb;
@@ -283,10 +284,10 @@ int verify;
        memcpy(&(tty_new),&(tty_orig),sizeof(tty_orig));
 #endif
 #ifdef VMS
-       status = SYS$ASSIGN(&terminal,&channel,0,0);
+       status = sys$assign(&terminal,&channel,0,0);
        if (status != SS$_NORMAL)
                return(-1);
-       status=SYS$QIOW(0,channel,IO$_SENSEMODE,&iosb,0,0,tty_orig,12,0,0,0,0);
+       status=sys$qiow(0,channel,IO$_SENSEMODE,&iosb,0,0,tty_orig,12,0,0,0,0);
        if ((status != SS$_NORMAL) || (iosb.iosb$w_value != SS$_NORMAL))
                return(-1);
 #endif
@@ -306,7 +307,7 @@ int verify;
        tty_new[0] = tty_orig[0];
        tty_new[1] = tty_orig[1] | TT$M_NOECHO;
        tty_new[2] = tty_orig[2];
-       status = SYS$QIOW(0,channel,IO$_SETMODE,&iosb,0,0,tty_new,12,0,0,0,0);
+       status = sys$qiow(0,channel,IO$_SETMODE,&iosb,0,0,tty_new,12,0,0,0,0);
        if ((status != SS$_NORMAL) || (iosb.iosb$w_value != SS$_NORMAL))
                return(-1);
 #endif
@@ -352,31 +353,26 @@ error:
        perror("fgets(tty)");
 #endif
        /* What can we do if there is an error? */
-#if defined(TTY_set) && !defined(VMS) 
+#if defined(TTY_set) && !defined(VMS)
        if (ps >= 2) TTY_set(fileno(tty),&tty_orig);
 #endif
 #ifdef VMS
        if (ps >= 2)
-               status = SYS$QIOW(0,channel,IO$_SETMODE,&iosb,0,0
+               status = sys$qiow(0,channel,IO$_SETMODE,&iosb,0,0
                        ,tty_orig,12,0,0,0,0);
 #endif
        
        if (ps >= 1) popsig();
        if (stdin != tty) fclose(tty);
 #ifdef VMS
-       status = SYS$DASSGN(channel);
+       status = sys$dassgn(channel);
 #endif
        return(!ok);
        }
 
 #else /* WIN16 */
 
-int des_read_pw(buf, buff, size, prompt, verify)
-char *buf;
-char *buff;
-int size;
-char *prompt;
-int verify;
+int des_read_pw(char *buf, char *buff, int size, char *prompt, int verify)
        { 
        memset(buf,0,size);
        memset(buff,0,size);
@@ -385,9 +381,15 @@ int verify;
 
 #endif
 
-static void pushsig()
+static void pushsig(void)
        {
        int i;
+#ifdef SIGACTION
+       struct sigaction sa;
+
+       memset(&sa,0,sizeof sa);
+       sa.sa_handler=recsig;
+#endif
 
        for (i=1; i<NX509_SIG; i++)
                {
@@ -400,7 +402,7 @@ static void pushsig()
                        continue;
 #endif
 #ifdef SIGACTION
-               sigaction(i,NULL,&savsig[i]);
+               sigaction(i,&sa,&savsig[i]);
 #else
                savsig[i]=signal(i,recsig);
 #endif
@@ -411,7 +413,7 @@ static void pushsig()
 #endif
        }
 
-static void popsig()
+static void popsig(void)
        {
        int i;
 
@@ -433,8 +435,7 @@ static void popsig()
                }
        }
 
-static void recsig(i)
-int i;
+static void recsig(int i)
        {
        longjmp(save,1);
 #ifdef LINT
@@ -443,10 +444,7 @@ int i;
        }
 
 #if defined(MSDOS) && !defined(WIN16)
-static int noecho_fgets(buf,size,tty)
-char *buf;
-int size;
-FILE *tty;
+static int noecho_fgets(char *buf, int size, FILE *tty)
        {
        int i;
        char *p;
@@ -479,11 +477,11 @@ FILE *tty;
  * usually a CR so this can be trouble. No STDIO fix seems to work but
  * flushing the console appears to do the trick.
  */
-                {
-                        HANDLE inh;
-                        inh = GetStdHandle(STD_INPUT_HANDLE);
-                        FlushConsoleInputBuffer(inh);
-                }
+               {
+                       HANDLE inh;
+                       inh = GetStdHandle(STD_INPUT_HANDLE);
+                       FlushConsoleInputBuffer(inh);
+               }
 #endif
        return(strlen(buf));
        }