summaryrefslogtreecommitdiff
path: root/src/interfaces/libpgtcl/pgtclId.c
diff options
context:
space:
mode:
authorMarc G. Fournier1996-07-09 06:22:35 +0000
committerMarc G. Fournier1996-07-09 06:22:35 +0000
commit24a952fe4a27c6c66dc46ee3b2d860755fe063e1 (patch)
tree9c669cd24c4dbcf57f03c278f3169dcb971a2151 /src/interfaces/libpgtcl/pgtclId.c
Postgres95 1.01 Distribution - Virgin SourcesPG95_DIST
Diffstat (limited to 'src/interfaces/libpgtcl/pgtclId.c')
-rw-r--r--src/interfaces/libpgtcl/pgtclId.c51
1 files changed, 51 insertions, 0 deletions
diff --git a/src/interfaces/libpgtcl/pgtclId.c b/src/interfaces/libpgtcl/pgtclId.c
new file mode 100644
index 0000000000..c860942567
--- /dev/null
+++ b/src/interfaces/libpgtcl/pgtclId.c
@@ -0,0 +1,51 @@
+/*-------------------------------------------------------------------------
+ *
+ * pgtclId.c--
+ * useful routines to convert between strings and pointers
+ * Needed because everything in tcl is a string, but we want pointers
+ * to data structures
+ *
+ * ASSUMPTION: sizeof(long) >= sizeof(void*)
+ *
+ *
+ * Copyright (c) 1994, Regents of the University of California
+ *
+ *
+ * IDENTIFICATION
+ * $Header$
+ *
+ *-------------------------------------------------------------------------
+ */
+
+#include <stdlib.h>
+#include <string.h>
+#include "tcl.h"
+
+#include "pgtclId.h"
+
+/* convert a pointer into a string */
+void
+PgSetId(char *id, void *ptr)
+{
+ (void) sprintf(id, "pgp%lx", (long) ptr);
+}
+
+
+/* get back a pointer from a string */
+void *
+PgGetId(char *id)
+{
+ long ptr;
+ ptr = strtol(id+3, NULL, 16);
+ return (void *) ptr;
+}
+
+/* check to see if the string is a valid pgtcl pointer */
+int
+PgValidId(char* id)
+{
+ if ( (strlen(id) > 3) && id[0]=='p' && id[1] == 'g' && id[2] == 'p')
+ return 1;
+ else
+ return 0;
+}