LCOV - code coverage report
Current view: top level - src/odbc - sqlwchar.c (source / functions) Hit Total Coverage
Test: FreeTDS coverage Lines: 7 27 25.9 %
Date: 2024-04-18 21:21:48 Functions: 2 4 50.0 %

          Line data    Source code
       1             : /* FreeTDS - Library of routines accessing Sybase and Microsoft databases
       2             :  * Copyright (C) 2008  Ziglio Frediano
       3             :  *
       4             :  * This library is free software; you can redistribute it and/or
       5             :  * modify it under the terms of the GNU Library General Public
       6             :  * License as published by the Free Software Foundation; either
       7             :  * version 2 of the License, or (at your option) any later version.
       8             :  *
       9             :  * This library is distributed in the hope that it will be useful,
      10             :  * but WITHOUT ANY WARRANTY; without even the implied warranty of
      11             :  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
      12             :  * Library General Public License for more details.
      13             :  *
      14             :  * You should have received a copy of the GNU Library General Public
      15             :  * License along with this library; if not, write to the
      16             :  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
      17             :  * Boston, MA 02111-1307, USA.
      18             :  */
      19             : 
      20             : #include <config.h>
      21             : 
      22             : #include <stdarg.h>
      23             : #include <stdio.h>
      24             : 
      25             : #if HAVE_STDLIB_H
      26             : #include <stdlib.h>
      27             : #endif /* HAVE_STDLIB_H */
      28             : 
      29             : #include <freetds/odbc.h>
      30             : 
      31             : #include <freetds/iconv.h>
      32             : #include <freetds/encodings.h>
      33             : 
      34             : #if SIZEOF_SQLWCHAR != SIZEOF_WCHAR_T
      35       15969 : size_t sqlwcslen(const SQLWCHAR * s)
      36             : {
      37       15969 :         const SQLWCHAR *p = s;
      38             : 
      39      636493 :         while (*p)
      40      604555 :                 ++p;
      41       15969 :         return p - s;
      42             : }
      43             : 
      44             : #ifdef ENABLE_ODBC_WIDE
      45             : /**
      46             :  * Convert a SQLWCHAR string into a wchar_t
      47             :  * Used only for debugging purpose
      48             :  * \param str string to convert
      49             :  * \param bufs linked list of buffer
      50             :  * \return string converted
      51             :  */
      52           0 : const wchar_t *sqlwstr(const SQLWCHAR *str, SQLWSTRBUF **bufs)
      53             : {
      54             :         wchar_t *dst, *dst_end;
      55           0 :         const SQLWCHAR *src = str;
      56             :         SQLWSTRBUF *buf;
      57             : 
      58           0 :         if (!str)
      59             :                 return NULL;
      60             : 
      61             :         /* allocate buffer for string, we do not care for memory errors */
      62           0 :         buf = tds_new0(SQLWSTRBUF, 1);
      63           0 :         if (!buf)
      64             :                 return NULL;
      65           0 :         buf->next = *bufs;
      66           0 :         *bufs = buf;
      67             : 
      68           0 :         dst = buf->buf;
      69           0 :         dst_end = dst + (TDS_VECTOR_SIZE(buf->buf) - 1);
      70             : 
      71           0 :         for (; *src && dst < dst_end; *dst++ = *src++)
      72           0 :                 continue;
      73           0 :         *dst = L'\0';
      74             : 
      75           0 :         return buf->buf;
      76             : }
      77             : 
      78           0 : void sqlwstr_free(SQLWSTRBUF *bufs)
      79             : {
      80           0 :         while (bufs) {
      81           0 :                 SQLWSTRBUF *buf = bufs;
      82           0 :                 bufs = buf->next;
      83           0 :                 free(buf);
      84             :         }
      85           0 : }
      86             : #endif
      87             : #endif
      88             : 
      89             : #if SIZEOF_SQLWCHAR == 2
      90             : # if WORDS_BIGENDIAN
      91             : #  define ODBC_WIDE_CANONIC TDS_CHARSET_UCS_2BE
      92             : #  define ODBC_WIDE_CANONIC_UTF TDS_CHARSET_UTF_16BE
      93             : # else
      94             : #  define ODBC_WIDE_CANONIC TDS_CHARSET_UCS_2LE
      95             : #  define ODBC_WIDE_CANONIC_UTF TDS_CHARSET_UTF_16LE
      96             : # endif
      97             : #elif SIZEOF_SQLWCHAR == 4
      98             : # if WORDS_BIGENDIAN
      99             : #  define ODBC_WIDE_CANONIC TDS_CHARSET_UCS_4BE
     100             : # else
     101             : #  define ODBC_WIDE_CANONIC TDS_CHARSET_UCS_4LE
     102             : # endif
     103             : #else
     104             : #error SIZEOF_SQLWCHAR not supported !!
     105             : #endif
     106             : 
     107        1470 : int odbc_get_wide_canonic(TDSCONNECTION *conn)
     108             : {
     109             : #if SIZEOF_SQLWCHAR == 2
     110        1470 :         if (conn->char_convs[client2ucs2]->to.charset.canonic == TDS_CHARSET_UTF_16LE)
     111             :                 return ODBC_WIDE_CANONIC_UTF;
     112             : #endif
     113           0 :         return ODBC_WIDE_CANONIC;
     114             : }

Generated by: LCOV version 1.13