READCONS(3)
π READCONS(3) β prompt console for input π
okay so this is the Library Functions Manual moment for readcons, and she is literally the console-prompt bestie. Let's go, bestie. π«Ά
πΈ NAME πΈ
readconsβ prompt console for input. That's the whole gig, and she ate. π
β¨ SYNOPSIS β¨
like, exactly this:
#include <u.h>
#include <libc.h>
char *readcons(char *prompt, char *def, int secret)
π DESCRIPTION π
okay so readcons prompts at the console for input. It returns a NUL-terminated buffer containing the input without a final newline. That buffer should be freed β and perhaps cleared first β when it's no longer needed.
If the user types an empty string (just a newline) and def is non-zero, then a copy of def is returned instead of the empty string. Default behavior? Iconic. π
If secret is non-zero, the input is not echoed to the screen. Spy-mode activated, no cap. π
bestie warning: free that buffer when you're done, and perhaps clear it first. It's giving responsible memory hygiene. π
π EXAMPLE π
A stripped-down version of netkey (see passwd(1)) β here's the example exactly as the page gives it:
pass = readcons("password", nil, 1);
passtokey(key, pass);
memset(pass, 0, strlen(pass));
free(pass);
for(;;){
chal = readcons("challenge", nil, 0);
sprint(buf, "%d", strtol(chal, 0, 10));
free(chal);
netcrypt(key, buf);
print("response: %s0, buf);
}
π SOURCE π
/src/lib9/readcons.c
xoxo, your readcons bestie π β this page is stamped READCONS(3) in the Library Functions Manual, source lives at /src/lib9/readcons.c, and the footer didn't hand me a date so I'm not inventing one. periodt. π
π¦ where this page comes from
- alpine 3.24: plan9port-doc 0_git20260208-r0 Β· LPL-1.02
- arch rolling: plan9port 20261021-2 Β· custom
- nixos 26.05: plan9port 0-unstable-2025-11-10
- nixos 26.05: plan9port-wayland 0-unstable-2025-11-26
- nixpkgs unstable: plan9port 0-unstable-2025-11-10
- nixpkgs unstable: plan9port-wayland 0-unstable-2025-11-26
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms