summaryrefslogtreecommitdiff
path: root/libguile/inline.h
diff options
context:
space:
mode:
authorAndy Wingo <wingo@pobox.com>2011-05-09 00:13:04 +0200
committerAndy Wingo <wingo@pobox.com>2011-05-09 00:13:04 +0200
commite690a3cbf290a39ede4b3a390e940702cddf6da8 (patch)
tree7ce19a861ece2c18fa4d91842b5a4894b26698ea /libguile/inline.h
parent059a588fedf377ffd32cc1f1fee7ed829b263890 (diff)
parent8f6a4b248b12db2c56ab29e909ba1441aa8f512d (diff)
downloadguile-e690a3cbf290a39ede4b3a390e940702cddf6da8.tar.gz
Merge remote-tracking branch 'origin/stable-2.0'
Diffstat (limited to 'libguile/inline.h')
-rw-r--r--libguile/inline.h34
1 files changed, 32 insertions, 2 deletions
diff --git a/libguile/inline.h b/libguile/inline.h
index 1eae2e40f..51a4db0ab 100644
--- a/libguile/inline.h
+++ b/libguile/inline.h
@@ -3,7 +3,8 @@
#ifndef SCM_INLINE_H
#define SCM_INLINE_H
-/* Copyright (C) 2001, 2002, 2003, 2004, 2006, 2008, 2009, 2010 Free Software Foundation, Inc.
+/* Copyright (C) 2001, 2002, 2003, 2004, 2006, 2008, 2009, 2010,
+ * 2011 Free Software Foundation, Inc.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public License
@@ -98,6 +99,7 @@ SCM_API int scm_is_pair (SCM x);
SCM_API int scm_is_string (SCM x);
SCM_API int scm_get_byte_or_eof (SCM port);
+SCM_API int scm_peek_byte_or_eof (SCM port);
SCM_API void scm_putc (char c, SCM port);
SCM_API void scm_puts (const char *str_data, SCM port);
@@ -362,7 +364,7 @@ scm_get_byte_or_eof (SCM port)
if (pt->read_pos >= pt->read_end)
{
- if (scm_fill_input (port) == EOF)
+ if (SCM_UNLIKELY (scm_fill_input (port) == EOF))
return EOF;
}
@@ -371,6 +373,34 @@ scm_get_byte_or_eof (SCM port)
return c;
}
+/* Like `scm_get_byte_or_eof' but does not change PORT's `read_pos'. */
+#ifndef SCM_INLINE_C_INCLUDING_INLINE_H
+SCM_C_EXTERN_INLINE
+#endif
+int
+scm_peek_byte_or_eof (SCM port)
+{
+ int c;
+ scm_t_port *pt = SCM_PTAB_ENTRY (port);
+
+ if (pt->rw_active == SCM_PORT_WRITE)
+ /* may be marginally faster than calling scm_flush. */
+ scm_ptobs[SCM_PTOBNUM (port)].flush (port);
+
+ if (pt->rw_random)
+ pt->rw_active = SCM_PORT_READ;
+
+ if (pt->read_pos >= pt->read_end)
+ {
+ if (SCM_UNLIKELY (scm_fill_input (port) == EOF))
+ return EOF;
+ }
+
+ c = *pt->read_pos;
+
+ return c;
+}
+
#ifndef SCM_INLINE_C_INCLUDING_INLINE_H
SCM_C_EXTERN_INLINE
#endif