+void record(int adapter_nr, char* output, int rectime) {
+ int fin, fout;
+ char input[256];
+ time_t start_time, current_time;
+ char buf[1316];
+ ssize_t rt, wt;
+ int size_remain;
+
+ fout = open(output, (O_WRONLY | O_CREAT | O_TRUNC));
+ if ( fout < 0 ) {
+ printf("output file open failed\n");
+ return;
+ }
+ sprintf(input, "/dev/dvb/adapter%d/dvr0", adapter_nr);
+ start_time = time(NULL);
+ fin = open(input, (O_RDONLY));
+ while ( rt = read(fin, buf, 1316) ) {
+ while ( wt = write(fout, buf, rt) ) {
+ rt -= wt;
+ if ( rt == 0 ) break;
+ if ( wt == 0 ) {
+ printf("output file write failed\n");
+ goto error;
+ }
+ }
+ current_time = time(NULL);
+ if ( current_time - start_time > rectime ) {
+ break;
+ }
+ }