Skip to content
This repository has been archived by the owner on Mar 23, 2020. It is now read-only.

Commit

Permalink
ng: add my_gets.h.
Browse files Browse the repository at this point in the history
  • Loading branch information
ysc3839 committed Feb 20, 2018
1 parent ce7757e commit fccc591
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
3 changes: 2 additions & 1 deletion main.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
#endif /* _MSC_VER */

#include "wslutil.h"
#include "my_gets.h"

#define DISTOR_NAME L"AOSC-OS"

Expand Down Expand Up @@ -43,7 +44,7 @@ HRESULT new_user(void)
wchar_t command[64];
do {
fputs("Enter new UNIX username: ", stdout);
gets_s(username, sizeof(username));
my_gets_s(username, sizeof(username));

if (strlen(username) == 0)
continue;
Expand Down
16 changes: 16 additions & 0 deletions my_gets.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
void my_gets_s(char* str, rsize_t n)
{
int c = getchar();
while (c != '\n' && c != EOF)
{
if (n > 1)
{
--n;
*str++ = c;
}

c = getchar();
}

*str = '\0';
}

0 comments on commit fccc591

Please sign in to comment.