コード例 #1
0
static int login_prompt ( char *buf_name )
{
	char buf [1024];
	char *sp, *ep;
	int i;

	for(i=0; i<EMPTY_USERNAME_COUNT; i++) {
		print_login_prompt();

		if ( !fgets ( buf, sizeof( buf ) - 1, stdin ))
			return 0;

		if ( !strchr ( buf, '\n' ))
			return 0;

		for ( sp = buf; isspace ( *sp ); sp++ ) { }
		for ( ep = sp; isgraph ( *ep ); ep++ ) { }

		*ep = 0;
		safe_strncpy(buf_name, sp, USERNAME_SIZE);
		if(buf_name[0])
			return 1;
	}
	return 0;
}
コード例 #2
0
static void get_username_or_die(char *buf, int size_buf)
{
    int c, cntdown;

    cntdown = EMPTY_USERNAME_COUNT;
prompt:
    print_login_prompt();
    /* skip whitespace */
    do {
        c = getchar();
        if (c == EOF)
            exit(EXIT_FAILURE);
        if (c == '\n') {
            if (!--cntdown)
                exit(EXIT_FAILURE);
            goto prompt;
        }
    } while (isspace(c)); /* maybe isblank? */

    *buf++ = c;
    if (!fgets(buf, size_buf-2, stdin))
        exit(EXIT_FAILURE);
    if (!strchr(buf, '\n'))
        exit(EXIT_FAILURE);
    while ((unsigned char)*buf > ' ')
        buf++;
    *buf = '\0';
}