added decompress file to create text format from binary format

This commit is contained in:
MrBesen 2021-04-02 17:24:45 +02:00
parent 3da2c84c6e
commit b65807dc10
Signed by: MrBesen
GPG Key ID: 596B2350DCD67504
2 changed files with 55 additions and 1 deletions

3
.gitignore vendored
View File

@ -1,2 +1,3 @@
*.log
activity
activity
decompress

53
decompress.c Executable file
View File

@ -0,0 +1,53 @@
//#!/usr/local/bin/tcc -run
#include <stdio.h>
#include <unistd.h>
#include <fcntl.h>
#include <time.h>
int main(int argc, char** argv) {
if(argc != 3) {
fprintf(stderr, "Usage: %s infile outfile\n", argv[0]);
return 1;
}
int in = open(argv[1], O_RDONLY);
if(in == -1) {
fprintf(stderr, "%s: Could not open in-file: %s\n", argv[0], argv[1]);
return 1;
}
int out = open(argv[2], O_WRONLY | O_CREAT | O_APPEND, S_IRUSR | S_IWUSR);
if(out == -1) {
close(in);
fprintf(stderr, "%s: Could not open out-file: %s\n", argv[0], argv[2]);
return 1;
}
const size_t OUTBUFFSIZE = 10;
char outbuff[OUTBUFFSIZE];
time_t inbuff;
//read until end
while(1) {
size_t rc = read(in, &inbuff, sizeof(inbuff));
if(rc != sizeof(inbuff)) break;
//prnt to file
size_t count = dprintf(out, "%u\n", inbuff);
if(count == 0) {
fprintf(stderr, "%s: Writing failed\n", argv[0]);
break;
}
}
close(in);
close(out);
printf("Successfull!\n");
return 0;
}