\hypertarget{group__keyvalue}{}\section{Value Manipulation Methods}
\label{group__keyvalue}\index{Value Manipulation Methods@{Value Manipulation Methods}}


Methods to do various operations on Key values.  


Collaboration diagram for Value Manipulation Methods\+:
\nopagebreak
\begin{figure}[H]
\begin{center}
\leavevmode
\includegraphics[width=249pt]{group__keyvalue}
\end{center}
\end{figure}
\subsection*{Functions}
\begin{DoxyCompactItemize}
\item 
const void $\ast$ \hyperlink{group__keyvalue_ga6f29609c5da53c6dc26a98678d5752af}{key\+Value} (const Key $\ast$key)
\begin{DoxyCompactList}\small\item\em Return a pointer to the real internal {\ttfamily key} value. \end{DoxyCompactList}\item 
const char $\ast$ \hyperlink{group__keyvalue_ga880936f2481d28e6e2acbe7486a21d05}{key\+String} (const Key $\ast$key)
\begin{DoxyCompactList}\small\item\em Get the c-\/string representing the value. \end{DoxyCompactList}\item 
ssize\+\_\+t \hyperlink{group__keyvalue_gae326672fffb7474abfe9baf53b73217e}{key\+Get\+Value\+Size} (const Key $\ast$key)
\begin{DoxyCompactList}\small\item\em Returns the number of bytes needed to store the key value, including the N\+U\+LL terminator. \end{DoxyCompactList}\item 
ssize\+\_\+t \hyperlink{group__keyvalue_ga41b9fac5ccddafe407fc0ae1e2eb8778}{key\+Get\+String} (const Key $\ast$key, char $\ast$returned\+String, size\+\_\+t max\+Size)
\begin{DoxyCompactList}\small\item\em Get the value of a key as a string. \end{DoxyCompactList}\item 
ssize\+\_\+t \hyperlink{group__keyvalue_ga622bde1eb0e0c4994728331326340ef2}{key\+Set\+String} (Key $\ast$key, const char $\ast$new\+String\+Value)
\begin{DoxyCompactList}\small\item\em Set the value for {\ttfamily key} as {\ttfamily new\+String\+Value}. \end{DoxyCompactList}\item 
ssize\+\_\+t \hyperlink{group__keyvalue_ga4c0d8a4a11174197699c231e0b5c3c84}{key\+Get\+Binary} (const Key $\ast$key, void $\ast$returned\+Binary, size\+\_\+t max\+Size)
\begin{DoxyCompactList}\small\item\em Get the value of a key as a binary. \end{DoxyCompactList}\item 
ssize\+\_\+t \hyperlink{group__keyvalue_gaa50a5358fd328d373a45f395fa1b99e7}{key\+Set\+Binary} (Key $\ast$key, const void $\ast$new\+Binary, size\+\_\+t data\+Size)
\begin{DoxyCompactList}\small\item\em Set the value of a key as a binary. \end{DoxyCompactList}\end{DoxyCompactItemize}


\subsection{Detailed Description}
Methods to do various operations on Key values. 

A key can contain a value in different format. The most likely situation is, that the value is interpreted as text. Use \hyperlink{group__keyvalue_ga41b9fac5ccddafe407fc0ae1e2eb8778}{key\+Get\+String()} for that. You can save any Unicode Symbols and Elektra will take care that you get the same back, independent of your current environment.

In some situations this idea fails. When you need exactly the same value back without any interpretation of the characters, there is \hyperlink{group__keyvalue_gaa50a5358fd328d373a45f395fa1b99e7}{key\+Set\+Binary()}. If you use that, its very likely that your Configuration is not according to the standard. Also for Numbers, Booleans and Date you should use \hyperlink{group__keyvalue_ga41b9fac5ccddafe407fc0ae1e2eb8778}{key\+Get\+String()}. To do so, you might use strtod() strtol() and then atol() or atof() to convert back.

To use them\+: 
\begin{DoxyCode}
\textcolor{preprocessor}{#include <kdb.h>}
\end{DoxyCode}
 

\subsection{Function Documentation}
\mbox{\Hypertarget{group__keyvalue_ga4c0d8a4a11174197699c231e0b5c3c84}\label{group__keyvalue_ga4c0d8a4a11174197699c231e0b5c3c84}} 
\index{Value Manipulation Methods@{Value Manipulation Methods}!key\+Get\+Binary@{key\+Get\+Binary}}
\index{key\+Get\+Binary@{key\+Get\+Binary}!Value Manipulation Methods@{Value Manipulation Methods}}
\subsubsection{\texorpdfstring{key\+Get\+Binary()}{keyGetBinary()}}
{\footnotesize\ttfamily ssize\+\_\+t key\+Get\+Binary (\begin{DoxyParamCaption}\item[{const Key $\ast$}]{key,  }\item[{void $\ast$}]{returned\+Binary,  }\item[{size\+\_\+t}]{max\+Size }\end{DoxyParamCaption})}



Get the value of a key as a binary. 

If the type is not binary -\/1 will be returned.

When the binary data is empty (this is not the same as \char`\"{}\char`\"{}!) 0 will be returned and the returned\+Binary will not be changed.

For string values see \hyperlink{group__keyvalue_ga41b9fac5ccddafe407fc0ae1e2eb8778}{key\+Get\+String()} and \hyperlink{group__keytest_gaea7670778abd07fee0fe8ac12a149190}{key\+Is\+String()}.

When the returned\+Binary is to small to hold the data (its maximum size is given by max\+Size), the returned\+Binary will not be changed and -\/1 is returned.

\begin{DoxyParagraph}{Example\+:}

\begin{DoxyCode}
Key *key = \hyperlink{group__key_gad23c65b44bf48d773759e1f9a4d43b89}{keyNew} (\textcolor{stringliteral}{"user/keyname"}, KEY\_TYPE, KEY\_TYPE\_BINARY, \hyperlink{group__key_gga91fb3178848bd682000958089abbaf40aa8adb6fcb92dec58fb19410eacfdd403}{KEY\_END});
\textcolor{keywordtype}{char} buffer[300];

\textcolor{keywordflow}{if} (\hyperlink{group__keyvalue_ga4c0d8a4a11174197699c231e0b5c3c84}{keyGetBinary}(key,buffer,\textcolor{keyword}{sizeof}(buffer)) == -1)
\{
        \textcolor{comment}{// handle error}
\}
\end{DoxyCode}

\end{DoxyParagraph}

\begin{DoxyParams}{Parameters}
{\em key} & the object to gather the value from \\
\hline
{\em returned\+Binary} & pre-\/allocated memory to store a copy of the key value \\
\hline
{\em max\+Size} & number of bytes of pre-\/allocated memory in {\ttfamily returned\+Binary} \\
\hline
\end{DoxyParams}
\begin{DoxyReturn}{Returns}
the number of bytes actually copied to {\ttfamily returned\+Binary} 
\end{DoxyReturn}

\begin{DoxyRetVals}{Return values}
{\em 0} & if the binary is empty \\
\hline
{\em -\/1} & on N\+U\+LL pointers \\
\hline
{\em -\/1} & if max\+Size is 0 \\
\hline
{\em -\/1} & if max\+Size is too small for string \\
\hline
{\em -\/1} & if max\+Size is larger than S\+S\+I\+Z\+E\+\_\+\+M\+AX \\
\hline
{\em -\/1} & on type mismatch\+: binary expected, but found string \\
\hline
\end{DoxyRetVals}
\begin{DoxySeeAlso}{See also}
\hyperlink{group__keyvalue_ga6f29609c5da53c6dc26a98678d5752af}{key\+Value()}, \hyperlink{group__keyvalue_gae326672fffb7474abfe9baf53b73217e}{key\+Get\+Value\+Size()}, \hyperlink{group__keyvalue_gaa50a5358fd328d373a45f395fa1b99e7}{key\+Set\+Binary()} 

\hyperlink{group__keyvalue_ga41b9fac5ccddafe407fc0ae1e2eb8778}{key\+Get\+String()} and \hyperlink{group__keyvalue_ga622bde1eb0e0c4994728331326340ef2}{key\+Set\+String()} as preferred alternative to binary 

\hyperlink{group__keytest_ga9526b371087564e43e3dff8ad0dac949}{key\+Is\+Binary()} to see how to check for binary type 
\end{DoxySeeAlso}
\mbox{\Hypertarget{group__keyvalue_ga41b9fac5ccddafe407fc0ae1e2eb8778}\label{group__keyvalue_ga41b9fac5ccddafe407fc0ae1e2eb8778}} 
\index{Value Manipulation Methods@{Value Manipulation Methods}!key\+Get\+String@{key\+Get\+String}}
\index{key\+Get\+String@{key\+Get\+String}!Value Manipulation Methods@{Value Manipulation Methods}}
\subsubsection{\texorpdfstring{key\+Get\+String()}{keyGetString()}}
{\footnotesize\ttfamily ssize\+\_\+t key\+Get\+String (\begin{DoxyParamCaption}\item[{const Key $\ast$}]{key,  }\item[{char $\ast$}]{returned\+String,  }\item[{size\+\_\+t}]{max\+Size }\end{DoxyParamCaption})}



Get the value of a key as a string. 

When there is no value inside the string, 1 will be returned and the returned\+String will be empty \char`\"{}\char`\"{} to avoid programming errors that old strings are shown to the user.

For binary values see \hyperlink{group__keyvalue_ga4c0d8a4a11174197699c231e0b5c3c84}{key\+Get\+Binary()} and \hyperlink{group__keytest_ga9526b371087564e43e3dff8ad0dac949}{key\+Is\+Binary()}.

\begin{DoxyParagraph}{Example\+:}

\begin{DoxyCode}
Key *key = \hyperlink{group__key_gad23c65b44bf48d773759e1f9a4d43b89}{keyNew} (\textcolor{stringliteral}{"user/keyname"}, \hyperlink{group__key_gga91fb3178848bd682000958089abbaf40aa8adb6fcb92dec58fb19410eacfdd403}{KEY\_END});
\textcolor{keywordtype}{char} buffer[300];

\textcolor{keywordflow}{if} (\hyperlink{group__keyvalue_ga41b9fac5ccddafe407fc0ae1e2eb8778}{keyGetString}(key,buffer,\textcolor{keyword}{sizeof}(buffer)) == -1)
\{
        \textcolor{comment}{// handle error}
\} \textcolor{keywordflow}{else} \{
        printf (\textcolor{stringliteral}{"buffer: %s\(\backslash\)n"}, buffer);
\}
\end{DoxyCode}

\end{DoxyParagraph}

\begin{DoxyParams}{Parameters}
{\em key} & the object to gather the value from \\
\hline
{\em returned\+String} & pre-\/allocated memory to store a copy of the key value \\
\hline
{\em max\+Size} & number of bytes of allocated memory in {\ttfamily returned\+String} \\
\hline
\end{DoxyParams}
\begin{DoxyReturn}{Returns}
the number of bytes actually copied to {\ttfamily returned\+String}, including final N\+U\+LL 
\end{DoxyReturn}

\begin{DoxyRetVals}{Return values}
{\em 1} & if the string is empty \\
\hline
{\em -\/1} & on any N\+U\+LL pointers \\
\hline
{\em -\/1} & on type mismatch\+: string expected, but found binary \\
\hline
{\em -\/1} & max\+Size is 0 \\
\hline
{\em -\/1} & if max\+Size is too small for string \\
\hline
{\em -\/1} & if max\+Size is larger than S\+S\+I\+Z\+E\+\_\+\+M\+AX \\
\hline
\end{DoxyRetVals}
\begin{DoxySeeAlso}{See also}
\hyperlink{group__keyvalue_ga6f29609c5da53c6dc26a98678d5752af}{key\+Value()}, \hyperlink{group__keyvalue_gae326672fffb7474abfe9baf53b73217e}{key\+Get\+Value\+Size()}, \hyperlink{group__keyvalue_ga622bde1eb0e0c4994728331326340ef2}{key\+Set\+String()}, \hyperlink{group__keyvalue_ga880936f2481d28e6e2acbe7486a21d05}{key\+String()} 

\hyperlink{group__keyvalue_ga4c0d8a4a11174197699c231e0b5c3c84}{key\+Get\+Binary()} for working with binary data 
\end{DoxySeeAlso}
\mbox{\Hypertarget{group__keyvalue_gae326672fffb7474abfe9baf53b73217e}\label{group__keyvalue_gae326672fffb7474abfe9baf53b73217e}} 
\index{Value Manipulation Methods@{Value Manipulation Methods}!key\+Get\+Value\+Size@{key\+Get\+Value\+Size}}
\index{key\+Get\+Value\+Size@{key\+Get\+Value\+Size}!Value Manipulation Methods@{Value Manipulation Methods}}
\subsubsection{\texorpdfstring{key\+Get\+Value\+Size()}{keyGetValueSize()}}
{\footnotesize\ttfamily ssize\+\_\+t key\+Get\+Value\+Size (\begin{DoxyParamCaption}\item[{const Key $\ast$}]{key }\end{DoxyParamCaption})}



Returns the number of bytes needed to store the key value, including the N\+U\+LL terminator. 

It returns the correct size, independent of the Key Type. If it is a binary there might be \textquotesingle{}\textbackslash{}0\textquotesingle{} values in it.

For an empty string you need one byte to store the ending N\+U\+LL. For that reason 1 is returned. This is not true for binary data, so there might be returned 0 too.

A binary key has no \textquotesingle{}\textbackslash{}0\textquotesingle{} termination. String types have it, so to there length will be added 1 to have enough space to store it.

This method can be used with \hyperlink{internal_8c_a35cdc2e5caed3454cb73b4fc7f37858c}{elektra\+Malloc()} before \hyperlink{group__keyvalue_ga41b9fac5ccddafe407fc0ae1e2eb8778}{key\+Get\+String()} or \hyperlink{group__keyvalue_ga4c0d8a4a11174197699c231e0b5c3c84}{key\+Get\+Binary()} is called.


\begin{DoxyCode}
\textcolor{keywordtype}{char} *buffer;
buffer = \hyperlink{internal_8c_a35cdc2e5caed3454cb73b4fc7f37858c}{elektraMalloc} (\hyperlink{group__keyvalue_gae326672fffb7474abfe9baf53b73217e}{keyGetValueSize} (key));
\textcolor{comment}{// use this buffer to store the value (binary or string)}
\textcolor{comment}{// pass keyGetValueSize (key) for maxSize}
\end{DoxyCode}



\begin{DoxyParams}{Parameters}
{\em key} & the key object to work with \\
\hline
\end{DoxyParams}
\begin{DoxyReturn}{Returns}
the number of bytes needed to store the key value 
\end{DoxyReturn}

\begin{DoxyRetVals}{Return values}
{\em 1} & when there is no data and type is not binary \\
\hline
{\em 0} & when there is no data and type is binary \\
\hline
{\em -\/1} & on null pointer \\
\hline
\end{DoxyRetVals}
\begin{DoxySeeAlso}{See also}
\hyperlink{group__keyvalue_ga41b9fac5ccddafe407fc0ae1e2eb8778}{key\+Get\+String()}, \hyperlink{group__keyvalue_ga4c0d8a4a11174197699c231e0b5c3c84}{key\+Get\+Binary()}, \hyperlink{group__keyvalue_ga6f29609c5da53c6dc26a98678d5752af}{key\+Value()} 
\end{DoxySeeAlso}
\mbox{\Hypertarget{group__keyvalue_gaa50a5358fd328d373a45f395fa1b99e7}\label{group__keyvalue_gaa50a5358fd328d373a45f395fa1b99e7}} 
\index{Value Manipulation Methods@{Value Manipulation Methods}!key\+Set\+Binary@{key\+Set\+Binary}}
\index{key\+Set\+Binary@{key\+Set\+Binary}!Value Manipulation Methods@{Value Manipulation Methods}}
\subsubsection{\texorpdfstring{key\+Set\+Binary()}{keySetBinary()}}
{\footnotesize\ttfamily ssize\+\_\+t key\+Set\+Binary (\begin{DoxyParamCaption}\item[{Key $\ast$}]{key,  }\item[{const void $\ast$}]{new\+Binary,  }\item[{size\+\_\+t}]{data\+Size }\end{DoxyParamCaption})}



Set the value of a key as a binary. 

A private copy of {\ttfamily new\+Binary} will allocated and saved inside {\ttfamily key}, so the parameter can be deallocated after the call.

Binary values might be encoded in another way then string values depending on the plugin. Typically character encodings should not take place on binary data. Consider using a string key instead.

When new\+Binary is a N\+U\+LL pointer the binary will be freed and 0 will be returned.

\begin{DoxyNote}{Note}
The metadata \char`\"{}binary\char`\"{} will be set to mark that the key is binary from now on. When the key is already binary the metadata won\textquotesingle{}t be changed. This will only happen in the successful case, but not when -\/1 is returned.
\end{DoxyNote}

\begin{DoxyParams}{Parameters}
{\em key} & the object on which to set the value \\
\hline
{\em new\+Binary} & is a pointer to any binary data or N\+U\+LL to free the previous set data \\
\hline
{\em data\+Size} & number of bytes to copy from {\ttfamily new\+Binary} \\
\hline
\end{DoxyParams}
\begin{DoxyReturn}{Returns}
the number of bytes actually copied to internal struct storage 
\end{DoxyReturn}

\begin{DoxyRetVals}{Return values}
{\em 0} & when the internal binary was freed and is now a null pointer \\
\hline
{\em -\/1} & if key is a N\+U\+LL pointer \\
\hline
{\em -\/1} & when data\+Size is 0 (but new\+Binary not N\+U\+LL) or larger than S\+S\+I\+Z\+E\+\_\+\+M\+AX \\
\hline
\end{DoxyRetVals}
\begin{DoxySeeAlso}{See also}
\hyperlink{group__keyvalue_ga4c0d8a4a11174197699c231e0b5c3c84}{key\+Get\+Binary()} 

\hyperlink{group__keytest_ga9526b371087564e43e3dff8ad0dac949}{key\+Is\+Binary()} to check if the type is binary 

\hyperlink{group__keyvalue_ga41b9fac5ccddafe407fc0ae1e2eb8778}{key\+Get\+String()} and \hyperlink{group__keyvalue_ga622bde1eb0e0c4994728331326340ef2}{key\+Set\+String()} as preferred alternative to binary 
\end{DoxySeeAlso}
\mbox{\Hypertarget{group__keyvalue_ga622bde1eb0e0c4994728331326340ef2}\label{group__keyvalue_ga622bde1eb0e0c4994728331326340ef2}} 
\index{Value Manipulation Methods@{Value Manipulation Methods}!key\+Set\+String@{key\+Set\+String}}
\index{key\+Set\+String@{key\+Set\+String}!Value Manipulation Methods@{Value Manipulation Methods}}
\subsubsection{\texorpdfstring{key\+Set\+String()}{keySetString()}}
{\footnotesize\ttfamily ssize\+\_\+t key\+Set\+String (\begin{DoxyParamCaption}\item[{Key $\ast$}]{key,  }\item[{const char $\ast$}]{new\+String\+Value }\end{DoxyParamCaption})}



Set the value for {\ttfamily key} as {\ttfamily new\+String\+Value}. 

The function will allocate and save a private copy of {\ttfamily new\+String\+Value}, so the parameter can be freed after the call.

String values will be saved in backend storage, when kdb\+Set\+Key() will be called, in U\+T\+F-\/8 universal encoding, regardless of the program\textquotesingle{}s current encoding, when iconv plugin is present.

\begin{DoxyNote}{Note}
The type will be set to K\+E\+Y\+\_\+\+T\+Y\+P\+E\+\_\+\+S\+T\+R\+I\+NG. When the type of the key is already a string type it won\textquotesingle{}t be changed.
\end{DoxyNote}

\begin{DoxyParams}{Parameters}
{\em key} & the key to set the string value \\
\hline
{\em new\+String\+Value} & N\+U\+L\+L-\/terminated text string to be set as {\ttfamily key\textquotesingle{}s} value \\
\hline
\end{DoxyParams}
\begin{DoxyReturn}{Returns}
the number of bytes actually saved in private struct including final N\+U\+LL 
\end{DoxyReturn}

\begin{DoxyRetVals}{Return values}
{\em 1} & if new\+String\+Value is a N\+U\+LL pointer, this will make the string empty (string only containing null termination) \\
\hline
{\em -\/1} & if key is a N\+U\+LL pointer \\
\hline
\end{DoxyRetVals}
\begin{DoxySeeAlso}{See also}
\hyperlink{group__keyvalue_ga41b9fac5ccddafe407fc0ae1e2eb8778}{key\+Get\+String()}, \hyperlink{group__keyvalue_ga6f29609c5da53c6dc26a98678d5752af}{key\+Value()}, \hyperlink{group__keyvalue_ga880936f2481d28e6e2acbe7486a21d05}{key\+String()} 
\end{DoxySeeAlso}
\mbox{\Hypertarget{group__keyvalue_ga880936f2481d28e6e2acbe7486a21d05}\label{group__keyvalue_ga880936f2481d28e6e2acbe7486a21d05}} 
\index{Value Manipulation Methods@{Value Manipulation Methods}!key\+String@{key\+String}}
\index{key\+String@{key\+String}!Value Manipulation Methods@{Value Manipulation Methods}}
\subsubsection{\texorpdfstring{key\+String()}{keyString()}}
{\footnotesize\ttfamily const char$\ast$ key\+String (\begin{DoxyParamCaption}\item[{const Key $\ast$}]{key }\end{DoxyParamCaption})}



Get the c-\/string representing the value. 

Will return (null) on null pointers. Will return (binary) on binary data not ended with a null byte.

It is not checked if it is actually a string, only if it terminates for security reasons.

\begin{DoxyReturn}{Returns}
the c-\/string of the value 
\end{DoxyReturn}

\begin{DoxyRetVals}{Return values}
{\em (null)} & on null keys \\
\hline
{\em \char`\"{}\char`\"{}} & if no data found \\
\hline
{\em (binary)} & on binary keys\\
\hline
\end{DoxyRetVals}

\begin{DoxyParams}{Parameters}
{\em key} & the key object to get the string from \\
\hline
\end{DoxyParams}
\mbox{\Hypertarget{group__keyvalue_ga6f29609c5da53c6dc26a98678d5752af}\label{group__keyvalue_ga6f29609c5da53c6dc26a98678d5752af}} 
\index{Value Manipulation Methods@{Value Manipulation Methods}!key\+Value@{key\+Value}}
\index{key\+Value@{key\+Value}!Value Manipulation Methods@{Value Manipulation Methods}}
\subsubsection{\texorpdfstring{key\+Value()}{keyValue()}}
{\footnotesize\ttfamily const void$\ast$ key\+Value (\begin{DoxyParamCaption}\item[{const Key $\ast$}]{key }\end{DoxyParamCaption})}



Return a pointer to the real internal {\ttfamily key} value. 

This is a much more efficient version of \hyperlink{group__keyvalue_ga41b9fac5ccddafe407fc0ae1e2eb8778}{key\+Get\+String()} \hyperlink{group__keyvalue_ga4c0d8a4a11174197699c231e0b5c3c84}{key\+Get\+Binary()}, and you should use it if you are responsible enough to not mess up things. You are not allowed to modify anything in the returned string. If you need a copy of the Value, consider to use \hyperlink{group__keyvalue_ga41b9fac5ccddafe407fc0ae1e2eb8778}{key\+Get\+String()} or \hyperlink{group__keyvalue_ga4c0d8a4a11174197699c231e0b5c3c84}{key\+Get\+Binary()} instead.\hypertarget{group__keyvalue_string}{}\subsection{String Handling}\label{group__keyvalue_string}
If {\ttfamily key} is string (\hyperlink{group__keytest_gaea7670778abd07fee0fe8ac12a149190}{key\+Is\+String()}), you may cast the returned as a {\ttfamily \char`\"{}char $\ast$\char`\"{}} because you\textquotesingle{}ll get a N\+U\+LL terminated regular string.

\hyperlink{group__keyvalue_ga6f29609c5da53c6dc26a98678d5752af}{key\+Value()} returns \char`\"{}\char`\"{} in string mode when there is no value. The reason is 
\begin{DoxyCode}
key=\hyperlink{group__key_gad23c65b44bf48d773759e1f9a4d43b89}{keyNew}(0);
\hyperlink{group__keyvalue_ga622bde1eb0e0c4994728331326340ef2}{keySetString}(key,\textcolor{stringliteral}{""});
\hyperlink{group__keyvalue_ga6f29609c5da53c6dc26a98678d5752af}{keyValue}(key); \textcolor{comment}{// you would expect "" here}
\hyperlink{group__key_ga3df95bbc2494e3e6703ece5639be5bb1}{keyDel}(key);
\end{DoxyCode}
\hypertarget{group__keyvalue_binary}{}\subsection{Binary Data Handling}\label{group__keyvalue_binary}
If the data is binary, the size of the value must be determined by \hyperlink{group__keyvalue_gae326672fffb7474abfe9baf53b73217e}{key\+Get\+Value\+Size()}, any strlen() operations are not suitable to determine the size.

\hyperlink{group__keyvalue_ga6f29609c5da53c6dc26a98678d5752af}{key\+Value()} returns 0 in binary mode when there is no value. The reason is 
\begin{DoxyCode}
key=\hyperlink{group__key_gad23c65b44bf48d773759e1f9a4d43b89}{keyNew}(0);
\hyperlink{group__keyvalue_gaa50a5358fd328d373a45f395fa1b99e7}{keySetBinary}(key, 0, 0);
\hyperlink{group__keyvalue_ga6f29609c5da53c6dc26a98678d5752af}{keyValue}(key); \textcolor{comment}{// you would expect 0 here}

\hyperlink{group__keyvalue_gaa50a5358fd328d373a45f395fa1b99e7}{keySetBinary}(key,\textcolor{stringliteral}{""}, 1);
\hyperlink{group__keyvalue_ga6f29609c5da53c6dc26a98678d5752af}{keyValue}(key); \textcolor{comment}{// you would expect "" (a pointer to '\(\backslash\)0') here}

\textcolor{keywordtype}{int} i=23;
\hyperlink{group__keyvalue_gaa50a5358fd328d373a45f395fa1b99e7}{keySetBinary}(key, (\textcolor{keywordtype}{void}*)&i, 4);
(\textcolor{keywordtype}{int}*)\hyperlink{group__keyvalue_ga6f29609c5da53c6dc26a98678d5752af}{keyValue}(key); \textcolor{comment}{// you would expect a pointer to (int)23 here}
\hyperlink{group__key_ga3df95bbc2494e3e6703ece5639be5bb1}{keyDel}(key);
\end{DoxyCode}


\begin{DoxyNote}{Note}
Note that the Key structure keeps its own size field that is calculated by library internal calls, so to avoid inconsistencies, you must never use the pointer returned by \hyperlink{group__keyvalue_ga6f29609c5da53c6dc26a98678d5752af}{key\+Value()} method to set a new value. Use \hyperlink{group__keyvalue_ga622bde1eb0e0c4994728331326340ef2}{key\+Set\+String()} or \hyperlink{group__keyvalue_gaa50a5358fd328d373a45f395fa1b99e7}{key\+Set\+Binary()} instead.
\end{DoxyNote}
\begin{DoxyWarning}{Warning}
Binary keys will return a N\+U\+LL pointer when there is no data in contrast to \hyperlink{group__keyname_ga8e805c726a60da921d3736cda7813513}{key\+Name()}, \hyperlink{group__keyname_gaaff35e7ca8af5560c47e662ceb9465f5}{key\+Base\+Name()}, \hyperlink{owner_8c_af6485fb8599714b6bbd830cf915ffea5}{key\+Owner()} and \hyperlink{group__meta_gac89fd319783b3457db45b4c09e55274a}{key\+Comment()}. For string value the behaviour is the same.
\end{DoxyWarning}
\begin{DoxyParagraph}{Example\+:}

\begin{DoxyCode}
KDB *handle = \hyperlink{group__kdb_ga6808defe5870f328dd17910aacbdc6ca}{kdbOpen}();
KeySet *ks=\hyperlink{group__keyset_ga671e1aaee3ae9dc13b4834a4ddbd2c3c}{ksNew}(0, \hyperlink{kdbenum_8c_a7a28fce3773b2c873c94ac80b8b4cd54}{KS\_END});
Key *current=0;

kdbGetByName(handle,ks,\textcolor{stringliteral}{"system/sw/my"},\hyperlink{group__keyset_gga98a3d6a4016c9dad9cbd1a99a9c2a45aad9d03b36ee88ca5a774cc01b190c99b8}{KDB\_O\_SORT}|KDB\_O\_RECURSIVE);

\hyperlink{group__keyset_gabe793ff51f1728e3429c84a8a9086b70}{ksRewind}(ks);
\textcolor{keywordflow}{while} (current=\hyperlink{group__keyset_ga317321c9065b5a4b3e33fe1c399bcec9}{ksNext}(ks)) \{
        \textcolor{keywordtype}{size\_t} size=0;

        \textcolor{keywordflow}{if} (keyIsBin(current)) \{
                size=\hyperlink{group__keyvalue_gae326672fffb7474abfe9baf53b73217e}{keyGetValueSize}(current);
                printf(\textcolor{stringliteral}{"Key %s has a value of size %d bytes. Value: <BINARY>\(\backslash\)nComment: %s"},
                        \hyperlink{group__keyname_ga8e805c726a60da921d3736cda7813513}{keyName}(current),
                        size,
                        \hyperlink{group__meta_gac89fd319783b3457db45b4c09e55274a}{keyComment}(current));
        \} \textcolor{keywordflow}{else} \{
                size=\hyperlink{internal_8c_afd676487565d083a6ad5a1381095acd8}{elektraStrLen}((\textcolor{keywordtype}{char} *)\hyperlink{group__keyvalue_ga6f29609c5da53c6dc26a98678d5752af}{keyValue}(current));
                printf(\textcolor{stringliteral}{"Key %s has a value of size %d bytes. Value: %s\(\backslash\)nComment: %s"},
                        \hyperlink{group__keyname_ga8e805c726a60da921d3736cda7813513}{keyName}(current),
                        size,
                        (\textcolor{keywordtype}{char} *)\hyperlink{group__keyvalue_ga6f29609c5da53c6dc26a98678d5752af}{keyValue}(current),
                        \hyperlink{group__meta_gac89fd319783b3457db45b4c09e55274a}{keyComment}(current));
        \}
\}

\hyperlink{group__keyset_ga27e5c16473b02a422238c8d970db7ac8}{ksDel} (ks);
\hyperlink{group__kdb_gadb54dc9fda17ee07deb9444df745c96f}{kdbClose} (handle);
\end{DoxyCode}

\end{DoxyParagraph}

\begin{DoxyParams}{Parameters}
{\em key} & the key object to work with \\
\hline
\end{DoxyParams}
\begin{DoxyReturn}{Returns}
a pointer to internal value 
\end{DoxyReturn}

\begin{DoxyRetVals}{Return values}
{\em \char`\"{}\char`\"{}} & when there is no data and key is not binary \\
\hline
{\em 0} & where there is no data and key is binary \\
\hline
{\em 0} & on N\+U\+LL pointer \\
\hline
\end{DoxyRetVals}
\begin{DoxySeeAlso}{See also}
\hyperlink{group__keyvalue_gae326672fffb7474abfe9baf53b73217e}{key\+Get\+Value\+Size()}, \hyperlink{group__keyvalue_ga41b9fac5ccddafe407fc0ae1e2eb8778}{key\+Get\+String()}, \hyperlink{group__keyvalue_ga4c0d8a4a11174197699c231e0b5c3c84}{key\+Get\+Binary()} 
\end{DoxySeeAlso}
