plan9port

fork of plan9port with libvec, libstr and libsdb
Log | Files | Refs | README | LICENSE

readcons.3 (990B)


      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 .I netkey
     33 (see
     34 .MR passwd (1) ):
     35 .IP
     36 .EX
     37 pass = readcons("password", nil, 1);
     38 passtokey(key, pass);
     39 memset(pass, 0, strlen(pass));
     40 free(pass);
     41 for(;;){
     42 	chal = readcons("challenge", nil, 0);
     43 	sprint(buf, "%d", strtol(chal, 0, 10));
     44 	free(chal);
     45 	netcrypt(key, buf);
     46 	print("response: %s\n", buf);
     47 }
     48 .EE
     49 .SH SOURCE
     50 .B \*9/src/lib9/readcons.c