-/* $NetBSD: caesar.c,v 1.5 1997/10/10 12:07:11 lukem Exp $ */
+/* $NetBSD: caesar.c,v 1.8 1999/07/21 04:04:21 hubertf Exp $ */
/*
* Copyright (c) 1989, 1993
#if 0
static char sccsid[] = "@(#)caesar.c 8.1 (Berkeley) 5/31/93";
#else
-__RCSID("$NetBSD: caesar.c,v 1.5 1997/10/10 12:07:11 lukem Exp $");
+__RCSID("$NetBSD: caesar.c,v 1.8 1999/07/21 04:04:21 hubertf Exp $");
#endif
#endif /* not lint */
#include <ctype.h>
+#include <err.h>
#include <errno.h>
#include <math.h>
#include <stdio.h>
int main __P((int, char *[]));
-void printit __P((char *));
+void printit __P((char *)) __attribute__((__noreturn__));
int
main(argc, argv)
char *inbuf;
int obs[26], try, winner;
+ /* revoke setgid privileges */
+ setregid(getgid(), getgid());
+
winnerdot = 0;
if (argc > 1)
printit(argv[1]);
- if (!(inbuf = malloc(LINELENGTH))) {
- (void)fprintf(stderr, "caesar: out of memory.\n");
- exit(1);
- }
+ if (!(inbuf = malloc(LINELENGTH)))
+ errx(1, "out of memory");
/* adjust frequency table to weight low probs REAL low */
for (i = 0; i < 26; ++i)
/* zero out observation table */
memset(obs, 0, 26 * sizeof(int));
- if ((nread = read(STDIN_FILENO, inbuf, LINELENGTH)) < 0) {
- (void)fprintf(stderr, "caesar: %s\n", strerror(errno));
- exit(1);
- }
+ if ((nread = read(STDIN_FILENO, inbuf, LINELENGTH)) < 0)
+ err(1, "reading from stdin");
for (i = nread; i--;) {
ch = inbuf[i];
if (islower(ch))
}
if (nread < LINELENGTH)
break;
- if ((nread = read(STDIN_FILENO, inbuf, LINELENGTH)) < 0) {
- (void)fprintf(stderr, "caesar: %s\n", strerror(errno));
- exit(1);
- }
+ if ((nread = read(STDIN_FILENO, inbuf, LINELENGTH)) < 0)
+ err(1, "reading from stdin");
}
exit(0);
}
{
int ch, rot;
- if ((rot = atoi(arg)) < 0) {
- (void)fprintf(stderr, "caesar: bad rotation value.\n");
- exit(1);
- }
+ if ((rot = atoi(arg)) < 0)
+ errx(1, "bad rotation value.");
while ((ch = getchar()) != EOF)
putchar(ROTATE(ch, rot));
exit(0);