]> gitweb.hhaalo.de Git - sane-kds-s2000w-net.git/commitdiff
add convert with argv one
authorBastian Dehn <hhaalo@arcor.de>
Mon, 5 Feb 2024 15:39:24 +0000 (16:39 +0100)
committerBastian Dehn <hhaalo@arcor.de>
Mon, 5 Feb 2024 15:39:24 +0000 (16:39 +0100)
tools/convert.c

index d797e88750249865724020d448560deac405a4c2..1886348468fc9cffada4955b8a73796af9adfa51 100644 (file)
@@ -10,14 +10,20 @@ int main(int argc, char* argv[])
        blob.size = 0;
        FILE* fptr = NULL;
        size_t size = 0;
-       blob.data = malloc(sizeof(char));
+       blob.data = NULL;
 
-       fptr = fopen("test.jpg", "r");
+       fptr = fopen(argv[1], "r");
+       if (fptr == NULL) {
+               printf("file %s not found\n", argv[1]);
+               exit(1);
+       }
+
+       blob.data = malloc(sizeof(char));
        while(fread(blob.data, sizeof(char), 1, fptr)) {
                blob.size++;
        }
        fseek(fptr, 0L, SEEK_SET);
-       printf("file size in bufs: %i\n", blob.size);
+       printf("file size of %s: %i byts\n", argv[1], blob.size);
        free(blob.data);
        blob.data = NULL;
 
@@ -32,6 +38,7 @@ int main(int argc, char* argv[])
 
        fptr = fopen("output.pnm", "w");
        fwrite(output.data, output.size, 1, fptr);
+       printf("file size of output.pnm: %i bytes\n", output.size);
        fclose(fptr);
        fptr = NULL;