/*

This file comes from Solar Designer's John the Ripper.

*/

#include <stdio.h>
#include <string.h>

char *
fgetl(char *s, int size, FILE *stream)
{
        char *res, *pos;
        int c;

        if ((res = fgets(s, size, stream))) {
                if (!*res) return res;

                pos = res + strlen(res) - 1;
                if (*pos == '\n') {
                        *pos = 0;
                        if (pos > res)
				if (*--pos == '\r') *pos = 0;
                } else
			if ((c = getc(stream)) == '\n') {
				if (*pos == '\r') *pos = 0;
			} else
				while (c != EOF && c != '\n')
					c = getc(stream);
        }

        return (res);
}
