~ubuntu-branches/ubuntu/oneiric/postgresql-9.1/oneiric-security

« back to all changes in this revision

Viewing changes to src/backend/utils/mb/conversion_procs/utf8_and_ascii/utf8_and_ascii.c

  • Committer: Bazaar Package Importer
  • Author(s): Martin Pitt
  • Date: 2011-05-11 10:41:53 UTC
  • Revision ID: james.westby@ubuntu.com-20110511104153-psbh2o58553fv1m0
Tags: upstream-9.1~beta1
ImportĀ upstreamĀ versionĀ 9.1~beta1

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*-------------------------------------------------------------------------
 
2
 *
 
3
 *        ASCII <--> UTF8
 
4
 *
 
5
 * Portions Copyright (c) 1996-2011, PostgreSQL Global Development Group
 
6
 * Portions Copyright (c) 1994, Regents of the University of California
 
7
 *
 
8
 * IDENTIFICATION
 
9
 *        src/backend/utils/mb/conversion_procs/utf8_and_ascii/utf8_and_ascii.c
 
10
 *
 
11
 *-------------------------------------------------------------------------
 
12
 */
 
13
 
 
14
#include "postgres.h"
 
15
#include "fmgr.h"
 
16
#include "mb/pg_wchar.h"
 
17
 
 
18
PG_MODULE_MAGIC;
 
19
 
 
20
PG_FUNCTION_INFO_V1(ascii_to_utf8);
 
21
PG_FUNCTION_INFO_V1(utf8_to_ascii);
 
22
 
 
23
extern Datum ascii_to_utf8(PG_FUNCTION_ARGS);
 
24
extern Datum utf8_to_ascii(PG_FUNCTION_ARGS);
 
25
 
 
26
/* ----------
 
27
 * conv_proc(
 
28
 *              INTEGER,        -- source encoding id
 
29
 *              INTEGER,        -- destination encoding id
 
30
 *              CSTRING,        -- source string (null terminated C string)
 
31
 *              CSTRING,        -- destination string (null terminated C string)
 
32
 *              INTEGER         -- source string length
 
33
 * ) returns VOID;
 
34
 * ----------
 
35
 */
 
36
 
 
37
Datum
 
38
ascii_to_utf8(PG_FUNCTION_ARGS)
 
39
{
 
40
        unsigned char *src = (unsigned char *) PG_GETARG_CSTRING(2);
 
41
        unsigned char *dest = (unsigned char *) PG_GETARG_CSTRING(3);
 
42
        int                     len = PG_GETARG_INT32(4);
 
43
 
 
44
        CHECK_ENCODING_CONVERSION_ARGS(PG_SQL_ASCII, PG_UTF8);
 
45
 
 
46
        /* this looks wrong, but basically we're just rejecting high-bit-set */
 
47
        pg_ascii2mic(src, dest, len);
 
48
 
 
49
        PG_RETURN_VOID();
 
50
}
 
51
 
 
52
Datum
 
53
utf8_to_ascii(PG_FUNCTION_ARGS)
 
54
{
 
55
        unsigned char *src = (unsigned char *) PG_GETARG_CSTRING(2);
 
56
        unsigned char *dest = (unsigned char *) PG_GETARG_CSTRING(3);
 
57
        int                     len = PG_GETARG_INT32(4);
 
58
 
 
59
        CHECK_ENCODING_CONVERSION_ARGS(PG_UTF8, PG_SQL_ASCII);
 
60
 
 
61
        /* this looks wrong, but basically we're just rejecting high-bit-set */
 
62
        pg_mic2ascii(src, dest, len);
 
63
 
 
64
        PG_RETURN_VOID();
 
65
}