File: getpass.c

package info (click to toggle)
dact 0.8.42-5
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, bullseye, sid, trixie
  • size: 1,412 kB
  • sloc: ansic: 5,923; sh: 2,748; makefile: 142
file content (31 lines) | stat: -rw-r--r-- 554 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
#include "dact.h"

#ifndef HAVE_GETPASS
#ifdef HAVE_UNISTD_H
#include <unistd.h>
#endif
#ifdef HAVE_STRING_H
#include <string.h>
#endif
#ifdef HAVE_STRINGS_H
#include <strings.h>
#endif
#ifdef HAVE_STDIO_H
#include <stdio.h>
#endif

#include "getpass.h"

char *getpass(const char *prompt) {
	static char buf[127];
	FILE *fp=NULL;

	fprintf(stderr, "%s", prompt);
	fp=fopen("/dev/tty", "w");
	if (fp==NULL) fp=stdin;
	fgets(buf, sizeof(buf), fp);
	while (buf[strlen(buf)-1]<' ') buf[strlen(buf)-1]='\0';
	if (fp!=stdin) fclose(fp);
	return(buf);
}
#endif