Browse Source

Builds and works correctly on OpenBSD! How did I not have unistd.h already?

Douglas William Thrift 13 years ago
parent
commit
2cccab6d37
4 changed files with 55 additions and 13 deletions
  1. 5 5
      GNUmakefile.in
  2. 19 1
      configure
  3. 4 2
      configure.ac
  4. 27 5
      dtpstree.cpp

+ 5 - 5
GNUmakefile.in

@@ -23,7 +23,7 @@ VPATH := @srcdir@
 srcdir := @srcdir@
 top_builddir := @top_builddir@
 
-CPPFLAGS := @CPPFLAGS@ $(filter -DPACKAGE_TARNAME% -DPACKAGE_VERSION% -DHAVE_NCURSES% -DHAVE_CURSES% -DHAVE_TERM% -DHAVE_STRUCT_KINFO_PROC% -DHAVE_DECL_KERN_PROC_PROC%,@DEFS@)
+CPPFLAGS := @CPPFLAGS@ $(filter -DPACKAGE_TARNAME% -DPACKAGE_VERSION% -DHAVE_NCURSES% -DHAVE_CURSES% -DHAVE_TERM% -DHAVE_STRUCT_KINFO_PROC% -DHAVE_DECL_KERN_PROC_PROC% -DHAVE_DECL_KERN_PROC_KTHREAD%,@DEFS@)
 CXX := @CXX@
 CXXFLAGS := @CXXFLAGS@ -Wall -Wno-long-long -Wno-parentheses
 LDFLAGS := @LDFLAGS@
@@ -89,11 +89,11 @@ install: all
 	$(INSTALL_DATA) $(srcdir)/man1/dtpstree.1 $(DESTDIR)$(man1dir)
 
 uninstall:
-	rm -fv $(DESTDIR)$(bindir)/dtpstree
-	rm -fv $(DESTDIR)$(man1dir)/dtpstree.1
+	rm -f $(DESTDIR)$(bindir)/dtpstree
+	rm -f $(DESTDIR)$(man1dir)/dtpstree.1
 
 clean:
-	rm -fv dtpstree $(wildcard *core)
+	rm -f dtpstree $(wildcard *core)
 
 distclean: clean
-	rm -fv GNUmakefile config.log config.status makefile
+	rm -f GNUmakefile config.log config.status makefile

+ 19 - 1
configure

@@ -4582,6 +4582,7 @@ ac_fn_cxx_check_decl "$LINENO" "KERN_PROC_PROC" "ac_cv_have_decl_KERN_PROC_PROC"
 #include <sys/sysctl.h>
 #include <sys/user.h>
 $ac_includes_default
+
 "
 if test "x$ac_cv_have_decl_KERN_PROC_PROC" = x""yes; then :
   ac_have_decl=1
@@ -4592,11 +4593,28 @@ fi
 cat >>confdefs.h <<_ACEOF
 #define HAVE_DECL_KERN_PROC_PROC $ac_have_decl
 _ACEOF
+ac_fn_cxx_check_decl "$LINENO" "KERN_PROC_KTHREAD" "ac_cv_have_decl_KERN_PROC_KTHREAD" "#include <kvm.h>
+#include <sys/param.h>
+#include <sys/sysctl.h>
+#include <sys/user.h>
+$ac_includes_default
+
+"
+if test "x$ac_cv_have_decl_KERN_PROC_KTHREAD" = x""yes; then :
+  ac_have_decl=1
+else
+  ac_have_decl=0
+fi
+
+cat >>confdefs.h <<_ACEOF
+#define HAVE_DECL_KERN_PROC_KTHREAD $ac_have_decl
+_ACEOF
 ac_fn_cxx_check_decl "$LINENO" "KERN_PROC_ALL" "ac_cv_have_decl_KERN_PROC_ALL" "#include <kvm.h>
 #include <sys/param.h>
 #include <sys/sysctl.h>
 #include <sys/user.h>
 $ac_includes_default
+
 "
 if test "x$ac_cv_have_decl_KERN_PROC_ALL" = x""yes; then :
   ac_have_decl=1
@@ -4608,7 +4626,7 @@ cat >>confdefs.h <<_ACEOF
 #define HAVE_DECL_KERN_PROC_ALL $ac_have_decl
 _ACEOF
 
-case $ac_cv_have_decl_KERN_PROC_PROC$ac_cv_have_decl_KERN_PROC_ALL in #(
+case $ac_cv_have_decl_KERN_PROC_PROC$ac_cv_have_decl_KERN_PROC_KTHREAD$ac_cv_have_decl_KERN_PROC_ALL in #(
   *yes*) :
      ;; #(
   *) :

+ 4 - 2
configure.ac

@@ -119,8 +119,10 @@ AC_CHECK_TYPE([struct kinfo_proc2],
 		[DT_MSG_KVM], [DT_INCLUDES_KVM]
 	)], [DT_INCLUDES_KVM]
 )
-AC_CHECK_DECLS([KERN_PROC_PROC, KERN_PROC_ALL], [], [], [DT_INCLUDES_KVM])
-AS_CASE([$ac_cv_have_decl_KERN_PROC_PROC$ac_cv_have_decl_KERN_PROC_ALL],
+AC_CHECK_DECLS([KERN_PROC_PROC, KERN_PROC_KTHREAD, KERN_PROC_ALL], [], [],
+	[DT_INCLUDES_KVM]
+)
+AS_CASE([$ac_cv_have_decl_KERN_PROC_PROC$ac_cv_have_decl_KERN_PROC_KTHREAD$ac_cv_have_decl_KERN_PROC_ALL],
 	[*yes*], [], [DT_MSG_KVM]
 )
 AS_CASE([$GNUMAKE], [make], [], [AC_CONFIG_FILES([makefile])])

+ 27 - 5
dtpstree.cpp

@@ -56,6 +56,7 @@
 #include <sys/sysctl.h>
 #include <sys/user.h>
 #include <sys/utsname.h>
+#include <unistd.h>
 #include <vis.h>
 
 #include "foreach.hpp"
@@ -65,6 +66,8 @@ namespace kvm
 
 #if HAVE_DECL_KERN_PROC_PROC
 const int All(KERN_PROC_PROC);
+#elif HAVE_DECL_KERN_PROC_KTHREAD
+const int All(KERN_PROC_KTHREAD);
 #else
 const int All(KERN_PROC_ALL);
 #endif
@@ -238,12 +241,24 @@ public:
 			verticalAndRight_ = L'\x251c';
 			downAndHorizontal_ = L'\x252c';
 
-			char *test;
+			wchar_t wides[] = { horizontal_, vertical_, upAndRight_, verticalAndRight_, downAndHorizontal_ };
 
-			if (asprintf(&test, "%lc%lc%lc%lc%lc", horizontal_, vertical_, upAndRight_, verticalAndRight_, downAndHorizontal_) == -1)
-				goto vt100;
+			for (int index(0); index != sizeof (wides) / sizeof (*wides); ++index)
+			{
+				char buffer[MB_CUR_MAX];
+				int size;
+
+				if ((size = std::wctomb(buffer, wides[index])) == -1)
+					goto vt100;
+
+				wchar_t wide;
+
+				if (std::mbtowc(&wide, buffer, size) == -1)
+					goto vt100;
 
-			std::free(test);
+				if (wide != wides[index])
+					goto vt100;
+			}
 		}
 		else if (flags & Vt100)
 		{
@@ -484,7 +499,14 @@ private:
 
 				std::mbstowcs(const_cast<wchar_t *>(wide.data()), string, wide.size());
 				std::free(string);
-				asprintf(&string, "%ls+", wide.c_str());
+
+				wide += L'+';
+
+				size_t size(std::wcstombs(NULL, wide.c_str(), 0) + 1);
+
+				string = static_cast<char *>(std::malloc(size));
+
+				std::wcstombs(string, wide.c_str(), size);
 
 				if (previous)
 				{