On Samstag, 29. Januar 2022 16:03:32 CET Tomas Hajny via fpc-devel wrote:
> does it return individual characters, or does it
> return the whole line at once (the latter being the case for other FPC
> targets as far as I know)?

Just tried with a small test program, and the behaviour is a  bit strange. 
Fread(0, count, buf) returns when you either press return, or the count has 
been reached. However, if you press return, the return value does not include 
the CR, nor is that CR written to the buffer.

[code]
int main(void)
{
        char buf[10];
        long count;
        long i;
        
        count = Fread(0, sizeof(buf), buf);
        printf("count: %ld\n", count);
        for (i = 0; i < count; i++)
                printf("%02x ", (unsigned char)buf[i]);
        printf("\nPress key\n");
        Cnecin();
        return 0;
}
[/code]

The Window ReadFile function behaves totally differently there. It only 
returns when you press enter, and the buffer and count includes a CR/LF.

[code]
int main(void)
{
        long res;
        long i;
        char buf[10];
        DWORD outcount;

        res = ReadFile(GetStdHandle(STD_INPUT_HANDLE), buf, sizeof(buf), 
&outcount, NULL);
        printf("res: %ld, count: %ld\n", res, (long)outcount);
        for (i = 0; i < outcount; i++)
                printf("%02x ", (unsigned char)buf[i]);
        return 0;
}
[/code]
_______________________________________________
fpc-devel maillist  -  fpc-devel@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-devel

Reply via email to