[prev in list] [next in list] [prev in thread] [next in thread] 

List:       postgresql-general
Subject:    Re: Why can't lseek the STDIN_FILENO?
From:       "=?gb18030?B?d2VuLXlp?=" <wen-yi () qq ! com>
Date:       2023-06-24 13:36:07
Message-ID: tencent_8D647B9C8A5BB3749FCB6E1DD22A96A90406 () qq ! com
[Download RAW message or body]

[Attachment #2 (text/plain)]

OK, I see, I'm so sorry for my action.
I will ask in cpplang slack community in the future.
And really thanks for your advice.



Your,
Wen Yi





------------------&nbsp;Original&nbsp;------------------
From:                                                                                 \
"John McKown"                                                                         \
<john.archie.mckown@gmail.com&gt;; Date:&nbsp;Sat, Jun 24, 2023 11:02 AM
To:&nbsp;
Cc:&nbsp;"pgsql-general"<pgsql-general@lists.postgresql.org&gt;;
Subject:&nbsp;Re: Why can't lseek the STDIN_FILENO?



My best advice would be to ask a C language question on a C language forum. This \
forum is really only for questions about the SQL language for the PostgreSQL \
database. I.e. no MariaDB, MySQL, MS SQL questions.


First, you didn't say what OS and she'll you're using. I an guessing BASH and \
Linux.&nbsp;


Second, you did NO error checking. I would purely guess that the lseek() is getting a \
return value of -1, probably with an error of ESPIPE.&nbsp;


This is probably a better \
explanation:&nbsp;https://unix.stackexchange.com/questions/502518/problems-when-test-whether-standard-input-is-capable-of-seeking



The bottom line from the above post is that STDIN is not seekable when it is a \
terminal.

On Fri, Jun 23, 2023, 21:17 Wen Yi <896634148@qq.com&gt; wrote:

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@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


[Attachment #3 (text/html)]

<meta http-equiv="Content-Type" content="text/html; charset=GB18030"><div>OK, I see, \
I'm so sorry for my action.</div><div>I will ask in cpplang slack community in the \
future.</div><div>And really thanks for your \
advice.<br></div><div><br></div><div>Your,</div><div>Wen Yi<br></div><div \
style="position: relative;"><div><br></div><div><br></div><div style="font-size: \
12px;font-family: Arial Narrow;padding:2px 0 2px \
0;">------------------&nbsp;Original&nbsp;------------------</div><div \
style="font-size: 12px;background:#efefef;padding:8px;"><div><b>From:</b>             \
"John McKown"                                                                         \
&lt;john.archie.mckown@gmail.com&gt;;</div><div><b>Date:</b>&nbsp;Sat, Jun 24, 2023 \
11:02 AM</div><div><b>To:</b>&nbsp;</div><div><b>Cc:</b>&nbsp;"pgsql-general"&lt;pgsql-general@lists.postgresql.org&gt;;<wbr></div><div><b>Subject:</b>&nbsp;Re: \
Why can't lseek the STDIN_FILENO?</div></div><div><br></div><div dir="auto"><div>My \
best advice would be to ask a C language question on a C language forum. This forum \
is really only for questions about the SQL language for the PostgreSQL database. I.e. \
no MariaDB, MySQL, MS SQL questions.</div><div dir="auto"><br></div><div \
dir="auto">First, you didn't say what OS and she'll you're using. I an guessing BASH \
and Linux.&nbsp;</div><div dir="auto"><br></div><div dir="auto">Second, you did NO \
error checking. I would purely guess that the lseek() is getting a return value of \
-1, probably with an error of ESPIPE.&nbsp;</div><div dir="auto"><br></div><div \
dir="auto">This is probably a better explanation:&nbsp;<a \
href="https://unix.stackexchange.com/questions/502518/problems-when-test-whether-standard-input-is-capable-of-seeking" \
rel="noreferrer noreferrer" \
target="_blank">https://unix.stackexchange.com/questions/502518/problems-when-test-whether-standard-input-is-capable-of-seeking</a></div><div \
dir="auto"><br></div><div dir="auto">The bottom line from the above post is that \
STDIN is not seekable when it is a terminal.<br><br><div class="gmail_quote" \
dir="auto"><div dir="ltr" class="gmail_attr">On Fri, Jun 23, 2023, 21:17 Wen Yi \
&lt;<a href="mailto:896634148@qq.com" rel="noreferrer noreferrer noreferrer" \
target="_blank">896634148@qq.com</a>&gt; wrote:<br></div><blockquote \
class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc \
solid;padding-left:1ex"><div>Hi community,</div><div>I am testing the lseek &amp; \
write &amp; read, and I write the code like \
this:</div><div><br></div><div>/*<br>&nbsp;&nbsp; &nbsp;lseek_test.c<br>&nbsp;&nbsp; \
&nbsp;&nbsp;&nbsp;&nbsp; Test the lseek<br>&nbsp;&nbsp; &nbsp;Wen \
Yi<br>*/<br>#include &lt;unistd.h&gt;<br>#include &lt;fcntl.h&gt;<br>int \
main()<br>{<br>&nbsp;&nbsp; &nbsp;int fd = 0;<br>&nbsp;&nbsp; &nbsp;char buffer[16] = \
{};<br>&nbsp;&nbsp; &nbsp;write(STDIN_FILENO, "Hello world\n", sizeof("Hello \
world\n"));<br>&nbsp;&nbsp; &nbsp;lseek(STDIN_FILENO, 0, SEEK_SET);<br>&nbsp;&nbsp; \
&nbsp;read(STDIN_FILENO, buffer, sizeof(buffer));<br>&nbsp;&nbsp; \
&nbsp;write(STDIN_FILENO, buffer, sizeof(buffer));<br>&nbsp;&nbsp; &nbsp;return \
0;<br>}</div><div><br></div><div>And I run the program ("Something Input" is my input \
content)<br></div><div><br></div><div>[beginnerc@bogon ѧϰ CÓïÑÔ]$ gcc \
lseek_test.c<br>[beginnerc@bogon ѧϰ CÓïÑÔ]$ ./a.out<br>Hello world<br>Something \
Input<br>Something Input<br>[beginnerc@bogon ѧϰ CÓïÑÔ]$ \
<br></div><div><br></div><div>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)</div><div><br></div><div>Can someone give me some advice?</div><div>Thanks in \
advance!</div><div><br></div><div>Yours,</div><div>Wen \
Yi<br></div></blockquote></div></div></div></div>



[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic