bump version to 1.2.0
[rofl0r-jobflow.git] / tests / stdin_to_file.c
blob214022d9f33e1e54be1004130b116cf6c5f1f1d8
1 #include "../../lib/include/stringptr.h"
2 #include <stdlib.h>
3 #include <stdio.h>
4 #include <unistd.h>
5 #include <fcntl.h>
6 #include <sys/stat.h>
8 int syntax() {
9 puts("prog name_of_file");
10 puts("writes stdin to supplied filename, in the fashion of the > shell operator.");
11 return 1;
14 int main(int argc, char** argv) {
15 stringptr line;
16 char buf[128 * 1024];
18 if(argc != 2) return syntax();
20 int fd = open(argv[1], O_WRONLY | O_CREAT | O_TRUNC, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
21 if(fd == -1) {
22 perror("file access");
23 return 1;
26 while(line = read_stdin_line(buf, sizeof(buf), 0), line.ptr) {
27 write(fd, line.ptr, line.size);
29 close(fd);
30 return 0;