88 *
99 *
1010 * IDENTIFICATION
11- * $PostgreSQL: pgsql/src/backend/utils/adt/varlena.c,v 1.122 2005/05/27 00:57:49 neilc Exp $
11+ * $PostgreSQL: pgsql/src/backend/utils/adt/varlena.c,v 1.123 2005/05/30 01:20:50 tgl Exp $
1212 *
1313 *-------------------------------------------------------------------------
1414 */
@@ -330,18 +330,10 @@ textsend(PG_FUNCTION_ARGS)
330330Datum
331331unknownin (PG_FUNCTION_ARGS )
332332{
333- char * inputStr = PG_GETARG_CSTRING (0 );
334- unknown * result ;
335- int len ;
336-
337- len = strlen (inputStr ) + VARHDRSZ ;
338-
339- result = (unknown * ) palloc (len );
340- VARATT_SIZEP (result ) = len ;
341-
342- memcpy (VARDATA (result ), inputStr , len - VARHDRSZ );
333+ char * str = PG_GETARG_CSTRING (0 );
343334
344- PG_RETURN_UNKNOWN_P (result );
335+ /* representation is same as cstring */
336+ PG_RETURN_CSTRING (pstrdup (str ));
345337}
346338
347339/*
@@ -350,16 +342,10 @@ unknownin(PG_FUNCTION_ARGS)
350342Datum
351343unknownout (PG_FUNCTION_ARGS )
352344{
353- unknown * t = PG_GETARG_UNKNOWN_P (0 );
354- int len ;
355- char * result ;
356-
357- len = VARSIZE (t ) - VARHDRSZ ;
358- result = (char * ) palloc (len + 1 );
359- memcpy (result , VARDATA (t ), len );
360- result [len ] = '\0' ;
345+ /* representation is same as cstring */
346+ char * str = PG_GETARG_CSTRING (0 );
361347
362- PG_RETURN_CSTRING (result );
348+ PG_RETURN_CSTRING (pstrdup ( str ) );
363349}
364350
365351/*
@@ -369,28 +355,27 @@ Datum
369355unknownrecv (PG_FUNCTION_ARGS )
370356{
371357 StringInfo buf = (StringInfo ) PG_GETARG_POINTER (0 );
372- unknown * result ;
358+ char * str ;
373359 int nbytes ;
374360
375- nbytes = buf -> len - buf -> cursor ;
376- result = (unknown * ) palloc (nbytes + VARHDRSZ );
377- VARATT_SIZEP (result ) = nbytes + VARHDRSZ ;
378- pq_copymsgbytes (buf , VARDATA (result ), nbytes );
379- PG_RETURN_UNKNOWN_P (result );
361+ str = pq_getmsgtext (buf , buf -> len - buf -> cursor , & nbytes );
362+ /* representation is same as cstring */
363+ PG_RETURN_CSTRING (str );
380364}
381365
382366/*
383367 * unknownsend - converts unknown to binary format
384- *
385- * This is a special case: just copy the input, since it's
386- * effectively the same format as bytea
387368 */
388369Datum
389370unknownsend (PG_FUNCTION_ARGS )
390371{
391- unknown * vlena = PG_GETARG_UNKNOWN_P_COPY (0 );
372+ /* representation is same as cstring */
373+ char * str = PG_GETARG_CSTRING (0 );
374+ StringInfoData buf ;
392375
393- PG_RETURN_UNKNOWN_P (vlena );
376+ pq_begintypsend (& buf );
377+ pq_sendtext (& buf , str , strlen (str ));
378+ PG_RETURN_BYTEA_P (pq_endtypsend (& buf ));
394379}
395380
396381
0 commit comments