uユ
Size: a a a
tr
tr
🎄T
FILE *input_file = fopen(argv[1], "rb");
if (input_file == NULL) {
perror("can't open input file.");
return EXIT_FAILURE;
}
FILE *output_file = fopen(argv[2], "wb");
if (output_file == NULL) {
fclose(input_file);
perror("can't open output file.");
return EXIT_FAILURE;
}
char *data;
size_t size;
int ret;
if ((ret = read_all(input_file, &data, &size) != SUCCESS)) {
const char *reason = “”;
fprintf(stderr, "%s: can't read all input file.", reason);
fclose(input_file);
fclose(output_file);
return EXIT_FAILURE;
}
char *test = NULL;
long transf = strtol(argv[3], &test, 10);
if (*test != '\0') {
fprintf(stderr, "%s: not int.", argv[3]);
fclose(input_file);
fclose(output_file);
free(data);
return EXIT_FAILURE;
}
struct picture *picture = malloc(sizeof(struct picture) + size * sizeof(char));
if(picture == NULL) {
fprintf(stderr, "NOMEM: can't allocate memory for picture.");
fclose(input_file);
fclose(output_file);
free(data);
return EXIT_FAILURE;
}
const char *end = NULL;
if ((ret = read_header(data, size, &picture->type, &picture->width, &picture->height, &picture->max_color,
&picture->pixel_size, &end)) != SUCCESS) {
const char *reason = “”;
fprintf(stderr, "%s:can't parse file.", reason);
fclose(input_file);
fclose(output_file);
free(data);
free(picture);
return EXIT_FAILURE;
}
memccpy(picture->data, end, sizeof(data[0]),
picture->height * picture->width * picture->pixel_size * (picture->type == P5 ? 1 : 3));
if (transform(picture, transf) != SUCCESS) {
fprintf(stderr, "transform error.");
fclose(input_file);
fclose(output_file);
free(data);
free(picture);
return EXIT_FAILURE;
}
🎄T
FILE *input_file = fopen(argv[1], "rb");
if (input_file == NULL) {
perror("can't open input file.");
return EXIT_FAILURE;
}
FILE *output_file = fopen(argv[2], "wb");
if (output_file == NULL) {
fclose(input_file);
perror("can't open output file.");
return EXIT_FAILURE;
}
char *data;
size_t size;
int ret;
if ((ret = read_all(input_file, &data, &size) != SUCCESS)) {
const char *reason = “”;
fprintf(stderr, "%s: can't read all input file.", reason);
fclose(input_file);
fclose(output_file);
return EXIT_FAILURE;
}
char *test = NULL;
long transf = strtol(argv[3], &test, 10);
if (*test != '\0') {
fprintf(stderr, "%s: not int.", argv[3]);
fclose(input_file);
fclose(output_file);
free(data);
return EXIT_FAILURE;
}
struct picture *picture = malloc(sizeof(struct picture) + size * sizeof(char));
if(picture == NULL) {
fprintf(stderr, "NOMEM: can't allocate memory for picture.");
fclose(input_file);
fclose(output_file);
free(data);
return EXIT_FAILURE;
}
const char *end = NULL;
if ((ret = read_header(data, size, &picture->type, &picture->width, &picture->height, &picture->max_color,
&picture->pixel_size, &end)) != SUCCESS) {
const char *reason = “”;
fprintf(stderr, "%s:can't parse file.", reason);
fclose(input_file);
fclose(output_file);
free(data);
free(picture);
return EXIT_FAILURE;
}
memccpy(picture->data, end, sizeof(data[0]),
picture->height * picture->width * picture->pixel_size * (picture->type == P5 ? 1 : 3));
if (transform(picture, transf) != SUCCESS) {
fprintf(stderr, "transform error.");
fclose(input_file);
fclose(output_file);
free(data);
free(picture);
return EXIT_FAILURE;
}