Why can't lseek the STDIN_FILENO? - Mailing list pgsql-general

From Wen Yi
Subject Why can't lseek the STDIN_FILENO?
Date
Msg-id tencent_BD37EEC28D51FACFA5B1EE6995C274087205@qq.com
Whole thread Raw
Responses Re: Why can't lseek the STDIN_FILENO?
Re: Why can't lseek the STDIN_FILENO?
List pgsql-general
Hi community,
I am testing the lseek & write & read, and I write the code like this:

/*
    lseek_test.c
        Test the lseek
    Wen Yi
*/
#include <unistd.h>
#include <fcntl.h>
int main()
{
    int fd = 0;
    char buffer[16] = {};
    write(STDIN_FILENO, "Hello world\n", sizeof("Hello world\n"));
    lseek(STDIN_FILENO, 0, SEEK_SET);
    read(STDIN_FILENO, buffer, sizeof(buffer));
    write(STDIN_FILENO, buffer, sizeof(buffer));
    return 0;
}

And I run the program ("Something Input" is my input content)

[beginnerc@bogon 学习 C语言]$ gcc lseek_test.c
[beginnerc@bogon 学习 C语言]$ ./a.out
Hello world
Something Input
Something Input
[beginnerc@bogon 学习 C语言]$

I really don't know, why the buffer's content not be "Hello world\n"? (I use the lseek to move the cursor to the beginning region)

Can someone give me some advice?
Thanks in advance!

Yours,
Wen Yi

pgsql-general by date:

Previous
From: Lorusso Domenico
Date:
Subject: Re: foreign keys on multiple parent table
Next
From: Tom Lane
Date:
Subject: Re: Why can't lseek the STDIN_FILENO?