DataMuseum.dk

Presents historical artifacts from the history of:

Commodore CBM-900

This is an automatic "excavation" of a thematic subset of
artifacts from Datamuseum.dk's BitArchive.

See our Wiki for more about Commodore CBM-900

Excavated with: AutoArchaeologist - Free & Open Source Software.


top - download

⟦22daeda73⟧ TextFile

    Length: 1204 (0x4b4)
    Types: TextFile
    Notes: UNIX file
    Names: »getpass.c«

Derivation

└─⟦f27320a65⟧ Bits:30001972 Commodore 900 hard disk image with partial source code
    └─⟦f4b8d8c84⟧ UNIX V7 Filesystem
        └─ ⟦this⟧ »libc/gen/getpass.c« 

TextFile

/*
 * Coherent I/O Library.
 * getpass -- get a password from the controlling
 * terminal with echo suppressed.
 */

#include <stdio.h>
#include <sgtty.h>
#include <signal.h>

#define	NPASS	50		/* Characters in a password */

static	char	tty[] = "/dev/tty";
static	struct	sgttyb sg;
static	int	omode;
static	FILE	*ifp;
static	FILE	*ofp;
static	int	(*ofunc)();

char *
getpass(pp)
char *pp;
{
	static char passwd[NPASS+1];
	char *p;
	int   c;
	int reset();

	if ((ofp = fopen(tty, "r+w")) != NULL)
		ifp = ofp;
	else {
		ifp = stdin;
		ofp = stderr;
	}
	if ((ofunc = signal(SIGINT, reset)) != SIG_IGN)
		signal(SIGINT, reset);
	ioctl(fileno(ofp), TIOCGETP, &sg);
	omode = sg.sg_flags;
	sg.sg_flags &= ~ECHO;
	ioctl(fileno(ofp), TIOCSETP, &sg);
	while (*pp)
		putc(*pp++, ofp);
	p = passwd;
	while ((c=getc(ifp))!=EOF && c!='\n') {
		if (p < &passwd[NPASS])
			*p++ = c;
	}
	while (p < &passwd[NPASS])
		*p++ = '\0';
	reset();
	if (ifp != stdin)
		fclose(ifp);
	signal(SIGINT, ofunc);
	return (c==EOF ? NULL : passwd);
}

/*
 * Reset echo on and signal catching.
 */
static
reset()
{
	signal(SIGINT, ofunc);
	sg.sg_flags = omode;
	ioctl(fileno(ofp), TIOCSETP, &sg);
	if (omode & ECHO)
		putc('\n', ofp);
}