\hypertarget{kdbhelper_8h}{}\section{kdbhelper.\+h File Reference}
\label{kdbhelper_8h}\index{kdbhelper.\+h@{kdbhelper.\+h}}


Helper for memory management.  


{\ttfamily \#include \char`\"{}kdbconfig.\+h\char`\"{}}\newline
{\ttfamily \#include $<$kdbtypes.\+h$>$}\newline
{\ttfamily \#include $<$stdarg.\+h$>$}\newline
{\ttfamily \#include $<$stddef.\+h$>$}\newline
Include dependency graph for kdbhelper.\+h\+:
\nopagebreak
\begin{figure}[H]
\begin{center}
\leavevmode
\includegraphics[width=325pt]{kdbhelper_8h__incl}
\end{center}
\end{figure}
This graph shows which files directly or indirectly include this file\+:
\nopagebreak
\begin{figure}[H]
\begin{center}
\leavevmode
\includegraphics[width=350pt]{kdbhelper_8h__dep__incl}
\end{center}
\end{figure}
\subsection*{Functions}
\begin{DoxyCompactItemize}
\item 
void $\ast$ \hyperlink{kdbhelper_8h_a35cdc2e5caed3454cb73b4fc7f37858c}{elektra\+Malloc} (size\+\_\+t size)
\begin{DoxyCompactList}\small\item\em Allocate memory for Elektra. \end{DoxyCompactList}\item 
void $\ast$ \hyperlink{kdbhelper_8h_a848ed030434c76176167fac6ab79429c}{elektra\+Calloc} (size\+\_\+t size)
\begin{DoxyCompactList}\small\item\em Allocate memory for Elektra. \end{DoxyCompactList}\item 
void \hyperlink{kdbhelper_8h_a7f572149d2e0bfe18023a6ac969f195c}{elektra\+Free} (void $\ast$ptr)
\begin{DoxyCompactList}\small\item\em Free memory of Elektra or its backends. \end{DoxyCompactList}\item 
int \hyperlink{kdbhelper_8h_ab0432d6765c40a5408a204c43747f4d4}{elektra\+Realloc} (void $\ast$$\ast$buffer, size\+\_\+t size)
\begin{DoxyCompactList}\small\item\em Reallocate Storage in a save way. \end{DoxyCompactList}\item 
char $\ast$ \hyperlink{kdbhelper_8h_abe50f54adaf932e177a100fe4fddad26}{elektra\+Str\+Dup} (const char $\ast$s)
\begin{DoxyCompactList}\small\item\em Copy string into new allocated memory. \end{DoxyCompactList}\item 
char $\ast$ \hyperlink{kdbhelper_8h_a04ad42d215b2ce5ed83e1a9354f6ba94}{elektra\+Str\+N\+Dup} (const char $\ast$s, size\+\_\+t l)
\begin{DoxyCompactList}\small\item\em Copy buffer into new allocated memory. \end{DoxyCompactList}\item 
char $\ast$ \hyperlink{kdbhelper_8h_a1a64d23660e0724a517dad25409f69e0}{elektra\+Format} (const char $\ast$format,...)
\begin{DoxyCompactList}\small\item\em Does string formatting in fresh allocated memory. \end{DoxyCompactList}\item 
char $\ast$ \hyperlink{kdbhelper_8h_abf1d4e3e507c0422bf4cc29a9fe92679}{elektra\+V\+Format} (const char $\ast$format, va\+\_\+list arg\+\_\+list)
\begin{DoxyCompactList}\small\item\em Does string formatting in fresh allocated memory. \end{DoxyCompactList}\item 
int \hyperlink{kdbhelper_8h_a2a0aa7edaa79853ac26703f270e8f3a1}{elektra\+Str\+Cmp} (const char $\ast$s1, const char $\ast$s2)
\begin{DoxyCompactList}\small\item\em Compare Strings. \end{DoxyCompactList}\item 
int \hyperlink{kdbhelper_8h_a686ccc3bc298a5b38c2bac0192551acd}{elektra\+Str\+Case\+Cmp} (const char $\ast$s1, const char $\ast$s2)
\begin{DoxyCompactList}\small\item\em Compare Strings ignoring case. \end{DoxyCompactList}\item 
int \hyperlink{kdbhelper_8h_aa39061cc72a17effc6b6777a899ae09d}{elektra\+Mem\+Case\+Cmp} (const char $\ast$s1, const char $\ast$s2, size\+\_\+t size)
\begin{DoxyCompactList}\small\item\em Compare two memory regions but make cmp chars uppercase before comparison. \end{DoxyCompactList}\item 
size\+\_\+t \hyperlink{kdbhelper_8h_afd676487565d083a6ad5a1381095acd8}{elektra\+Str\+Len} (const char $\ast$s)
\begin{DoxyCompactList}\small\item\em Calculates the length in bytes of a string. \end{DoxyCompactList}\end{DoxyCompactItemize}


\subsection{Detailed Description}
Helper for memory management. 

Should be always preferred. Can be used for profiling and tracing.

\begin{DoxyCopyright}{Copyright}
B\+SD License (see L\+I\+C\+E\+N\+S\+E.\+md or \href{https://www.libelektra.org}{\tt https\+://www.\+libelektra.\+org}) 
\end{DoxyCopyright}


\subsection{Function Documentation}
\mbox{\Hypertarget{kdbhelper_8h_a848ed030434c76176167fac6ab79429c}\label{kdbhelper_8h_a848ed030434c76176167fac6ab79429c}} 
\index{kdbhelper.\+h@{kdbhelper.\+h}!elektra\+Calloc@{elektra\+Calloc}}
\index{elektra\+Calloc@{elektra\+Calloc}!kdbhelper.\+h@{kdbhelper.\+h}}
\subsubsection{\texorpdfstring{elektra\+Calloc()}{elektraCalloc()}}
{\footnotesize\ttfamily void$\ast$ elektra\+Calloc (\begin{DoxyParamCaption}\item[{size\+\_\+t}]{size }\end{DoxyParamCaption})}



Allocate memory for Elektra. 

Memory will be set to 0.


\begin{DoxyParams}{Parameters}
{\em size} & the requested size \\
\hline
\end{DoxyParams}
\begin{DoxySeeAlso}{See also}
\hyperlink{internal_8c_a35cdc2e5caed3454cb73b4fc7f37858c}{elektra\+Malloc} 
\end{DoxySeeAlso}
\mbox{\Hypertarget{kdbhelper_8h_a1a64d23660e0724a517dad25409f69e0}\label{kdbhelper_8h_a1a64d23660e0724a517dad25409f69e0}} 
\index{kdbhelper.\+h@{kdbhelper.\+h}!elektra\+Format@{elektra\+Format}}
\index{elektra\+Format@{elektra\+Format}!kdbhelper.\+h@{kdbhelper.\+h}}
\subsubsection{\texorpdfstring{elektra\+Format()}{elektraFormat()}}
{\footnotesize\ttfamily char$\ast$ elektra\+Format (\begin{DoxyParamCaption}\item[{const char $\ast$}]{format,  }\item[{}]{... }\end{DoxyParamCaption})}



Does string formatting in fresh allocated memory. 


\begin{DoxyParams}{Parameters}
{\em format} & as in printf() \\
\hline
{\em ...} & as in printf()\\
\hline
\end{DoxyParams}
\begin{DoxyReturn}{Returns}
new allocated memory (free with elektra\+Free) 
\end{DoxyReturn}
\mbox{\Hypertarget{kdbhelper_8h_a7f572149d2e0bfe18023a6ac969f195c}\label{kdbhelper_8h_a7f572149d2e0bfe18023a6ac969f195c}} 
\index{kdbhelper.\+h@{kdbhelper.\+h}!elektra\+Free@{elektra\+Free}}
\index{elektra\+Free@{elektra\+Free}!kdbhelper.\+h@{kdbhelper.\+h}}
\subsubsection{\texorpdfstring{elektra\+Free()}{elektraFree()}}
{\footnotesize\ttfamily void elektra\+Free (\begin{DoxyParamCaption}\item[{void $\ast$}]{ptr }\end{DoxyParamCaption})}



Free memory of Elektra or its backends. 


\begin{DoxyParams}{Parameters}
{\em ptr} & the pointer to free\\
\hline
\end{DoxyParams}
If ptr is N\+U\+LL, no operation is performed.

\begin{DoxySeeAlso}{See also}
\hyperlink{internal_8c_a35cdc2e5caed3454cb73b4fc7f37858c}{elektra\+Malloc} 
\end{DoxySeeAlso}
\mbox{\Hypertarget{kdbhelper_8h_a35cdc2e5caed3454cb73b4fc7f37858c}\label{kdbhelper_8h_a35cdc2e5caed3454cb73b4fc7f37858c}} 
\index{kdbhelper.\+h@{kdbhelper.\+h}!elektra\+Malloc@{elektra\+Malloc}}
\index{elektra\+Malloc@{elektra\+Malloc}!kdbhelper.\+h@{kdbhelper.\+h}}
\subsubsection{\texorpdfstring{elektra\+Malloc()}{elektraMalloc()}}
{\footnotesize\ttfamily void$\ast$ elektra\+Malloc (\begin{DoxyParamCaption}\item[{size\+\_\+t}]{size }\end{DoxyParamCaption})}



Allocate memory for Elektra. 


\begin{DoxyCode}
\textcolor{keywordflow}{if} ((buffer = \hyperlink{internal_8c_a35cdc2e5caed3454cb73b4fc7f37858c}{elektraMalloc} (length)) == 0) \{
        \textcolor{comment}{// here comes the failure handler}
        \textcolor{comment}{// no allocation happened here, so don't use buffer}
\textcolor{preprocessor}{#if DEBUG}
        fprintf (stderr, \textcolor{stringliteral}{"Allocation error"});
\textcolor{preprocessor}{#endif}
        \textcolor{comment}{// return with error}
\}
\end{DoxyCode}



\begin{DoxyParams}{Parameters}
{\em size} & the requested size\\
\hline
\end{DoxyParams}
This function is compatible to A\+N\+S\+I-\/C malloc \begin{DoxySeeAlso}{See also}
\hyperlink{internal_8c_a7f572149d2e0bfe18023a6ac969f195c}{elektra\+Free} 

\hyperlink{internal_8c_a848ed030434c76176167fac6ab79429c}{elektra\+Calloc} 
\end{DoxySeeAlso}
\mbox{\Hypertarget{kdbhelper_8h_aa39061cc72a17effc6b6777a899ae09d}\label{kdbhelper_8h_aa39061cc72a17effc6b6777a899ae09d}} 
\index{kdbhelper.\+h@{kdbhelper.\+h}!elektra\+Mem\+Case\+Cmp@{elektra\+Mem\+Case\+Cmp}}
\index{elektra\+Mem\+Case\+Cmp@{elektra\+Mem\+Case\+Cmp}!kdbhelper.\+h@{kdbhelper.\+h}}
\subsubsection{\texorpdfstring{elektra\+Mem\+Case\+Cmp()}{elektraMemCaseCmp()}}
{\footnotesize\ttfamily int elektra\+Mem\+Case\+Cmp (\begin{DoxyParamCaption}\item[{const char $\ast$}]{s1,  }\item[{const char $\ast$}]{s2,  }\item[{size\+\_\+t}]{size }\end{DoxyParamCaption})}



Compare two memory regions but make cmp chars uppercase before comparison. 


\begin{DoxyParams}{Parameters}
{\em s1} & The first string to be compared \\
\hline
{\em s2} & The second string to be compared \\
\hline
{\em size} & to be compared\\
\hline
\end{DoxyParams}
\begin{DoxyReturn}{Returns}
a negative number if s1 is less than s2 
\end{DoxyReturn}

\begin{DoxyRetVals}{Return values}
{\em 0} & if s1 matches s2 \\
\hline
\end{DoxyRetVals}
\begin{DoxyReturn}{Returns}
a positive number if s1 is greater than s2 
\end{DoxyReturn}
\mbox{\Hypertarget{kdbhelper_8h_ab0432d6765c40a5408a204c43747f4d4}\label{kdbhelper_8h_ab0432d6765c40a5408a204c43747f4d4}} 
\index{kdbhelper.\+h@{kdbhelper.\+h}!elektra\+Realloc@{elektra\+Realloc}}
\index{elektra\+Realloc@{elektra\+Realloc}!kdbhelper.\+h@{kdbhelper.\+h}}
\subsubsection{\texorpdfstring{elektra\+Realloc()}{elektraRealloc()}}
{\footnotesize\ttfamily int elektra\+Realloc (\begin{DoxyParamCaption}\item[{void $\ast$$\ast$}]{buffer,  }\item[{size\+\_\+t}]{size }\end{DoxyParamCaption})}



Reallocate Storage in a save way. 


\begin{DoxyCode}
\textcolor{keywordflow}{if} (\hyperlink{internal_8c_ab0432d6765c40a5408a204c43747f4d4}{elektraRealloc} ((\textcolor{keywordtype}{void} **) & buffer, new\_length) < 0) \{
        \textcolor{comment}{// here comes the failure handler}
        \textcolor{comment}{// you can still use the old buffer}
\textcolor{preprocessor}{#if DEBUG}
        fprintf (stderr, \textcolor{stringliteral}{"Reallocation error\(\backslash\)n"});
\textcolor{preprocessor}{#endif}
        \hyperlink{internal_8c_a7f572149d2e0bfe18023a6ac969f195c}{elektraFree} (buffer);
        buffer = 0;
        \textcolor{comment}{// return with error}
\}
\end{DoxyCode}



\begin{DoxyParams}{Parameters}
{\em buffer} & is a pointer to a elektra\+Malloc \\
\hline
{\em size} & is the new size for the memory \\
\hline
\end{DoxyParams}

\begin{DoxyRetVals}{Return values}
{\em -\/1} & on failure \\
\hline
{\em 0} & on success \\
\hline
\end{DoxyRetVals}
\mbox{\Hypertarget{kdbhelper_8h_a686ccc3bc298a5b38c2bac0192551acd}\label{kdbhelper_8h_a686ccc3bc298a5b38c2bac0192551acd}} 
\index{kdbhelper.\+h@{kdbhelper.\+h}!elektra\+Str\+Case\+Cmp@{elektra\+Str\+Case\+Cmp}}
\index{elektra\+Str\+Case\+Cmp@{elektra\+Str\+Case\+Cmp}!kdbhelper.\+h@{kdbhelper.\+h}}
\subsubsection{\texorpdfstring{elektra\+Str\+Case\+Cmp()}{elektraStrCaseCmp()}}
{\footnotesize\ttfamily int elektra\+Str\+Case\+Cmp (\begin{DoxyParamCaption}\item[{const char $\ast$}]{s1,  }\item[{const char $\ast$}]{s2 }\end{DoxyParamCaption})}



Compare Strings ignoring case. 


\begin{DoxyParams}{Parameters}
{\em s1} & The first string to be compared \\
\hline
{\em s2} & The second string to be compared\\
\hline
\end{DoxyParams}
\begin{DoxyReturn}{Returns}
a negative number if s1 is less than s2 
\end{DoxyReturn}

\begin{DoxyRetVals}{Return values}
{\em 0} & if s1 matches s2 \\
\hline
\end{DoxyRetVals}
\begin{DoxyReturn}{Returns}
a positive number if s1 is greater than s2 
\end{DoxyReturn}
\mbox{\Hypertarget{kdbhelper_8h_a2a0aa7edaa79853ac26703f270e8f3a1}\label{kdbhelper_8h_a2a0aa7edaa79853ac26703f270e8f3a1}} 
\index{kdbhelper.\+h@{kdbhelper.\+h}!elektra\+Str\+Cmp@{elektra\+Str\+Cmp}}
\index{elektra\+Str\+Cmp@{elektra\+Str\+Cmp}!kdbhelper.\+h@{kdbhelper.\+h}}
\subsubsection{\texorpdfstring{elektra\+Str\+Cmp()}{elektraStrCmp()}}
{\footnotesize\ttfamily int elektra\+Str\+Cmp (\begin{DoxyParamCaption}\item[{const char $\ast$}]{s1,  }\item[{const char $\ast$}]{s2 }\end{DoxyParamCaption})}



Compare Strings. 


\begin{DoxyParams}{Parameters}
{\em s1} & The first string to be compared \\
\hline
{\em s2} & The second string to be compared\\
\hline
\end{DoxyParams}
\begin{DoxyReturn}{Returns}
a negative number if s1 is less than s2 
\end{DoxyReturn}

\begin{DoxyRetVals}{Return values}
{\em 0} & if s1 matches s2 \\
\hline
\end{DoxyRetVals}
\begin{DoxyReturn}{Returns}
a positive number if s1 is greater than s2 
\end{DoxyReturn}
\mbox{\Hypertarget{kdbhelper_8h_abe50f54adaf932e177a100fe4fddad26}\label{kdbhelper_8h_abe50f54adaf932e177a100fe4fddad26}} 
\index{kdbhelper.\+h@{kdbhelper.\+h}!elektra\+Str\+Dup@{elektra\+Str\+Dup}}
\index{elektra\+Str\+Dup@{elektra\+Str\+Dup}!kdbhelper.\+h@{kdbhelper.\+h}}
\subsubsection{\texorpdfstring{elektra\+Str\+Dup()}{elektraStrDup()}}
{\footnotesize\ttfamily char$\ast$ elektra\+Str\+Dup (\begin{DoxyParamCaption}\item[{const char $\ast$}]{s }\end{DoxyParamCaption})}



Copy string into new allocated memory. 

You need to free the memory yourself.

\begin{DoxyNote}{Note}
that size is determined at runtime. So if you have a size information, don\textquotesingle{}t use that function.
\end{DoxyNote}

\begin{DoxyParams}{Parameters}
{\em s} & the null-\/terminated string to duplicate\\
\hline
\end{DoxyParams}
\begin{DoxyReturn}{Returns}
0 if out of memory, a pointer otherwise 
\end{DoxyReturn}
\begin{DoxyPrecond}{Precondition}
s must be a c-\/string. 
\end{DoxyPrecond}
\begin{DoxySeeAlso}{See also}
\hyperlink{internal_8c_a7f572149d2e0bfe18023a6ac969f195c}{elektra\+Free} 

\hyperlink{internal_8c_afd676487565d083a6ad5a1381095acd8}{elektra\+Str\+Len} 

\hyperlink{internal_8c_a04ad42d215b2ce5ed83e1a9354f6ba94}{elektra\+Str\+N\+Dup} 
\end{DoxySeeAlso}
\mbox{\Hypertarget{kdbhelper_8h_afd676487565d083a6ad5a1381095acd8}\label{kdbhelper_8h_afd676487565d083a6ad5a1381095acd8}} 
\index{kdbhelper.\+h@{kdbhelper.\+h}!elektra\+Str\+Len@{elektra\+Str\+Len}}
\index{elektra\+Str\+Len@{elektra\+Str\+Len}!kdbhelper.\+h@{kdbhelper.\+h}}
\subsubsection{\texorpdfstring{elektra\+Str\+Len()}{elektraStrLen()}}
{\footnotesize\ttfamily size\+\_\+t elektra\+Str\+Len (\begin{DoxyParamCaption}\item[{const char $\ast$}]{s }\end{DoxyParamCaption})}



Calculates the length in bytes of a string. 

This function differs from strlen() because it is Unicode and multibyte chars safe. While strlen() counts characters and ignores the final N\+U\+LL, \hyperlink{internal_8c_afd676487565d083a6ad5a1381095acd8}{elektra\+Str\+Len()} count bytes including the ending N\+U\+LL.

It must not be used to search for / in the name, because it does not consider escaping. Instead use the unescaped name.

\begin{DoxySeeAlso}{See also}
\hyperlink{group__keyname_ga6fe6af4c27b35d911a533f4ae4d698bb}{key\+Unescaped\+Name()}
\end{DoxySeeAlso}

\begin{DoxyParams}{Parameters}
{\em s} & the string to get the length from \\
\hline
\end{DoxyParams}
\begin{DoxyReturn}{Returns}
number of bytes used by the string, including the final N\+U\+LL. 
\end{DoxyReturn}
\mbox{\Hypertarget{kdbhelper_8h_a04ad42d215b2ce5ed83e1a9354f6ba94}\label{kdbhelper_8h_a04ad42d215b2ce5ed83e1a9354f6ba94}} 
\index{kdbhelper.\+h@{kdbhelper.\+h}!elektra\+Str\+N\+Dup@{elektra\+Str\+N\+Dup}}
\index{elektra\+Str\+N\+Dup@{elektra\+Str\+N\+Dup}!kdbhelper.\+h@{kdbhelper.\+h}}
\subsubsection{\texorpdfstring{elektra\+Str\+N\+Dup()}{elektraStrNDup()}}
{\footnotesize\ttfamily char$\ast$ elektra\+Str\+N\+Dup (\begin{DoxyParamCaption}\item[{const char $\ast$}]{s,  }\item[{size\+\_\+t}]{l }\end{DoxyParamCaption})}



Copy buffer into new allocated memory. 

You need to free the memory yourself.

This function also works with \textbackslash{}0 characters in the buffer. The length is taken as given, it must be correct.

\begin{DoxyReturn}{Returns}
0 if out of memory, a pointer otherwise 
\end{DoxyReturn}

\begin{DoxyParams}{Parameters}
{\em s} & must be a allocated buffer \\
\hline
{\em l} & the length of s \\
\hline
\end{DoxyParams}
\mbox{\Hypertarget{kdbhelper_8h_abf1d4e3e507c0422bf4cc29a9fe92679}\label{kdbhelper_8h_abf1d4e3e507c0422bf4cc29a9fe92679}} 
\index{kdbhelper.\+h@{kdbhelper.\+h}!elektra\+V\+Format@{elektra\+V\+Format}}
\index{elektra\+V\+Format@{elektra\+V\+Format}!kdbhelper.\+h@{kdbhelper.\+h}}
\subsubsection{\texorpdfstring{elektra\+V\+Format()}{elektraVFormat()}}
{\footnotesize\ttfamily char$\ast$ elektra\+V\+Format (\begin{DoxyParamCaption}\item[{const char $\ast$}]{format,  }\item[{va\+\_\+list}]{arg\+\_\+list }\end{DoxyParamCaption})}



Does string formatting in fresh allocated memory. 


\begin{DoxyParams}{Parameters}
{\em format} & as in vprintf() \\
\hline
{\em arg\+\_\+list} & as in vprintf()\\
\hline
\end{DoxyParams}
\begin{DoxyReturn}{Returns}
new allocated memory (free with elektra\+Free) 
\end{DoxyReturn}
