LCOV - code coverage report
Current view: top level - include/freetds/utils - string.h (source / functions) Hit Total Coverage
Test: FreeTDS coverage Lines: 5 5 100.0 %
Date: 2025-12-03 08:48:55 Functions: 0 0 -

          Line data    Source code
       1             : /* FreeTDS - Library of routines accessing Sybase and Microsoft databases
       2             :  * Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003, 2004  Brian Bruns
       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             : #ifndef _tdsguard_d2McTbRS3vmVcq0ls4BzwH_
      21             : #define _tdsguard_d2McTbRS3vmVcq0ls4BzwH_
      22             : 
      23             : #include <freetds/macros.h>
      24             : #include <freetds/bool.h>
      25             : 
      26             : #include <freetds/pushvis.h>
      27             : 
      28             : /** \addtogroup dstring
      29             :  * @{ 
      30             :  */
      31             : 
      32             : /**
      33             :  * Structure to hold a string.
      34             :  * Use tds_dstr_* functions/macros, do not access members directly.
      35             :  * There should be always a buffer.
      36             :  */
      37             : typedef struct tds_dstr {
      38             :         size_t dstr_size;
      39             :         char dstr_s[1];
      40             : } *DSTR;
      41             : 
      42             : /** Internal representation for an empty string */
      43             : extern const struct tds_dstr tds_str_empty;
      44             : 
      45             : /** Initializer, used to initialize string like in the following example
      46             :  * @code
      47             :  * DSTR s = DSTR_INITIALIZER;
      48             :  * @endcode
      49             :  */
      50             : #define DSTR_INITIALIZER ((struct tds_dstr*) &tds_str_empty)
      51             : 
      52             : /** init a string with empty */
      53             : static inline void
      54             : tds_dstr_init(DSTR * s)
      55             : {
      56      846409 :         *(s) = DSTR_INITIALIZER;
      57             : }
      58             : 
      59             : /** test if string is empty */
      60             : static inline bool
      61             : tds_dstr_isempty(const DSTR * s)
      62             : {
      63      341784 :         return (*s)->dstr_size == 0;
      64             : }
      65             : 
      66             : /**
      67             :  * Returns a buffer to edit the string.
      68             :  * Be careful to avoid buffer overflows and remember to
      69             :  * set the correct length at the end of the editing if changed.
      70             :  */
      71             : static inline char *
      72             : tds_dstr_buf(DSTR * s)
      73             : {
      74      194499 :         return (*s)->dstr_s;
      75             : }
      76             : 
      77             : /** Returns a C version (NUL terminated string) of dstr */
      78             : static inline const char *
      79             : tds_dstr_cstr(const DSTR * s)
      80             : {
      81      309261 :         return (*s)->dstr_s;
      82             : }
      83             : 
      84             : /** Returns the length of the string in bytes */
      85             : static inline size_t
      86             : tds_dstr_len(const DSTR * s)
      87             : {
      88       93611 :         return (*s)->dstr_size;
      89             : }
      90             : 
      91             : /** Make a string empty */
      92             : #define tds_dstr_empty(s) \
      93             :         tds_dstr_free(s)
      94             : 
      95             : void tds_dstr_zero(DSTR * s);
      96             : void tds_dstr_free(DSTR * s);
      97             : 
      98             : DSTR* tds_dstr_dup(DSTR * s, const DSTR * src) TDS_WUR;
      99             : DSTR* tds_dstr_copy(DSTR * s, const char *src) TDS_WUR;
     100             : DSTR* tds_dstr_copyn(DSTR * s, const char *src, size_t length) TDS_WUR;
     101             : DSTR* tds_dstr_set(DSTR * s, char *src) TDS_WUR;
     102             : 
     103             : DSTR* tds_dstr_setlen(DSTR *s, size_t length);
     104             : DSTR* tds_dstr_alloc(DSTR *s, size_t length) TDS_WUR;
     105             : 
     106             : /** @} */
     107             : 
     108             : #include <freetds/popvis.h>
     109             : 
     110             : #endif /* _tdsguard_d2McTbRS3vmVcq0ls4BzwH_ */

Generated by: LCOV version 1.13