From: Wen Yi <896634148@qq.com>
To: pgsql-general <pgsql-general@lists.postgresql.org>
Subject: Why can't lseek the STDIN_FILENO?
Date: Sat, 24 Jun 2023 10:16:41 +0800
Message-ID: <tencent_BD37EEC28D51FACFA5B1EE6995C274087205@qq.com> (raw)
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
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-general@postgresql.org
Cc: 896634148@qq.com
Subject: Re: Why can't lseek the STDIN_FILENO?
In-Reply-To: <tencent_BD37EEC28D51FACFA5B1EE6995C274087205@qq.com>
References: <tencent_BD37EEC28D51FACFA5B1EE6995C274087205@qq.com>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox