-/* $NetBSD: caesar.c,v 1.20 2005/11/19 14:22:21 rillig Exp $ */
+/* $NetBSD: caesar.c,v 1.22 2008/07/20 01:03:21 lukem Exp $ */
/*
* Copyright (c) 1989, 1993
#include <sys/cdefs.h>
#ifndef lint
-__COPYRIGHT("@(#) Copyright (c) 1989, 1993\n\
- The Regents of the University of California. All rights reserved.\n");
+__COPYRIGHT("@(#) Copyright (c) 1989, 1993\
+ The Regents of the University of California. All rights reserved.");
#endif /* not lint */
#ifndef lint
#if 0
static char sccsid[] = "@(#)caesar.c 8.1 (Berkeley) 5/31/93";
#else
-__RCSID("$NetBSD: caesar.c,v 1.20 2005/11/19 14:22:21 rillig Exp $");
+__RCSID("$NetBSD: caesar.c,v 1.22 2008/07/20 01:03:21 lukem Exp $");
#endif
#endif /* not lint */
errno = 0;
rot = strtol(arg, &endp, 10);
- if (!(errno == 0 && *endp == '\0' && 0 <= rot && rot <= INT_MAX)) {
- errx(EXIT_FAILURE, "bad rotation value: %s", arg);
- /* NOTREACHED */
- }
- return (int) rot;
+ if (errno == 0 && (arg[0] == '\0' || *endp != '\0'))
+ errno = EINVAL;
+ if (errno == 0 && (rot < 0 || rot > INT_MAX))
+ errno = ERANGE;
+ if (errno)
+ err(EXIT_FAILURE, "Bad rotation value `%s'", arg);
+ return (int)rot;
}
static void