xref: /openbsd-src/gnu/usr.bin/cvs/vms/getpass.c (revision b6f6614ecf345cfa15dd59c3c624b2ef31ac6aa3)
1*b6f6614eStholo /* This program is free software; you can redistribute it and/or modify
2*b6f6614eStholo    it under the terms of the GNU General Public License as published by
3*b6f6614eStholo    the Free Software Foundation; either version 2, or (at your option)
4*b6f6614eStholo    any later version.
5*b6f6614eStholo 
6*b6f6614eStholo    This program is distributed in the hope that it will be useful,
7*b6f6614eStholo    but WITHOUT ANY WARRANTY; without even the implied warranty of
8*b6f6614eStholo    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
9*b6f6614eStholo    GNU General Public License for more details.  */
10*b6f6614eStholo 
11*b6f6614eStholo #undef TEST
12*b6f6614eStholo 
1350bf276cStholo #include <stdio.h>
14*b6f6614eStholo #include <iodef.h>
15*b6f6614eStholo #include <descrip.h>
16*b6f6614eStholo #include <starlet.h>
17*b6f6614eStholo #include <string.h>
18*b6f6614eStholo 
19*b6f6614eStholo #ifdef TEST
20*b6f6614eStholo #include <stdlib.h>
21*b6f6614eStholo static void error (int, int, char *);
22*b6f6614eStholo #else
23*b6f6614eStholo #  include "cvs.h"
24*b6f6614eStholo #endif
2550bf276cStholo 
2650bf276cStholo char *
getpass(char * prompt)2750bf276cStholo getpass (char *prompt)
2850bf276cStholo {
29*b6f6614eStholo     int status;
30*b6f6614eStholo     unsigned short chan;
31*b6f6614eStholo     static $DESCRIPTOR (sys_command, "SYS$COMMAND");
32*b6f6614eStholo     unsigned short iosb[4];
33*b6f6614eStholo     /* Arbitrary limit.  It doesn't seem worth going through multiple
34*b6f6614eStholo        SYS$QIOW calls and who knows what to get rid of it, I don't
35*b6f6614eStholo        think.  */
3650bf276cStholo     static char buf[2048];
3750bf276cStholo 
38*b6f6614eStholo     /* Try to ensure that we avoid stepping on whatever output has
39*b6f6614eStholo        been sent to stdout.  */
40*b6f6614eStholo     printf ("\n");
41*b6f6614eStholo     fflush (stdout);
4250bf276cStholo 
43*b6f6614eStholo     status = sys$assign (&sys_command, &chan, 0, 0);
44*b6f6614eStholo     if (!(status & 1))
45*b6f6614eStholo 	error (1, 0, "sys$assign failed in getpass");
46*b6f6614eStholo     status = sys$qiow (0, chan, IO$_READPROMPT | IO$M_NOECHO, &iosb, 0, 0,
47*b6f6614eStholo 		       buf, sizeof (buf) - 1, 0, 0, prompt, strlen (prompt));
48*b6f6614eStholo     if (!(status & 1))
49*b6f6614eStholo 	error (1, 0, "sys$qiow failed in getpass");
50*b6f6614eStholo     if (!(iosb[0] & 1))
51*b6f6614eStholo 	error (1, 0, "sys$qiow (iosb) failed in getpass");
52*b6f6614eStholo     buf[iosb[1]] = '\0';
53*b6f6614eStholo     status = sys$dassgn (chan);
54*b6f6614eStholo     if (!(status & 1))
55*b6f6614eStholo 	error (0, 0, "sys$dassgn failed in getpass");
56*b6f6614eStholo     /* Since there is no echo, we better go to the next line ourselves.  */
5750bf276cStholo     printf ("\n");
5850bf276cStholo     return buf;
5950bf276cStholo }
6050bf276cStholo 
61*b6f6614eStholo #ifdef TEST
6250bf276cStholo int
main()6350bf276cStholo main ()
6450bf276cStholo {
6550bf276cStholo     printf ("thank you for saying \"%s\"\n", getpass ("What'll it be? "));
6650bf276cStholo     return 0;
6750bf276cStholo }
68*b6f6614eStholo 
error(int x,int y,char * msg)69*b6f6614eStholo static void error (int x, int y, char *msg)
70*b6f6614eStholo {
71*b6f6614eStholo     printf ("error: %s\n", msg);
72*b6f6614eStholo     if (x)
73*b6f6614eStholo         exit (EXIT_FAILURE);
74*b6f6614eStholo }
7550bf276cStholo #endif
76