Ticket #1483: read_from_stdin.cpp

File read_from_stdin.cpp, 512 bytes (added by kaoutsis, 12 years ago)

the source file for the test-app

Line 
1#include <stdio.h>
2#include <unistd.h>
3#include <string.h>
4#include <sys/types.h>
5
6
7int
8main()
9{
10 char buffer[512];
11 size_t numOfButes = sizeof(buffer);
12 memset(buffer, '\0', numOfButes);
13 ssize_t bytesRead;
14
15 while (true) {
16 bytesRead = read(STDIN_FILENO, buffer, numOfButes);
17 if (!strncmp(buffer, "quit", 4)) {
18 printf("break, buffer : %s butesRead %d %d\n", buffer, bytesRead, (int)buffer[4]);
19 break;
20 }
21 write(STDOUT_FILENO, buffer, numOfButes);
22 memset(buffer, '\0', numOfButes);
23 }
24 return 0;
25}