READCONS(3)

πŸ“¦ version 0_git20260208, in alpine 3.24, arch rolling, nixos 26.05, nixpkgs unstable

πŸ’– 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. πŸŽ€