Blob


1 .TH READCONS 3
2 .SH NAME
3 readcons \- prompt console for input
4 .SH SYNOPSIS
5 .B
6 #include <u.h>
7 .PP
8 .B
9 #include <libc.h>
10 .PP
11 .B
12 char *readcons(char *prompt, char *def, int secret)
13 .SH DESCRIPTION
14 .I Readcons
15 prompts at the console for input.
16 It returns a NUL-terminated buffer containing the input
17 without a final newline.
18 The buffer should be freed (and perhaps cleared first)
19 when no longer needed.
20 .PP
21 If the user types an empty string (just a newline) and
22 .I def
23 is non-zero, then a copy of
24 .I def
25 is returned instead of the empty string.
26 .PP
27 If
28 .I secret
29 is non-zero, the input is not echoed to the screen.
30 .SH EXAMPLE
31 A stripped-down version of
32 .IR netkey (1):
33 .IP
34 .EX
35 pass = readcons("password", nil, 1);
36 passtokey(key, pass);
37 memset(pass, 0, strlen(pass));
38 free(pass);
39 for(;;){
40 chal = readcons("challenge", nil, 0);
41 sprint(buf, "%d", strtol(chal, 0, 10));
42 free(chal);
43 netcrypt(key, buf);
44 print("response: %s\n", buf);
45 }
46 .EE
47 .SH SOURCE
48 .B \*9/src/lib9/readcons.c