Kaynağa Gözat

libdpkg: Move varbuf declarations to varbuf.h

Guillem Jover 17 yıl önce
ebeveyn
işleme
51012b34dc
4 değiştirilmiş dosya ile 144 ekleme ve 52 silme
  1. 1 1
      lib/dpkg/Makefile.am
  2. 1 50
      lib/dpkg/dpkg-db.h
  3. 0 1
      lib/dpkg/dpkg.h
  4. 142 0
      lib/dpkg/varbuf.h

+ 1 - 1
lib/dpkg/Makefile.am

@@ -48,5 +48,5 @@ libdpkg_a_SOURCES = \
 	triglib.c \
 	trigdeferred.l \
 	utils.c \
-	varbuf.c \
+	varbuf.c varbuf.h \
 	vercmp.c

+ 1 - 50
lib/dpkg/dpkg-db.h

@@ -24,6 +24,7 @@
 #define DPKG_DB_H
 
 #include <dpkg/macros.h>
+#include <dpkg/varbuf.h>
 
 DPKG_BEGIN_DECLS
 
@@ -372,56 +373,6 @@ const char *parseversion(struct versionrevision *rversion, const char*);
 const char *versiondescribe(const struct versionrevision*,
                             enum versiondisplayepochwhen);
 
-/*** from varbuf.c ***/
-
-struct varbuf;
-
-#define VARBUF_INIT { 0, 0, NULL }
-
-extern void varbufaddc(struct varbuf *v, int c);
-extern void varbufdupc(struct varbuf *v, int c, size_t s);
-extern void varbufsubstc(struct varbuf *v, int c_src, int c_dst);
-int varbufprintf(struct varbuf *v, const char *fmt, ...) DPKG_ATTR_PRINTF(2);
-int varbufvprintf(struct varbuf *v, const char *fmt, va_list va);
-void varbufinit(struct varbuf *v, size_t size);
-void varbufreset(struct varbuf *v);
-void varbufextend(struct varbuf *v);
-void varbuffree(struct varbuf *v);
-#define varbufaddstr(v, s)      varbufaddbuf(v, s, strlen(s))
-extern void varbufaddbuf(struct varbuf *v, const void *s, size_t size);
-
-/* varbufinit must be called exactly once before the use of each varbuf
- * (including before any call to varbuffree), or the variable must be
- * initialized with VARBUF_INIT.
- *
- * However, varbufs allocated `static' are properly initialised anyway and
- * do not need varbufinit; multiple consecutive calls to varbufinit before
- * any use are allowed.
- *
- * varbuffree must be called after a varbuf is finished with, if anything
- * other than varbufinit has been done.  After this you are allowed but
- * not required to call varbufinit again if you want to start using the
- * varbuf again.
- *
- * Callers using C++ need not worry about any of this.
- */
-struct varbuf {
-  size_t used, size;
-  char *buf;
-
-#ifdef __cplusplus
-  void init(size_t _size = 0) { varbufinit(this, _size); }
-  void free() { varbuffree(this); }
-  varbuf(size_t _size = 0) { varbufinit(this, _size); }
-  ~varbuf() { varbuffree(this); }
-  void operator()(int c) { varbufaddc(this,c); }
-  void operator()(const char *s) { varbufaddstr(this,s); }
-  void terminate(void/*to shut 2.6.3 up*/) { varbufaddc(this,0); used--; }
-  void reset() { used=0; }
-  const char *string() { terminate(); return buf; }
-#endif
-};
-
 /*** from dump.c ***/
 
 void writerecord(FILE*, const char*,

+ 0 - 1
lib/dpkg/dpkg.h

@@ -163,7 +163,6 @@ void do_internerr(const char *file, int line, const char *fmt, ...) DPKG_ATTR_NO
 #define internerr(args...) do_internerr(__FILE__, __LINE__, args)
 #endif
 
-struct varbuf;
 void ohshit(const char *fmt, ...) DPKG_ATTR_NORET DPKG_ATTR_PRINTF(1);
 void ohshitv(const char *fmt, va_list al) DPKG_ATTR_NORET;
 void ohshite(const char *fmt, ...) DPKG_ATTR_NORET DPKG_ATTR_PRINTF(1);

+ 142 - 0
lib/dpkg/varbuf.h

@@ -0,0 +1,142 @@
+/*
+ * libdpkg - Debian packaging suite library routines
+ * varbuf.h - variable length expandable buffer handling
+ *
+ * Copyright © 1994, 1995 Ian Jackson <ian@chiark.greenend.org.uk>
+ * Copyright © 2008, 2009 Guillem Jover <guillem@debian.org>
+ *
+ * This is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation; either version 2,
+ * or (at your option) any later version.
+ *
+ * This is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public
+ * License along with dpkg; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ */
+
+#ifndef DPKG_VARBUF_H
+#define DPKG_VARBUF_H
+
+#include <stddef.h>
+#include <stdarg.h>
+
+#include <dpkg/macros.h>
+
+DPKG_BEGIN_DECLS
+
+/*
+ * varbufinit must be called exactly once before the use of each varbuf
+ * (including before any call to varbuffree), or the variable must be
+ * initialized with VARBUF_INIT.
+ *
+ * However, varbufs allocated ‘static’ are properly initialised anyway and
+ * do not need varbufinit; multiple consecutive calls to varbufinit before
+ * any use are allowed.
+ *
+ * varbuffree must be called after a varbuf is finished with, if anything
+ * other than varbufinit has been done. After this you are allowed but
+ * not required to call varbufinit again if you want to start using the
+ * varbuf again.
+ *
+ * Callers using C++ need not worry about any of this.
+ */
+struct varbuf {
+	size_t used, size;
+	char *buf;
+
+#ifdef __cplusplus
+	varbuf(size_t _size = 0);
+	~varbuf();
+	void init(size_t _size = 0);
+	void reset();
+	void free();
+	void operator()(int c);
+	void operator()(const char *s);
+	void terminate(void/*to shut 2.6.3 up*/);
+	const char *string();
+#endif
+};
+
+#define VARBUF_INIT { 0, 0, NULL }
+
+void varbufinit(struct varbuf *v, size_t size);
+void varbufextend(struct varbuf *v);
+void varbufreset(struct varbuf *v);
+void varbuffree(struct varbuf *v);
+
+void varbufaddc(struct varbuf *v, int c);
+void varbufdupc(struct varbuf *v, int c, size_t n);
+void varbufsubstc(struct varbuf *v, int c_src, int c_dst);
+#define varbufaddstr(v, s) varbufaddbuf(v, s, strlen(s))
+void varbufaddbuf(struct varbuf *v, const void *s, size_t size);
+
+int varbufprintf(struct varbuf *v, const char *fmt, ...) DPKG_ATTR_PRINTF(2);
+int varbufvprintf(struct varbuf *v, const char *fmt, va_list va);
+
+DPKG_END_DECLS
+
+#ifdef __cplusplus
+inline
+varbuf::varbuf(size_t _size)
+{
+	varbufinit(this, _size);
+}
+
+inline
+varbuf::~varbuf()
+{
+	varbuffree(this);
+}
+
+inline void
+varbuf::init(size_t _size)
+{
+	varbufinit(this, _size);
+}
+
+inline void
+varbuf::reset()
+{
+	used = 0;
+}
+
+inline void
+varbuf::free()
+{
+	varbuffree(this);
+}
+
+inline void
+varbuf::operator()(int c)
+{
+	varbufaddc(this, c);
+}
+
+inline void
+varbuf::operator()(const char *s)
+{
+	varbufaddstr(this, s);
+}
+
+inline void
+varbuf::terminate(void/*to shut 2.6.3 up*/)
+{
+	varbufaddc(this, 0);
+	used--;
+}
+
+inline const char *
+varbuf::string()
+{
+	terminate();
+	return buf;
+}
+#endif
+
+#endif /* DPKG_VARBUF_H */