-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprogram.c
More file actions
33 lines (26 loc) · 711 Bytes
/
Copy pathprogram.c
File metadata and controls
33 lines (26 loc) · 711 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
#include <stdio.h>
#include <unistd.h>
#include <error.h>
#include <stdlib.h>
#include <sys/ioctl.h>
/*
Please make sure you understand host.c
*/
int main(void){
int unread;
char *buf;
// wait for stdin
while(unread<1){
if(ioctl(STDIN_FILENO,FIONREAD,&unread)){
perror("ioctl");
exit(EXIT_FAILURE);
}
}
buf = (char*)malloc(sizeof(char)*(unread+1));
// read from stdin fd
read(STDIN_FILENO,buf,unread);
// output to stdout
printf("<HTML><HEAD><meta http-equiv=\"content-type\" content=\"text/html;charset=utf-8\">\n");
printf("<TITLE>I'm a example</TITLE>\n");
printf("<BODY>parameter: %s</BODY></HTML>\n",buf);
}