- 论坛徽章:
- 0
|
#include <sys/poll.h>
#include <unistd.h>
#include <stdlib.h>
#include <stdio.h>
#define BUFFSIZE 80
void err_msg(const char *p_error);
int main(void)
{
struct pollfd fdarray[1];
char buf[BUFFSIZE];
int readn;
// initial structure member
fdarray[0].fd = STDIN_FILENO;
fdarray[0].events = POLLIN;
fdarray[0].revents = 0;
if (poll(fdarray, 1, 0) == -1)
err_msg("poll error.\n" ;
if (fdarray[0].revents) { // I think question is here
if ((readn = read(STDIN_FILENO, buf, BUFFSIZE)) < 0)
err_msg("read error.\n" ;
if (write(STDOUT_FILENO, buf, readn) != readn)
err_msg("write error.\n" ;
}
exit(0);
}
void err_msg(const char *p_error)
{
fprintf(stderr, p_error);
exit(1);
}
====================
I want to test STDIN_FILENO desciptor, I think STDIN_FILENO descriptor is not block, but why I can't input string, program already over. where error?
please help me, sorry My system have no chinese input and my english is very poor, sorry!
 |
|