implement a "basic" getpass
[AROS.git] / compiler / posixc / getpass.c
blob60ef1fd60ec3f7315543293aa6d2991402fbb969
1 /*
2 Copyright © 2017, The AROS Development Team. All rights reserved.
3 $Id$
4 */
6 #include <sys/types.h>
8 #include <proto/exec.h>
10 #include <limits.h>
11 #include <string.h>
13 #include "__posixc_intbase.h"
15 /*****************************************************************************
17 NAME */
18 #include <unistd.h>
20 char * getpass(
22 /* SYNOPSIS */
23 const char *prompt)
25 /* FUNCTION
26 (obsolete) prompt for a password.
28 INPUTS
30 RESULT
32 NOTES
33 This function returns a pointer to a static buffer
34 containing (the first PASS_MAX bytes of) the password without the
35 trailing newline, terminated by a null byte ('\0').
37 The buffer may be overwritten by a subsequent call
39 EXAMPLE
41 BUGS
43 SEE ALSO
45 INTERNALS
47 ******************************************************************************/
49 struct PosixCBase *PosixCBase = __aros_getbase_PosixCBase();
50 struct PosixCIntBase *PosixCIntBase = (struct PosixCIntBase *)PosixCBase;
51 char *s;
53 /* quick and ugly... */
54 if ((prompt) &&
55 ((fputs(prompt, PosixCBase->_stdout) != EOF) &&
56 (fputs("\n", PosixCBase->_stdout) != EOF)))
58 fflush(PosixCBase->_stdout);
60 s = fgets(PosixCIntBase->passbuffer, PASS_MAX, PosixCBase->_stdin);
61 if (s)
63 /* strip trailing \n */
64 size_t sl = strlen(s);
65 if ( (sl > 0) && (s[sl-1] == '\n') )
67 s[sl-1] = '\0';
70 return s;