contrib/openpam/lib/libpam/openpam_readline.c
/*
 * OpenPAM extension
 *
 * Read a line from a file.
 */
OpenPAM extension
Read a line from a file.
OpenPAM extension Read a line from a file .
char *
openpam_readline(FILE *f, int *lineno, size_t *lenp)
{
	char *line;
	size_t len, size;
	int ch;
	line = NULL;
	if (openpam_straddch(&line, &size, &len, 0) != 0)
		return (NULL);
	for (;;) {
		ch = fgetc(f);
		if (ch == '#') {
			do {
				ch = fgetc(f);
			} while (ch != EOF && ch != '\n');
		}
		if (ch == EOF) {
			break;
		}
		if (ch == '\n') {
			if (lineno != NULL)
				++*lineno;
			if (len == 0)
				continue;
			if (line[len - 1] == '\\') {
				line[--len] = '\0';
				continue;
			}
			break;
		}
		if (openpam_straddch(&line, &size, &len, ch) != 0)
			goto fail;
	}
	if (len == 0)
		goto fail;
	if (lenp != NULL)
		*lenp = len;
	return (line);
fail:
	FREE(line);
	return (NULL);
}
char * openpam_readline ( FILE * f , int * lineno , size_t * lenp ) { char * line ; size_t len , size ; int ch ; line = NULL ; if ( openpam_straddch ( & line , & size , & len , 0 ) != 0 ) return ( NULL ) ; for ( ; ; ) { ch = fgetc ( f ) ; if ( ch == ' ' ) { do { ch = fgetc ( f ) ; } while ( ch != EOF && ch != ' \n ' ) ; } if ( ch == EOF ) { break ; } if ( ch == ' \n ' ) { if ( lineno != NULL ) ++ * lineno ; if ( len == 0 ) continue ; if ( line [ len - 1 ] == ' \\ ' ) { line [ -- len ] = ' \0 ' ; continue ; } break ; } if ( openpam_straddch ( & line , & size , & len , ch ) != 0 ) goto fail ; } if ( len == 0 ) goto fail ; if ( lenp != NULL ) * lenp = len ; return ( line ) ; fail : FREE ( line ) ; return ( NULL ) ; }
OpenPAM extension
 Read a line from a file.
OpenPAM extension Read a line from a file .
/* strip comment */ /* eof */ /* done */ /* eol */ /* skip blank lines */ /* continuation */ /* done */ /* anything else */