LCOV - code coverage report
Current view: top level - source3/lib - substitute_generic.c (source / functions) Hit Total Coverage
Test: coverage report for v4-17-lts 011c5a9f Lines: 12 18 66.7 %
Date: 2026-05-29 04:08:37 Functions: 2 3 66.7 %

          Line data    Source code
       1             : /*
       2             :    Unix SMB/CIFS implementation.
       3             :    Samba utility functions
       4             : 
       5             :    Copyright (C) Andrew Tridgell 1992-2001
       6             :    Copyright (C) Simo Sorce      2001-2002
       7             :    Copyright (C) Martin Pool     2003
       8             :    Copyright (C) James Peach     2006
       9             :    Copyright (C) Jeremy Allison  1992-2007
      10             : 
      11             :    This program is free software; you can redistribute it and/or modify
      12             :    it under the terms of the GNU General Public License as published by
      13             :    the Free Software Foundation; either version 3 of the License, or
      14             :    (at your option) any later version.
      15             : 
      16             :    This program is distributed in the hope that it will be useful,
      17             :    but WITHOUT ANY WARRANTY; without even the implied warranty of
      18             :    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      19             :    GNU General Public License for more details.
      20             : 
      21             :    You should have received a copy of the GNU General Public License
      22             :    along with this program.  If not, see <http://www.gnu.org/licenses/>.
      23             : */
      24             : 
      25             : #include "includes.h"
      26             : 
      27           0 : void fstring_sub(char *s,const char *pattern,const char *insert)
      28             : {
      29           0 :         string_sub(s, pattern, insert, sizeof(fstring));
      30           0 : }
      31             : 
      32             : /**
      33             :  Similar to string_sub2, but it will accept only allocated strings
      34             :  and may realloc them so pay attention at what you pass on no
      35             :  pointers inside strings, no const may be passed
      36             :  as string.
      37             : **/
      38             : 
      39       43779 : char *realloc_string_sub2(char *string,
      40             :                         const char *pattern,
      41             :                         const char *insert,
      42             :                         bool remove_unsafe_characters,
      43             :                         bool allow_trailing_dollar)
      44             : {
      45       43779 :         const char *unsafe_characters = NULL;
      46       43779 :         char safe_character = '\0';
      47             :         bool ok;
      48             : 
      49       43779 :         if (!insert || !pattern || !*pattern || !string || !*string)
      50           0 :                 return NULL;
      51             : 
      52       43779 :         if (remove_unsafe_characters) {
      53       43779 :                 unsafe_characters = STRING_SUB_UNSAFE_CHARACTERS;
      54       43779 :                 safe_character = '_';
      55             :         }
      56             : 
      57       43779 :         ok = realloc_string_sub_raw(&string,
      58             :                                     pattern,
      59             :                                     insert,
      60             :                                     false,  /* replace_once */
      61             :                                     allow_trailing_dollar,
      62             :                                     unsafe_characters,
      63             :                                     safe_character);
      64       43779 :         if (!ok) {
      65           0 :                 DBG_ERR("out of memory, realloc_string_sub_raw()!\n");
      66             :                 /*
      67             :                  * The calling convention of realloc_string_sub2()
      68             :                  * is very strange regarding stale string pointers.
      69             :                  *
      70             :                  * It is assumed the given string was allocated
      71             :                  * on talloc_tos(), so we just don't touch
      72             :                  * it at all here...
      73             :                  */
      74           0 :                 return NULL;
      75             :         }
      76             : 
      77       43779 :         return string;
      78             : }
      79             : 
      80       43779 : char *realloc_string_sub(char *string,
      81             :                         const char *pattern,
      82             :                         const char *insert)
      83             : {
      84       43779 :         return realloc_string_sub2(string, pattern, insert, true, false);
      85             : }

Generated by: LCOV version 1.13