Sync with NetBSD:
authorJoerg Sonnenberger <joerg@dragonflybsd.org>
Mon, 4 Jul 2005 10:11:57 +0000 (10:11 +0000)
committerJoerg Sonnenberger <joerg@dragonflybsd.org>
Mon, 4 Jul 2005 10:11:57 +0000 (10:11 +0000)
* add some comments.
* add some functions:
   _citrus_memory_stream_bind_ptr()
   _citrus_memory_stream_tell()
   _citrus_memory_stream_ungetc()
   _citrus_region_get_subregion()
* fix a bug in _citrus_memory_stream_seek().

lib/libc/citrus/citrus_memstream.h
lib/libc/citrus/citrus_namespace.h
lib/libc/citrus/citrus_region.h

index ac4c9e7..22a8f68 100644 (file)
@@ -1,5 +1,5 @@
-/*     $NetBSD: src/lib/libc/citrus/citrus_memstream.h,v 1.2 2004/12/30 05:01:19 christos Exp $        */
-/*     $DragonFly: src/lib/libc/citrus/citrus_memstream.h,v 1.1 2005/03/11 23:33:53 joerg Exp $ */
+/*     $NetBSD: citrus_memstream.h,v 1.3 2005/05/14 17:55:42 tshiozak Exp $    */
+/*     $DragonFly: src/lib/libc/citrus/citrus_memstream.h,v 1.2 2005/07/04 10:11:57 joerg Exp $ */
 
 /*-
  * Copyright (c)2003 Citrus Project,
@@ -61,12 +61,28 @@ _citrus_memory_stream_bind(struct _citrus_memory_stream * __restrict ms,
        ms->ms_pos = 0;
 }
 
+static __inline void
+_citrus_memory_stream_bind_ptr(struct _citrus_memory_stream * __restrict ms,
+                              void *ptr, size_t sz)
+{
+       struct _citrus_region r;
+
+       _citrus_region_init(&r, ptr, sz);
+       _citrus_memory_stream_bind(ms, &r);
+}
+
 static __inline void
 _citrus_memory_stream_rewind(struct _citrus_memory_stream *ms)
 {
        ms->ms_pos = 0;
 }
 
+static __inline size_t
+_citrus_memory_stream_tell(struct _citrus_memory_stream *ms)
+{
+       return ms->ms_pos;
+}
+
 static __inline size_t
 _citrus_memory_stream_remainder(struct _citrus_memory_stream *ms)
 {
@@ -88,9 +104,10 @@ _citrus_memory_stream_seek(struct _citrus_memory_stream *ms, size_t pos, int w)
                ms->ms_pos = pos;
                break;
        case SEEK_CUR:
-               pos += ms->ms_pos;
+               pos += (ssize_t)ms->ms_pos;
                if (pos>=sz)
                        return -1;
+               ms->ms_pos = pos;
                break;
        case SEEK_END:
                if (sz<pos)
@@ -109,6 +126,13 @@ _citrus_memory_stream_getc(struct _citrus_memory_stream *ms)
        return _citrus_region_peek8(&ms->ms_region, ms->ms_pos++);
 }
 
+static __inline void
+_citrus_memory_stream_ungetc(struct _citrus_memory_stream *ms, int ch)
+{
+       if (ch != EOF && ms->ms_pos > 0)
+               ms->ms_pos--;
+}
+
 static __inline int
 _citrus_memory_stream_peek(struct _citrus_memory_stream *ms)
 {
@@ -173,4 +197,18 @@ _citrus_memory_stream_get32(struct _citrus_memory_stream *ms, uint32_t *rval)
        return 0;
 }
 
+static __inline int
+_citrus_memory_stream_getln_region(struct _citrus_memory_stream *ms,
+                                  struct _citrus_region *r)
+{
+       const char *ptr;
+       size_t sz;
+
+       ptr = _citrus_memory_stream_getln(ms, &sz);
+       if (ptr)
+               _citrus_region_init(r, __DECONST(char *, ptr), sz);
+
+       return ptr == NULL;
+}
+
 #endif
index 92a12d1..6137f5f 100644 (file)
@@ -1,5 +1,5 @@
-/*     $NetBSD: src/lib/libc/citrus/citrus_namespace.h,v 1.4 2004/07/21 14:16:34 tshiozak Exp $        */
-/*     $DragonFly: src/lib/libc/citrus/citrus_namespace.h,v 1.1 2005/03/11 23:33:53 joerg Exp $ */
+/*     $NetBSD: citrus_namespace.h,v 1.5 2005/05/14 17:55:42 tshiozak Exp $    */
+/*     $DragonFly: src/lib/libc/citrus/citrus_namespace.h,v 1.2 2005/07/04 10:11:57 joerg Exp $ */
 
 /*-
  * Copyright (c)2003 Citrus Project,
 #define _memstream_skip_ws     _citrus_memory_stream_skip_ws
 #define _memstream_iseof       _citrus_memory_stream_iseof
 #define _memstream_bind                _citrus_memory_stream_bind
+#define _memstream_bind_ptr    _citrus_memory_stream_bind_ptr
 #define _memstream_seek                _citrus_memory_stream_seek
 #define _memstream_rewind      _citrus_memory_stream_rewind
+#define _memstream_tell                _citrus_memory_stream_tell
 #define _memstream_remainder   _citrus_memory_stream_remainder
 #define _memstream_getc                _citrus_memory_stream_getc
+#define _memstream_ungetc      _citrus_memory_stream_ungetc
 #define _memstream_peek                _citrus_memory_stream_peek
 #define _memstream_getregion   _citrus_memory_stream_getregion
+#define _memstream_getln_region        _citrus_memory_stream_getln_region
 #endif /* _CITRUS_MEMSTREAM_NO_NAMESPACE */
 
 /* citrus_mmap */
 #define _region_peek8          _citrus_region_peek8
 #define _region_peek16         _citrus_region_peek16
 #define _region_peek32         _citrus_region_peek32
+#define _region_get_subregion  _citrus_region_get_subregion
 #endif /* _CITRUS_REGION_NO_NAMESPACE */
 
 /* citrus_stdenc.h */
index d4cd3a0..bdcafdc 100644 (file)
@@ -1,5 +1,5 @@
-/*     $NetBSD: src/lib/libc/citrus/citrus_region.h,v 1.5 2004/12/30 05:00:42 christos Exp $   */
-/*     $DragonFly: src/lib/libc/citrus/citrus_region.h,v 1.1 2005/03/11 23:33:53 joerg Exp $ */
+/*     $NetBSD: citrus_region.h,v 1.6 2005/05/14 17:55:42 tshiozak Exp $       */
+/*     $DragonFly: src/lib/libc/citrus/citrus_region.h,v 1.2 2005/07/04 10:11:57 joerg Exp $ */
 
 /*-
  * Copyright (c)2003 Citrus Project,
@@ -91,4 +91,15 @@ _citrus_region_peek32(const struct _citrus_region *r, size_t pos)
        return val;
 }
 
+static __inline int
+_citrus_region_get_subregion(struct _citrus_region *subr,
+                            const struct _citrus_region *r,
+                            size_t ofs, size_t sz)
+{
+       if (_citrus_region_check(r, ofs, sz))
+               return -1;
+       _citrus_region_init(subr, _citrus_region_offset(r, ofs), sz);
+       return 0;
+}
+
 #endif