All pastes #79491 Raw Edit

Mine

public c v1 · immutable
·published 2006-07-05 12:56 UTC
rendered paste body
int sgets(int sock, char *buf, int len){        char c;        char *s;        for (s = buf ; c != '\n' && s < &buf[len-1]; *s++ )        {                switch ( read(sock, &c, 1) )                {                case 1:                        *s = c;                        break;                case 0:         // Check for socket closure                        return 0;                case -1:        // check for read error                        return -1;                }        }        *s = '\0';        return 1;}