summaryrefslogtreecommitdiffstats
path: root/lib/libmemstat
diff options
context:
space:
mode:
authorrwatson <rwatson@FreeBSD.org>2005-07-24 01:41:47 +0000
committerrwatson <rwatson@FreeBSD.org>2005-07-24 01:41:47 +0000
commit560d460544dfe9f0c7701b09b72a5cb644278eca (patch)
tree4c4accb460ee9ff6aeea1f182a6dd60357adfa68 /lib/libmemstat
parentf689e777d1bf190fcd7b2185bd64f3ca6a46c45c (diff)
downloadFreeBSD-src-560d460544dfe9f0c7701b09b72a5cb644278eca.zip
FreeBSD-src-560d460544dfe9f0c7701b09b72a5cb644278eca.tar.gz
Having decided not to provide a libmemstat(3) error number to text
conversion routine, now change my mind and add one, memstat_strerror(3), which returns a const char * pointer to a string describing the error, to be used on the results of memstat_mtl_geterror(). While here, also correct a minor typo in the HISTORY man page. Pointers on improving ease of internationalization would be appreciated. MFC after: 1 day
Diffstat (limited to 'lib/libmemstat')
-rw-r--r--lib/libmemstat/Makefile1
-rw-r--r--lib/libmemstat/libmemstat.314
-rw-r--r--lib/libmemstat/memstat.c21
-rw-r--r--lib/libmemstat/memstat.h5
4 files changed, 38 insertions, 3 deletions
diff --git a/lib/libmemstat/Makefile b/lib/libmemstat/Makefile
index e58f99e..1d3c43d 100644
--- a/lib/libmemstat/Makefile
+++ b/lib/libmemstat/Makefile
@@ -17,6 +17,7 @@ MLINKS+= libmemstat.3 memstat_mtl_next.3
MLINKS+= libmemstat.3 memstat_mtl_find.3
MLINKS+= libmemstat.3 memstat_mtl_free.3
MLINKS+= libmemstat.3 memstat_mtl_geterror.3
+MLINKS+= libmemstat.3 memstat_strerror.3
MLINKS+= libmemstat.3 memstat_sysctl_all.3
MLINKS+= libmemstat.3 memstat_sysctl_malloc.3
MLINKS+= libmemstat.3 memstat_sysctl_uma.3
diff --git a/lib/libmemstat/libmemstat.3 b/lib/libmemstat/libmemstat.3
index 2e9f0bf..0bc3410 100644
--- a/lib/libmemstat/libmemstat.3
+++ b/lib/libmemstat/libmemstat.3
@@ -35,6 +35,9 @@
.Sh SYNOPSIS
.In sys/types.h
.In memstat.h
+.Ss General Functions
+.Ft const char *
+.Fn memstat_strerror "int error"
.Ss Memory Type List Management Functions
.Ft struct memory_type_list *
.Fn memstat_mtl_alloc "void"
@@ -150,7 +153,9 @@ Repeated calls will incrementally update the list of memory types, permitting
tracking over time without recreating all list state.
If an error is detected during a query call, error condition information may
be retrieved using
-.Fn memstat_mtl_geterror .
+.Fn memstat_mtl_geterror ,
+and converted to a user-readable string using
+.Fn memstat_strerror .
.Pp
Freeing the list will free all memory type data in the list, and so
invalidates any outstanding pointers to entries in the list.
@@ -356,7 +361,10 @@ on success, or
on failure.
If a failure is returned, the list error access method,
.Fn memstat_mtl_geterror ,
-may be used to retrieve the error state. Possible error values are:
+may be used to retrieve the error state.
+The string representation of the error may be retrieved using
+.Fn memstat_strerror .
+Possible error values are:
.Pp
.Bl -tag -width "MEMSTAT_ERROR_TOOMANYCPUS" -compact -offset wee
.It Dv MEMSTAT_ERROR_UNDEFINED
@@ -426,7 +434,7 @@ printf("Mbufs: %llu\\n", (unsigned long long)mbuf_count);
.Xr uma 9
.Sh HISTORY
The
-.Nm memstat
+.Nm libmemstat
library appeared in
.Fx 6.0 .
.Sh AUTHORS
diff --git a/lib/libmemstat/memstat.c b/lib/libmemstat/memstat.c
index f053e95..f32541f 100644
--- a/lib/libmemstat/memstat.c
+++ b/lib/libmemstat/memstat.c
@@ -38,6 +38,27 @@
#include "memstat.h"
#include "memstat_internal.h"
+const char *
+memstat_strerror(int error)
+{
+
+ switch (error) {
+ case MEMSTAT_ERROR_NOMEMORY:
+ return ("Cannot allocate memory");
+ case MEMSTAT_ERROR_VERSION:
+ return ("Version mismatch");
+ case MEMSTAT_ERROR_PERMISSION:
+ return ("Permission denied");
+ case MEMSTAT_ERROR_TOOMANYCPUS:
+ return ("Too many CPUs");
+ case MEMSTAT_ERROR_DATAERROR:
+ return ("Data format error");
+ case MEMSTAT_ERROR_UNDEFINED:
+ default:
+ return ("Unknown error");
+ }
+}
+
struct memory_type_list *
memstat_mtl_alloc(void)
{
diff --git a/lib/libmemstat/memstat.h b/lib/libmemstat/memstat.h
index c2e3174..f466408 100644
--- a/lib/libmemstat/memstat.h
+++ b/lib/libmemstat/memstat.h
@@ -90,6 +90,11 @@ struct memory_type_list;
__BEGIN_DECLS
/*
+ * Functions that operate without memory type or memory type list context.
+ */
+const char *memstat_strerror(int error);
+
+/*
* Functions for managing memory type and statistics data.
*/
struct memory_type_list *memstat_mtl_alloc(void);
OpenPOWER on IntegriCloud