From 6316f4d3db11678472430a3e406382faaad71da8 Mon Sep 17 00:00:00 2001
From: "Thomas G. Lockhart" <lockhart@fourpalms.org>
Date: Tue, 16 Dec 1997 15:59:11 +0000
Subject: [PATCH] Define text, varchar, and bpchar string length functions.

---
 src/backend/utils/adt/varchar.c | 22 ++++++++++++++++++++--
 src/backend/utils/adt/varlena.c | 16 +++++-----------
 2 files changed, 25 insertions(+), 13 deletions(-)

diff --git a/src/backend/utils/adt/varchar.c b/src/backend/utils/adt/varchar.c
index 1661f08cd8a..325d5f6f415 100644
--- a/src/backend/utils/adt/varchar.c
+++ b/src/backend/utils/adt/varchar.c
@@ -7,7 +7,7 @@
  *
  *
  * IDENTIFICATION
- *	  $Header: /cvsroot/pgsql/src/backend/utils/adt/varchar.c,v 1.12 1997/12/06 22:57:14 momjian Exp $
+ *	  $Header: /cvsroot/pgsql/src/backend/utils/adt/varchar.c,v 1.13 1997/12/16 15:59:09 thomas Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -121,7 +121,7 @@ bpcharout(char *s)
  *	  len is the length specified in () plus VARHDRSZ bytes. (XXX dummy is here
  *	  because we pass typelem as the second argument for array_in.)
  */
-char	   *
+char *
 varcharin(char *s, int dummy, int typlen)
 {
 	char	   *result;
@@ -191,6 +191,15 @@ bcTruelen(char *arg)
 	return (i + 1);
 }
 
+int32
+bpcharlen(char *arg)
+{
+	if (!PointerIsValid(arg))
+		elog(WARN, "Bad (null) char() external representation", NULL);
+
+	return(bcTruelen(arg));
+} /* bpcharlen() */
+
 bool
 bpchareq(char *arg1, char *arg2)
 {
@@ -338,6 +347,15 @@ vcTruelen(char *arg)
 	return i;
 }
 
+int32
+varcharlen(char *arg)
+{
+	if (!PointerIsValid(arg))
+		elog(WARN, "Bad (null) varchar() external representation", NULL);
+
+	return(vcTruelen(arg));
+} /* vclen() */
+
 bool
 varchareq(char *arg1, char *arg2)
 {
diff --git a/src/backend/utils/adt/varlena.c b/src/backend/utils/adt/varlena.c
index 580ef561f5b..57cc01295e2 100644
--- a/src/backend/utils/adt/varlena.c
+++ b/src/backend/utils/adt/varlena.c
@@ -7,7 +7,7 @@
  *
  *
  * IDENTIFICATION
- *	  $Header: /cvsroot/pgsql/src/backend/utils/adt/varlena.c,v 1.24 1997/12/08 04:42:48 momjian Exp $
+ *	  $Header: /cvsroot/pgsql/src/backend/utils/adt/varlena.c,v 1.25 1997/12/16 15:59:11 thomas Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -210,20 +210,14 @@ textout(struct varlena * vlena)
  *	  returns the actual length of a text* (which may be less than
  *	  the VARSIZE of the text*)
  */
-#ifdef NOT_USED
 int
 textlen(text *t)
 {
-	int			i = 0;
-	int			max = VARSIZE(t) - VARHDRSZ;
-	char	   *ptr = VARDATA(t);
-
-	while (i < max && *ptr++)
-		i++;
-	return i;
-}
+	if (!PointerIsValid(t))
+		elog(WARN,"Null input to textlen");
 
-#endif
+	return (VARSIZE(t) - VARHDRSZ);
+} /* textlen() */
 
 /*
  * textcat -
-- 
GitLab