[14/19] libctf: library version enforcement

Message ID 20190430225706.159422-15-nick.alcock@oracle.com
State New
Headers show
Series
  • libctf, and CTF support for objdump and readelf
Related show

Commit Message

Nick Alcock April 30, 2019, 10:57 p.m.
This old Solaris standard allows callers to specify that they are
expecting one particular API and/or CTF file format from the library.

It is basically vestigial and I would be amenable to dropping it.

libctf/
	* ctf-lib.c (ctf_version): New.

include/
	* ctf-api.h (ctf_version): New.
---
 include/ctf-api.h |  1 +
 libctf/ctf-lib.c  | 26 ++++++++++++++++++++++++++
 2 files changed, 27 insertions(+)

-- 
2.21.0.237.gd0cfaa883d

Patch

diff --git a/include/ctf-api.h b/include/ctf-api.h
index 0adecfee7e..3fcb1d2d6c 100644
--- a/include/ctf-api.h
+++ b/include/ctf-api.h
@@ -233,6 +233,7 @@  extern void *ctf_getspecific (ctf_file_t *);
 
 extern int ctf_errno (ctf_file_t *);
 extern const char *ctf_errmsg (int);
+extern int ctf_version (int);
 
 extern int ctf_func_info (ctf_file_t *, unsigned long, ctf_funcinfo_t *);
 extern int ctf_func_args (ctf_file_t *, unsigned long, uint32_t, ctf_id_t *);
diff --git a/libctf/ctf-lib.c b/libctf/ctf-lib.c
index e60d2c985b..3a52539755 100644
--- a/libctf/ctf-lib.c
+++ b/libctf/ctf-lib.c
@@ -478,3 +478,29 @@  ctf_write (ctf_file_t *fp, int fd)
 
   return 0;
 }
+
+/* Set the CTF library client version to the specified version.  If version is
+   zero, we just return the default library version number.  */
+int
+ctf_version (int version)
+{
+  if (version < 0)
+    {
+      errno = EINVAL;
+      return -1;
+    }
+
+  if (version > 0)
+    {
+      /*  Dynamic version switching is not presently supported. */
+      if (version != CTF_VERSION)
+	{
+	  errno = ENOTSUP;
+	  return -1;
+	}
+      ctf_dprintf ("ctf_version: client using version %d\n", version);
+      _libctf_version = version;
+    }
+
+  return _libctf_version;
+}