Why can't lseek the STDIN_FILENO?

From: Wen Yi <896634148(at)qq(dot)com>
To: pgsql-general <pgsql-general(at)lists(dot)postgresql(dot)org>
Subject: Why can't lseek the STDIN_FILENO?
Date: 2023-06-24 02:16:41
Message-ID: tencent_BD37EEC28D51FACFA5B1EE6995C274087205@qq.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Hi community,
I am testing the lseek &amp; write &amp; read, and I write the code like this:

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

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

[beginnerc(at)bogon 学习 C语言]$ gcc lseek_test.c
[beginnerc(at)bogon 学习 C语言]$ ./a.out
Hello world
Something Input
Something Input
[beginnerc(at)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

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Tom Lane 2023-06-24 02:40:05 Re: Why can't lseek the STDIN_FILENO?
Previous Message Lorusso Domenico 2023-06-23 23:08:24 Re: foreign keys on multiple parent table