Search Postgresql Archives

Why can't lseek the STDIN_FILENO?

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Postgresql Jobs]     [Postgresql Admin]     [Postgresql Performance]     [Linux Clusters]     [PHP Home]     [PHP on Windows]     [Kernel Newbies]     [PHP Classes]     [PHP Databases]     [Postgresql & PHP]     [Yosemite]

  Powered by Linux