LCOV - code coverage report
Current view: top level - lib/util - util_strlist_v3.c (source / functions) Hit Total Coverage
Test: coverage report for master 2b515b7d Lines: 32 40 80.0 %
Date: 2024-02-28 12:06:22 Functions: 3 3 100.0 %

          Line data    Source code
       1             : /*
       2             :    Unix SMB/CIFS implementation.
       3             : 
       4             :    Copyright (C) Andrew Tridgell 2005
       5             :    Copyright (C) Jelmer Vernooij 2005
       6             : 
       7             :    This program is free software; you can redistribute it and/or modify
       8             :    it under the terms of the GNU General Public License as published by
       9             :    the Free Software Foundation; either version 3 of the License, or
      10             :    (at your option) any later version.
      11             : 
      12             :    This program is distributed in the hope that it will be useful,
      13             :    but WITHOUT ANY WARRANTY; without even the implied warranty of
      14             :    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      15             :    GNU General Public License for more details.
      16             : 
      17             :    You should have received a copy of the GNU General Public License
      18             :    along with this program.  If not, see <http://www.gnu.org/licenses/>.
      19             : */
      20             : 
      21             : #include "includes.h"
      22             : #include "system/locale.h"
      23             : #include "lib/util/tsort.h"
      24             : 
      25             : #undef strcasecmp
      26             : 
      27             : /**
      28             :  * @file
      29             :  * @brief String list manipulation v3
      30             :  */
      31             : 
      32             : /**
      33             :  * Needed for making an "unconst" list "const"
      34             :  */
      35    31215124 : _PUBLIC_ const char **const_str_list(char **list)
      36             : {
      37    31215124 :         return discard_const_p(const char *, list);
      38             : }
      39             : 
      40             : /**
      41             :  * str_list_make, v3 version. The v4 version does not
      42             :  * look at quoted strings with embedded blanks, so
      43             :  * do NOT merge this function please!
      44             :  */
      45             : #define S_LIST_ABS 16 /* List Allocation Block Size */
      46             : 
      47     4213674 : char **str_list_make_v3(TALLOC_CTX *mem_ctx, const char *string,
      48             :         const char *sep)
      49             : {
      50       18517 :         char **list;
      51       18517 :         const char *str;
      52       18517 :         char *s, *tok;
      53       18517 :         int num, lsize;
      54             : 
      55     4213674 :         if (!string || !*string)
      56       98173 :                 return NULL;
      57             : 
      58     4114881 :         list = talloc_array(mem_ctx, char *, S_LIST_ABS+1);
      59     4114881 :         if (list == NULL) {
      60           0 :                 return NULL;
      61             :         }
      62     4114881 :         lsize = S_LIST_ABS;
      63             : 
      64     4114881 :         s = talloc_strdup(list, string);
      65     4114881 :         if (s == NULL) {
      66           0 :                 DEBUG(0,("str_list_make: Unable to allocate memory\n"));
      67           0 :                 TALLOC_FREE(list);
      68           0 :                 return NULL;
      69             :         }
      70             : 
      71             :         /*
      72             :          * DON'T REPLACE THIS BY "LIST_SEP". The common version of
      73             :          * LIST_SEP does not contain the ;, which used to be accepted
      74             :          * by Samba 4.0 before param merges. It would be the far
      75             :          * better solution to split the _v3 version again to source3/
      76             :          * where it belongs, see the _v3 in its name.
      77             :          *
      78             :          * Unfortunately it is referenced in /lib/param/loadparm.c,
      79             :          * which depends on the version that the AD-DC mandates,
      80             :          * namely without the ; as part of the list separator. I am
      81             :          * missing the waf fu to properly work around the wrong
      82             :          * include paths here for this defect.
      83             :          */
      84     4114881 :         if (sep == NULL) {
      85     4114877 :                 sep = " \t,;\n\r";
      86             :         }
      87             : 
      88     4114881 :         num = 0;
      89     4114881 :         str = s;
      90             : 
      91    15680071 :         while (next_token_talloc(list, &str, &tok, sep)) {
      92             : 
      93    11565190 :                 if (num == lsize) {
      94           0 :                         char **tmp;
      95             : 
      96         254 :                         lsize += S_LIST_ABS;
      97             : 
      98         254 :                         tmp = talloc_realloc(mem_ctx, list, char *,
      99             :                                                    lsize + 1);
     100         254 :                         if (tmp == NULL) {
     101           0 :                                 DEBUG(0,("str_list_make: "
     102             :                                         "Unable to allocate memory\n"));
     103           0 :                                 TALLOC_FREE(list);
     104           0 :                                 return NULL;
     105             :                         }
     106             : 
     107         254 :                         list = tmp;
     108             : 
     109         254 :                         memset (&list[num], 0,
     110             :                                 ((sizeof(char*)) * (S_LIST_ABS +1)));
     111             :                 }
     112             : 
     113    11565190 :                 list[num] = tok;
     114    11565190 :                 num += 1;
     115             :         }
     116             : 
     117     4114881 :         list[num] = NULL;
     118             : 
     119     4114881 :         TALLOC_FREE(s);
     120     4114881 :         return list;
     121             : }
     122             : 
     123     1513259 : const char **str_list_make_v3_const(TALLOC_CTX *mem_ctx,
     124             :                                     const char *string,
     125             :                                     const char *sep)
     126             : {
     127     1513259 :         return const_str_list(str_list_make_v3(mem_ctx, string, sep));
     128             : }

Generated by: LCOV version 1.14