image.c: use MAX

This commit is contained in:
Lennart Buhl 2013-11-02 23:14:08 +01:00
parent aec66da3b1
commit 556189ee3a
3 changed files with 10 additions and 8 deletions

View File

@ -1,5 +1,12 @@
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <sys/param.h> // MAX
#include "image.h" #include "image.h"
#define LINELEN 20000
char *readImage(const char* filename, int *cols, int *rows) { char *readImage(const char* filename, int *cols, int *rows) {
FILE *f = fopen(filename, "r"); FILE *f = fopen(filename, "r");
@ -11,7 +18,7 @@ char *readImage(const char* filename, int *cols, int *rows) {
if (!f) { if (!f) {
while (fgets(linebuf, LINELEN, f)) { while (fgets(linebuf, LINELEN, f)) {
int len = strlen(linebuf); int len = strlen(linebuf);
*cols = len>*cols?len:*cols; *cols = MAX(len, *cols);
(*rows)++; (*rows)++;
} }
@ -29,3 +36,4 @@ char *readImage(const char* filename, int *cols, int *rows) {
return ret; return ret;
} }

View File

@ -1,12 +1,6 @@
#ifndef __IMAGE #ifndef __IMAGE
#define __IMAGE #define __IMAGE
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define LINELEN 20000
char *readImage(const char* filename, int *cols, int *rows); char *readImage(const char* filename, int *cols, int *rows);
#endif #endif