summaryrefslogtreecommitdiffabout
authorSergey Poznyakoff <gray@gnu.org>2018-05-30 11:24:08 (GMT)
committer Sergey Poznyakoff <gray@gnu.org>2018-05-30 11:24:08 (GMT)
commit60605e947884726fe14c8896fa5c766f6e99742a (patch) (side-by-side diff)
tree93aaf1452b3f6da0ac66d8eb08165be4fd37b04d
parent4e819c987988432ef936c6c3e003db6b26463154 (diff)
downloadgdbm-60605e947884726fe14c8896fa5c766f6e99742a.tar.gz
gdbm-60605e947884726fe14c8896fa5c766f6e99742a.tar.bz2
Rewrite gdbm_file_write etc. as inline functions.
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--src/proto.h57
1 files changed, 40 insertions, 17 deletions
diff --git a/src/proto.h b/src/proto.h
index 3fb990c..e543506 100644
--- a/src/proto.h
+++ b/src/proto.h
@@ -84,24 +84,47 @@ int _gdbm_dump (GDBM_FILE dbf, FILE *fp);
/* From recover.c */
int _gdbm_next_bucket_dir (GDBM_FILE dbf, int bucket_dir);
-/* I/O macros. */
+/* I/O functions */
+static inline ssize_t
+gdbm_file_read (GDBM_FILE dbf, void *buf, size_t size)
+{
#if HAVE_MMAP
-# define gdbm_file_read(_dbf, _buf, _size) \
- _gdbm_mapped_read(_dbf, _buf, _size)
-# define gdbm_file_write(_dbf, _buf, _size) \
- _gdbm_mapped_write(_dbf, _buf, _size)
-# define gdbm_file_seek(_dbf, _off, _whn) \
- _gdbm_mapped_lseek(_dbf, _off, _whn)
-# define gdbm_file_sync(_dbf) \
- _gdbm_mapped_sync(_dbf)
+ return _gdbm_mapped_read (dbf, buf, size);
#else
-# define gdbm_file_read(_dbf, _buf, _size) read(_dbf->desc, _buf, _size)
-# define gdbm_file_write(_dbf, _buf, _size) write(_dbf->desc, _buf, _size)
-# define gdbm_file_seek(_dbf, _off, _whn) lseek(_dbf->desc, _off, _whn)
-# if HAVE_FSYNC
-# define gdbm_file_sync(_dbf) fsync(_dbf->desc)
-# else
-# define gdbm_file_sync(_dbf) { sync(); sync(); }
-# endif
+ return read (dbf->desc, buf, size);
#endif
+}
+
+static inline ssize_t
+gdbm_file_write (GDBM_FILE dbf, void *buf, size_t size)
+{
+#if HAVE_MMAP
+ return _gdbm_mapped_write (dbf, buf, size);
+#else
+ return write (dbf->desc, buf, size);
+#endif
+}
+
+static inline off_t
+gdbm_file_seek (GDBM_FILE dbf, off_t off, int whence)
+{
+#if HAVE_MMAP
+ return _gdbm_mapped_lseek (dbf, off, whence);
+#else
+ return lseek (dbf->desc, off, whence);
+#endif
+}
+
+static inline void
+gdbm_file_sync (GDBM_FILE dbf)
+{
+#if HAVE_MMAP
+ _gdbm_mapped_sync (dbf);
+#elif HAVE_FSYNC
+ fsync (dbf->desc);
+#else
+ sync ();
+ sync ();
+#endif
+}

Return to:

Send suggestions and report system problems to the System administrator.