summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTheo de Raadt <deraadt@cvs.openbsd.org>2009-10-28 05:06:18 +0000
committerTheo de Raadt <deraadt@cvs.openbsd.org>2009-10-28 05:06:18 +0000
commit7a04a928e255217124b5c687b4b951793f7f0815 (patch)
tree79e60ffa8f530dc07cbff38ee64399f694bb138b
parent536af7b41e3a7717b992f5b3e07884c4161a73ec (diff)
the code to support -DDES spread it's way outside of -DDES... fix that
ok guenther
-rw-r--r--bin/ed/io.c27
1 files changed, 23 insertions, 4 deletions
diff --git a/bin/ed/io.c b/bin/ed/io.c
index 46dd83342b4..c73246d5570 100644
--- a/bin/ed/io.c
+++ b/bin/ed/io.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: io.c,v 1.13 2009/10/27 23:59:21 deraadt Exp $ */
+/* $OpenBSD: io.c,v 1.14 2009/10/28 05:06:17 deraadt Exp $ */
/* $NetBSD: io.c,v 1.2 1995/03/21 09:04:43 cgd Exp $ */
/* io.c: This file contains the i/o routines for the ed line editor */
@@ -77,8 +77,10 @@ read_stream(FILE *fp, int n)
int len;
isbinary = newline_added = 0;
+#ifdef DES
if (des)
init_des_cipher();
+#endif
for (current_addr = n; (len = get_stream_line(fp)) > 0; size += len) {
SPL1();
if (put_sbuf_line(sbuf) == NULL) {
@@ -112,6 +114,11 @@ read_stream(FILE *fp, int n)
return size;
}
+#ifdef DES
+#define DESGETCHAR(fp) (des ? get_des_char((fp)) : getc((fp)))
+#else
+#define DESGETCHAR(fp) (getc((fp)))
+#endif
/* get_stream_line: read a line of text from a stream; return line length */
int
@@ -120,7 +127,7 @@ get_stream_line(FILE *fp)
int c;
int i = 0;
- while (((c = des ? get_des_char(fp) : getc(fp)) != EOF || (!feof(fp) &&
+ while (((c = DESGETCHAR(fp)) != EOF || (!feof(fp) &&
!ferror(fp))) && c != '\n') {
REALLOC(sbuf, sbufsz, i + 1, ERR);
if (!(sbuf[i++] = c))
@@ -175,8 +182,10 @@ write_stream(FILE *fp, int n, int m)
char *s;
int len;
+#ifdef DES
if (des)
init_des_cipher();
+#endif
for (; n && n <= m; n++, lp = lp->q_forw) {
if ((s = get_sbuf_line(lp)) == NULL)
return ERR;
@@ -187,24 +196,34 @@ write_stream(FILE *fp, int n, int m)
return ERR;
size += len;
}
+#ifdef DES
if (des) {
flush_des_file(fp); /* flush buffer */
size += 8 - size % 8; /* adjust DES size */
}
+#endif
return size;
}
+#ifdef DES
+#define DESPUTCHAR(c, fp) (des ? put_des_char(c, (fp)) : fputc((c), (fp)))
+#else
+#define DESPUTCHAR(c, fp) (fputc((c), (fp)))
+#endif
+
/* put_stream_line: write a line of text to a stream; return status */
int
put_stream_line(FILE *fp, char *s, int len)
{
- while (len--)
- if ((des ? put_des_char(*s++, fp) : fputc(*s++, fp)) < 0) {
+ while (len--) {
+ if (DESPUTCHAR(*s, fp) < 0) {
perror(NULL);
seterrmsg("cannot write file");
return ERR;
}
+ s++;
+ }
return 0;
}