aboutsummaryrefslogtreecommitdiff
path: root/src/interfaces/libpgtcl/pgtclId.c
blob: 00dffe7a88322e02216e14577f09e47f30d1ecec (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
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: /cvsroot/pgsql/src/interfaces/libpgtcl/Attic/pgtclId.c,v 1.1.1.1 1996/07/09 06:22:16 scrappy Exp $
 *
 *-------------------------------------------------------------------------
 */

#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;
}