Beispiel #1
0
int get_line(int fd, char *buf, int size)
{

    int i=0;
    char c = '\0';
    int n;

    while((i < size-1) && (c != '\n'))
    {
        n = readnbytes(fd, &c, 1);
        if (n > 0)
        {
            if (c == '\r')
            {
                n = readnbytes(fd, &c, 1);

                if ((n > 0) && (c == '\n'))
                {
                    //this is an \r\n endline for request
                    //we want to then return the line
                    //readnbytes(fd, &c, 1);
                    continue;
                } 
                else 
                {
                    c = '\n';
                }
            }
            buf[i] = c;
            i++;
        } 
        else
        {
            c = '\n';
        }
    }
    buf[i] = '\0';
    return i;
}
Beispiel #2
0
int get_line(int fd, char *buf, int size)
{

    int i=0;
    char c = '\0';
    int n;

    while((i < size-1) && (c != '\n'))
    {
        n = readnbytes(fd, &c, 1);
        if (n > 0)
        {
            if (c == '\r')
            {
                n = readnbytes(fd, &c, 1);

                if ((n > 0) && (c == '\n'))
                {
                    continue;
                } 
                else 
                {
                    c = '\n';
                }
            }
            buf[i] = c;
            i++;
        } 
        else
        {
            c = '\n';
        }
    }
    buf[i] = '\0';
    return i;
}