Convert tail(1) to use size_t

This commit is contained in:
FRIGN 2015-02-09 15:30:23 +01:00
parent 080a1ee833
commit 78f33ff069

9
tail.c
View File

@ -1,5 +1,6 @@
/* See LICENSE file for copyright and license details. */ /* See LICENSE file for copyright and license details. */
#include <limits.h> #include <limits.h>
#include <stdint.h>
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
@ -11,7 +12,7 @@
static int fflag = 0; static int fflag = 0;
static void static void
dropinit(FILE *fp, const char *str, long n) dropinit(FILE *fp, const char *str, size_t n)
{ {
char *buf = NULL; char *buf = NULL;
size_t size = 0; size_t size = 0;
@ -26,7 +27,7 @@ dropinit(FILE *fp, const char *str, long n)
} }
static void static void
taketail(FILE *fp, const char *str, long n) taketail(FILE *fp, const char *str, size_t n)
{ {
char **ring = NULL; char **ring = NULL;
long i, j; long i, j;
@ -64,7 +65,7 @@ main(int argc, char *argv[])
size_t n = 10, tmpsize; size_t n = 10, tmpsize;
int ret = 0, newline, many; int ret = 0, newline, many;
char *lines, *tmp; char *lines, *tmp;
void (*tail)(FILE *, const char *, long) = taketail; void (*tail)(FILE *, const char *, size_t) = taketail;
ARGBEGIN { ARGBEGIN {
case 'f': case 'f':
@ -72,7 +73,7 @@ main(int argc, char *argv[])
break; break;
case 'n': case 'n':
lines = EARGF(usage()); lines = EARGF(usage());
n = estrtonum(lines, 0, LONG_MAX); n = estrtonum(lines, 0, MIN(LLONG_MAX, SIZE_MAX));
if (lines[0] == '+') if (lines[0] == '+')
tail = dropinit; tail = dropinit;
break; break;