summaryrefslogtreecommitdiff
path: root/usr.bin
diff options
context:
space:
mode:
authorOtto Moerbeek <otto@cvs.openbsd.org>2003-10-22 12:03:55 +0000
committerOtto Moerbeek <otto@cvs.openbsd.org>2003-10-22 12:03:55 +0000
commitf49ecb567de10a6bb8d3d8459d78e41d7f1ec617 (patch)
tree7142682d75c537351ef912798231a346d7ff17af /usr.bin
parentb4716c815f6b9d0155ed95f461868794a86e4617 (diff)
Make ungetting a char read form a string behave the same as ungetting
a char from a stream.
Diffstat (limited to 'usr.bin')
-rw-r--r--usr.bin/dc/inout.c15
1 files changed, 10 insertions, 5 deletions
diff --git a/usr.bin/dc/inout.c b/usr.bin/dc/inout.c
index e43476d178d..5daaa081ca7 100644
--- a/usr.bin/dc/inout.c
+++ b/usr.bin/dc/inout.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: inout.c,v 1.6 2003/10/18 20:34:26 otto Exp $ */
+/* $OpenBSD: inout.c,v 1.7 2003/10/22 12:03:54 otto Exp $ */
/*
* Copyright (c) 2003, Otto Moerbeek <otto@drijf.net>
@@ -17,7 +17,7 @@
*/
#ifndef lint
-static const char rcsid[] = "$OpenBSD: inout.c,v 1.6 2003/10/18 20:34:26 otto Exp $";
+static const char rcsid[] = "$OpenBSD: inout.c,v 1.7 2003/10/22 12:03:54 otto Exp $";
#endif /* not lint */
#include <ssl/ssl.h>
@@ -115,9 +115,14 @@ src_getcharstring(struct source *src)
static int
src_ungetcharstring(struct source *src)
{
- if (src->u.string.pos > 0)
- return src->u.string.buf[--src->u.string.pos];
- else
+ int ch;
+
+ if (src->u.string.pos > 0) {
+ if (src->lastchar != '\0')
+ --src->u.string.pos;
+ ch = src->u.string.buf[src->u.string.pos];
+ return ch == '\0' ? EOF : ch;
+ } else
return EOF;
}