#include <ioctl.h>
#include <stdio.h>
#include <unistd.h>
#include <string.h>
#include <limits.h>

extern int __mint;

char *
getpass(prompt)
	const char *prompt;
{
	static char buf[PASS_MAX + 1];
        char *ret;
	struct sgttyb oldsb, newsb;
	FILE *tty;
	int ttyfd = 0;

	fflush(stdin);
	tty = stdin;
	if (__mint) {
		if ((tty = fopen("U:\\DEV\\TTY", "r")) == NULL)
			return NULL;
	}
	ttyfd = fileno(tty);
	fflush(tty);
	gtty(ttyfd, &oldsb);
	newsb = oldsb;
	newsb.sg_flags &= ~ECHO;
	stty(ttyfd, &newsb);
	fputs(prompt, stderr);
	fflush(stderr);
	if ((ret = fgets(buf, PASS_MAX + 1, tty)) != 0)
	{
	  /* zap the newline */
	  if (buf[strlen(buf) - 1] == '\n')
	    buf[strlen(buf) - 1] = 0;
	}
	stty(ttyfd, &oldsb);
	if (__mint)
		(void) fclose(tty);
	return ret;
}
