cleanup: Add and use macro MIN().
[cparser] / input.c
diff --git a/input.c b/input.c
index b219d0a..693b180 100644 (file)
--- a/input.c
+++ b/input.c
@@ -1,5 +1,11 @@
+/*
+ * This file is part of cparser.
+ * Copyright (C) 2012 Matthias Braun <matze@braunis.de>
+ */
 #include "config.h"
 
+#include "adt/util.h"
+#include "diagnostic.h"
 #include "input.h"
 
 #include <ctype.h>
@@ -49,8 +55,7 @@ static size_t read_block(input_t *input, unsigned char *const read_buf,
        } else {
                assert(input->kind == INPUT_STRING);
                size_t len = strlen(input->in.string);
-               if (len > n)
-                       len = n;
+               len = MIN(len, n);
                memcpy(read_buf, input->in.string, len);
                input->in.string += len;
                return len;
@@ -301,7 +306,7 @@ static void choose_decoder(input_t *result, const char *encoding)
                        result->decode = i->decoder;
                        return;
                }
-               fprintf(stderr, "error: input encoding \"%s\" not supported\n", encoding);
+               errorf(NULL, "input encoding \"%s\" not supported", encoding);
        }
        result->decode = decode_utf8;
 }