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