\hypertarget{group__internal}{
\section{KDB Backends :: Internal Helper for Elektra}
\label{group__internal}\index{KDB Backends :: Internal Helper for Elektra@{KDB Backends :: Internal Helper for Elektra}}
}


Internal Methods for Elektra and Backends.  


\subsection*{Functions}
\begin{DoxyCompactItemize}
\item 
int \hyperlink{group__internal_ga2a0aa7edaa79853ac26703f270e8f3a1}{elektraStrCmp} (const char $\ast$s1, const char $\ast$s2)
\item 
int \hyperlink{group__internal_ga686ccc3bc298a5b38c2bac0192551acd}{elektraStrCaseCmp} (const char $\ast$s1, const char $\ast$s2)
\item 
int \hyperlink{group__internal_gab0432d6765c40a5408a204c43747f4d4}{elektraRealloc} (void $\ast$$\ast$buffer, size\_\-t size)
\item 
void \hyperlink{group__internal_ga7f572149d2e0bfe18023a6ac969f195c}{elektraFree} (void $\ast$ptr)
\item 
char $\ast$ \hyperlink{group__internal_gabe50f54adaf932e177a100fe4fddad26}{elektraStrDup} (const char $\ast$s)
\item 
char $\ast$ \hyperlink{group__internal_ga04ad42d215b2ce5ed83e1a9354f6ba94}{elektraStrNDup} (const char $\ast$s, size\_\-t l)
\item 
size\_\-t \hyperlink{group__internal_gafd676487565d083a6ad5a1381095acd8}{elektraStrLen} (const char $\ast$s)
\end{DoxyCompactItemize}


\subsection{Detailed Description}
Internal Methods for Elektra and Backends. To use them: 
\begin{DoxyCode}
 #include <kdbbackend.h>
\end{DoxyCode}


There are some areas where libraries have to reimplement some basic functions to archive support for non-\/standard systems, for testing purposes or to provide a little more convenience. 

\subsection{Function Documentation}
\hypertarget{group__internal_ga7f572149d2e0bfe18023a6ac969f195c}{
\index{internal@{internal}!elektraFree@{elektraFree}}
\index{elektraFree@{elektraFree}!internal@{internal}}
\subsubsection[{elektraFree}]{\setlength{\rightskip}{0pt plus 5cm}void elektraFree (
\begin{DoxyParamCaption}
\item[{void $\ast$}]{ ptr}
\end{DoxyParamCaption}
)}}
\label{group__internal_ga7f572149d2e0bfe18023a6ac969f195c}
Free memory of elektra or its backends.


\begin{DoxyParams}{Parameters}
\item[{\em ptr}]the pointer to free\end{DoxyParams}
\begin{DoxySeeAlso}{See also}
elektraMalloc 
\end{DoxySeeAlso}
\hypertarget{group__internal_gab0432d6765c40a5408a204c43747f4d4}{
\index{internal@{internal}!elektraRealloc@{elektraRealloc}}
\index{elektraRealloc@{elektraRealloc}!internal@{internal}}
\subsubsection[{elektraRealloc}]{\setlength{\rightskip}{0pt plus 5cm}int elektraRealloc (
\begin{DoxyParamCaption}
\item[{void $\ast$$\ast$}]{ buffer, }
\item[{size\_\-t}]{ size}
\end{DoxyParamCaption}
)}}
\label{group__internal_gab0432d6765c40a5408a204c43747f4d4}
Reallocate Storage in a save way.


\begin{DoxyCode}
if (elektraRealloc ((void **) & buffer, new_length) < 0) {
        // here comes the failure handler
        // you can still use the old buffer
#if DEBUG
        fprintf (stderr, "Reallocation error\n");
#endif
        free (buffer);
        buffer = 0;
        // return with error
}
 *
\end{DoxyCode}



\begin{DoxyParams}{Parameters}
\item[{\em buffer}]is a pointer to a malloc \item[{\em size}]is the new size for the memory \end{DoxyParams}
\begin{DoxyReturn}{Returns}
-\/1 on failure 

0 on success 
\end{DoxyReturn}
\hypertarget{group__internal_ga686ccc3bc298a5b38c2bac0192551acd}{
\index{internal@{internal}!elektraStrCaseCmp@{elektraStrCaseCmp}}
\index{elektraStrCaseCmp@{elektraStrCaseCmp}!internal@{internal}}
\subsubsection[{elektraStrCaseCmp}]{\setlength{\rightskip}{0pt plus 5cm}int elektraStrCaseCmp (
\begin{DoxyParamCaption}
\item[{const char $\ast$}]{ s1, }
\item[{const char $\ast$}]{ s2}
\end{DoxyParamCaption}
)}}
\label{group__internal_ga686ccc3bc298a5b38c2bac0192551acd}
Compare Strings ignoring case using kdb semantics.

TODO: semantics not correct Does not work with binary sort.


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

0 if s1 matches s2 

a positive number if s1 is greater than s2 
\end{DoxyReturn}
\hypertarget{group__internal_ga2a0aa7edaa79853ac26703f270e8f3a1}{
\index{internal@{internal}!elektraStrCmp@{elektraStrCmp}}
\index{elektraStrCmp@{elektraStrCmp}!internal@{internal}}
\subsubsection[{elektraStrCmp}]{\setlength{\rightskip}{0pt plus 5cm}int elektraStrCmp (
\begin{DoxyParamCaption}
\item[{const char $\ast$}]{ s1, }
\item[{const char $\ast$}]{ s2}
\end{DoxyParamCaption}
)}}
\label{group__internal_ga2a0aa7edaa79853ac26703f270e8f3a1}
Compare Strings using kdb semantics.


\begin{DoxyParams}{Parameters}
\item[{\em s1}]The first string to be compared \item[{\em s2}]The second string to be compared\end{DoxyParams}
/ is handled special, it will always be prefered for any other character.

\begin{DoxyReturn}{Returns}
a negative number if s1 is less than s2 

a number less than, equal to or greater than zero if s1 is found, respectively, to be less than, to match, or be greater than s2. 
\end{DoxyReturn}
\hypertarget{group__internal_gabe50f54adaf932e177a100fe4fddad26}{
\index{internal@{internal}!elektraStrDup@{elektraStrDup}}
\index{elektraStrDup@{elektraStrDup}!internal@{internal}}
\subsubsection[{elektraStrDup}]{\setlength{\rightskip}{0pt plus 5cm}char$\ast$ elektraStrDup (
\begin{DoxyParamCaption}
\item[{const char $\ast$}]{ s}
\end{DoxyParamCaption}
)}}
\label{group__internal_gabe50f54adaf932e177a100fe4fddad26}
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't use that function.
\end{DoxyNote}

\begin{DoxyParams}{Parameters}
\item[{\em s}]the null-\/terminated string to duplicate\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{group__internal_ga7f572149d2e0bfe18023a6ac969f195c}{elektraFree} 

\hyperlink{group__internal_gafd676487565d083a6ad5a1381095acd8}{elektraStrLen} 

\hyperlink{group__internal_ga04ad42d215b2ce5ed83e1a9354f6ba94}{elektraStrNDup} 
\end{DoxySeeAlso}
\hypertarget{group__internal_gafd676487565d083a6ad5a1381095acd8}{
\index{internal@{internal}!elektraStrLen@{elektraStrLen}}
\index{elektraStrLen@{elektraStrLen}!internal@{internal}}
\subsubsection[{elektraStrLen}]{\setlength{\rightskip}{0pt plus 5cm}size\_\-t elektraStrLen (
\begin{DoxyParamCaption}
\item[{const char $\ast$}]{ s}
\end{DoxyParamCaption}
)}}
\label{group__internal_gafd676487565d083a6ad5a1381095acd8}
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 NULL, \hyperlink{group__internal_gafd676487565d083a6ad5a1381095acd8}{elektraStrLen()} count bytes including the ending NULL.


\begin{DoxyParams}{Parameters}
\item[{\em s}]the string to get the length from \end{DoxyParams}
\begin{DoxyReturn}{Returns}
number of bytes used by the string, including the final NULL. 
\end{DoxyReturn}
\hypertarget{group__internal_ga04ad42d215b2ce5ed83e1a9354f6ba94}{
\index{internal@{internal}!elektraStrNDup@{elektraStrNDup}}
\index{elektraStrNDup@{elektraStrNDup}!internal@{internal}}
\subsubsection[{elektraStrNDup}]{\setlength{\rightskip}{0pt plus 5cm}char$\ast$ elektraStrNDup (
\begin{DoxyParamCaption}
\item[{const char $\ast$}]{ s, }
\item[{size\_\-t}]{ l}
\end{DoxyParamCaption}
)}}
\label{group__internal_ga04ad42d215b2ce5ed83e1a9354f6ba94}
Copy buffer into new allocated memory.

You need to free the memory yourself.

This function also works with $\backslash$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}
\item[{\em s}]must be a allocated buffer \item[{\em l}]the length of s \end{DoxyParams}
