]> granicus.if.org Git - postgresql/blobdiff - src/backend/utils/adt/char.c
Add support for EUI-64 MAC addresses as macaddr8
[postgresql] / src / backend / utils / adt / char.c
index 1a5a70d430b4d030822879ed20cbc6f079eb6bfc..1b849e870354d9ca6c54f9175cd1b33b20ab6857 100644 (file)
@@ -4,12 +4,12 @@
  *       Functions for the built-in type "char" (not to be confused with
  *       bpchar, which is the SQL CHAR(n) type).
  *
- * Portions Copyright (c) 1996-2004, PostgreSQL Global Development Group
+ * Portions Copyright (c) 1996-2017, PostgreSQL Global Development Group
  * Portions Copyright (c) 1994, Regents of the University of California
  *
  *
  * IDENTIFICATION
- *       $PostgreSQL: pgsql/src/backend/utils/adt/char.c,v 1.41 2004/10/04 22:49:51 tgl Exp $
+ *       src/backend/utils/adt/char.c
  *
  *-------------------------------------------------------------------------
  */
 #include "libpq/pqformat.h"
 #include "utils/builtins.h"
 
-#ifndef SCHAR_MAX
-#define SCHAR_MAX (0x7F)
-#endif
-#ifndef SCHAR_MIN
-#define SCHAR_MIN (-SCHAR_MAX-1)
-#endif
-
-
 /*****************************************************************************
  *      USER I/O ROUTINES                                                                                                               *
  *****************************************************************************/
@@ -67,7 +59,7 @@ charout(PG_FUNCTION_ARGS)
  *             charrecv                        - converts external binary format to char
  *
  * The external representation is one byte, with no character set
- * conversion. This is somewhat dubious, perhaps, but in many
+ * conversion.  This is somewhat dubious, perhaps, but in many
  * cases people use char for a 1-byte binary type.
  */
 Datum
@@ -183,16 +175,16 @@ i4tochar(PG_FUNCTION_ARGS)
 Datum
 text_char(PG_FUNCTION_ARGS)
 {
-       text       *arg1 = PG_GETARG_TEXT_P(0);
+       text       *arg1 = PG_GETARG_TEXT_PP(0);
        char            result;
 
        /*
-        * An empty input string is converted to \0 (for consistency with
-        * charin). If the input is longer than one character, the excess data
-        * is silently discarded.
+        * An empty input string is converted to \0 (for consistency with charin).
+        * If the input is longer than one character, the excess data is silently
+        * discarded.
         */
-       if (VARSIZE(arg1) > VARHDRSZ)
-               result = *(VARDATA(arg1));
+       if (VARSIZE_ANY_EXHDR(arg1) > 0)
+               result = *(VARDATA_ANY(arg1));
        else
                result = '\0';
 
@@ -211,11 +203,11 @@ char_text(PG_FUNCTION_ARGS)
         */
        if (arg1 != '\0')
        {
-               VARATT_SIZEP(result) = VARHDRSZ + 1;
+               SET_VARSIZE(result, VARHDRSZ + 1);
                *(VARDATA(result)) = arg1;
        }
        else
-               VARATT_SIZEP(result) = VARHDRSZ;
+               SET_VARSIZE(result, VARHDRSZ);
 
        PG_RETURN_TEXT_P(result);
 }