\hypertarget{group__key}{\section{Key}
\label{group__key}\index{Key@{Key}}
}


A Key is the essential class that encapsulates key \hyperlink{group__keyname}{name }, \hyperlink{group__keyvalue}{value } and \hyperlink{group__keymeta}{metainfo }.  


Collaboration diagram for Key\-:
\nopagebreak
\begin{figure}[H]
\begin{center}
\leavevmode
\includegraphics[width=290pt]{group__key}
\end{center}
\end{figure}
\subsection*{Modules}
\begin{DoxyCompactItemize}
\item 
\hyperlink{group__key__basic}{Basic Methods}
\begin{DoxyCompactList}\small\item\em Key construction and initialization methods. \end{DoxyCompactList}\item 
\hyperlink{group__keymeta}{Meta Info Manipulation Methods}
\begin{DoxyCompactList}\small\item\em Methods to do various operations on Key metainfo. \end{DoxyCompactList}\item 
\hyperlink{group__keytest}{Methods for Making Tests}
\begin{DoxyCompactList}\small\item\em Methods to do various tests on Keys. \end{DoxyCompactList}\item 
\hyperlink{group__keyname}{Name Manipulation Methods}
\begin{DoxyCompactList}\small\item\em Methods to do various operations on Key names. \end{DoxyCompactList}\item 
\hyperlink{group__keyvalue}{Value Manipulation Methods}
\begin{DoxyCompactList}\small\item\em Methods to do various operations on Key values. \end{DoxyCompactList}\end{DoxyCompactItemize}
\subsection*{Enumerations}
\begin{DoxyCompactItemize}
\item 
enum \hyperlink{group__key_ga91fb3178848bd682000958089abbaf40}{keyswitch\-\_\-t} \{ \\*
\hyperlink{group__key_gga91fb3178848bd682000958089abbaf40ad6127fc38f96410bf7c8f6e93b0397da}{K\-E\-Y\-\_\-\-N\-A\-M\-E} = 1, 
\hyperlink{group__key_gga91fb3178848bd682000958089abbaf40ac66e4a49d09212b79f5754ca6db5bd2e}{K\-E\-Y\-\_\-\-V\-A\-L\-U\-E} = 1$<$$<$1, 
\hyperlink{group__key_gga91fb3178848bd682000958089abbaf40a77ca60362fa8daca8d5347db4385068b}{K\-E\-Y\-\_\-\-O\-W\-N\-E\-R} = 1$<$$<$2, 
\hyperlink{group__key_gga91fb3178848bd682000958089abbaf40ac29427bb47cc31689d02912e36161ee3}{K\-E\-Y\-\_\-\-C\-O\-M\-M\-E\-N\-T} = 1$<$$<$3, 
\\*
\hyperlink{group__key_gga91fb3178848bd682000958089abbaf40a1ca18d4e094ae7487d35ecedda2235ff}{K\-E\-Y\-\_\-\-B\-I\-N\-A\-R\-Y} = 1$<$$<$4, 
\hyperlink{group__key_gga91fb3178848bd682000958089abbaf40a28f01a87d65f065172f734c9c9446c0e}{K\-E\-Y\-\_\-\-U\-I\-D} = 1$<$$<$5, 
\hyperlink{group__key_gga91fb3178848bd682000958089abbaf40ac0628bbaba7c837ca73323681393d15f}{K\-E\-Y\-\_\-\-G\-I\-D} = 1$<$$<$6, 
\hyperlink{group__key_gga91fb3178848bd682000958089abbaf40a1b0a91ff3a855d6993930ebf0abaa518}{K\-E\-Y\-\_\-\-M\-O\-D\-E} = 1$<$$<$7, 
\\*
\hyperlink{group__key_gga91fb3178848bd682000958089abbaf40af303f9ebb4983d7500ba8e06ef3ec178}{K\-E\-Y\-\_\-\-A\-T\-I\-M\-E} = 1$<$$<$8, 
\hyperlink{group__key_gga91fb3178848bd682000958089abbaf40abfbab4bf55be6c53a7ffb2e43a82b355}{K\-E\-Y\-\_\-\-M\-T\-I\-M\-E} = 1$<$$<$9, 
\hyperlink{group__key_gga91fb3178848bd682000958089abbaf40afbad53ecfc1512b1b49ca04b57a628b4}{K\-E\-Y\-\_\-\-C\-T\-I\-M\-E} = 1$<$$<$10, 
\hyperlink{group__key_gga91fb3178848bd682000958089abbaf40a6d531b5c41445d19d0452eebdccbfa01}{K\-E\-Y\-\_\-\-S\-I\-Z\-E} = 1$<$$<$11, 
\\*
\hyperlink{group__key_gga91fb3178848bd682000958089abbaf40a9e43e47c8a21478538e2d20e049981d5}{K\-E\-Y\-\_\-\-D\-I\-R} = 1$<$$<$14, 
\hyperlink{group__key_gga91fb3178848bd682000958089abbaf40aa8adb6fcb92dec58fb19410eacfdd403}{K\-E\-Y\-\_\-\-E\-N\-D} = 0
 \}
\end{DoxyCompactItemize}
\subsection*{Functions}
\begin{DoxyCompactItemize}
\item 
Key $\ast$ \hyperlink{group__key_gad23c65b44bf48d773759e1f9a4d43b89}{key\-New} (const char $\ast$name,...)
\item 
Key $\ast$ \hyperlink{group__key_gae6ec6a60cc4b8c1463fa08623d056ce3}{key\-Dup} (const Key $\ast$source)
\item 
int \hyperlink{group__key_ga6a12cbbe656a1ad9f41b8c681d7a2f92}{key\-Copy} (Key $\ast$dest, const Key $\ast$source)
\item 
int \hyperlink{group__key_ga3df95bbc2494e3e6703ece5639be5bb1}{key\-Del} (Key $\ast$key)
\item 
int \hyperlink{group__key_gab2242311a36bbc0520e0d36895107ec1}{key\-Clear} (Key $\ast$key)
\item 
ssize\-\_\-t \hyperlink{group__key_ga6970a6f254d67af7e39f8e469bb162f1}{key\-Inc\-Ref} (Key $\ast$key)
\item 
ssize\-\_\-t \hyperlink{group__key_ga2c6433ca22109e4e141946057eccb283}{key\-Dec\-Ref} (Key $\ast$key)
\item 
ssize\-\_\-t \hyperlink{group__key_ga4aabc4272506dd63161db2bbb42de8ae}{key\-Get\-Ref} (const Key $\ast$key)
\end{DoxyCompactItemize}


\subsection{Detailed Description}
A Key is the essential class that encapsulates key \hyperlink{group__keyname}{name }, \hyperlink{group__keyvalue}{value } and \hyperlink{group__keymeta}{metainfo }. 

\subsection{Enumeration Type Documentation}
\hypertarget{group__key_ga91fb3178848bd682000958089abbaf40}{\index{Key@{Key}!keyswitch\-\_\-t@{keyswitch\-\_\-t}}
\index{keyswitch\-\_\-t@{keyswitch\-\_\-t}!Key@{Key}}
\subsubsection[{keyswitch\-\_\-t}]{\setlength{\rightskip}{0pt plus 5cm}enum {\bf keyswitch\-\_\-t}}}\label{group__key_ga91fb3178848bd682000958089abbaf40}
Switches to denote the various Key attributes in methods throughout this library.

This enum switch provide a flag for every metadata in a key.

In case of \hyperlink{group__key_gad23c65b44bf48d773759e1f9a4d43b89}{key\-New()} they give Information what Parameter comes next.

\begin{DoxySeeAlso}{See Also}
\hyperlink{group__key_gad23c65b44bf48d773759e1f9a4d43b89}{key\-New()} 

ks\-To\-Stream(), key\-To\-Stream() 
\end{DoxySeeAlso}
\begin{Desc}
\item[Enumerator\-: ]\par
\begin{description}
\index{K\-E\-Y\-\_\-\-N\-A\-M\-E@{K\-E\-Y\-\_\-\-N\-A\-M\-E}!Key@{Key}}\index{Key@{Key}!K\-E\-Y\-\_\-\-N\-A\-M\-E@{K\-E\-Y\-\_\-\-N\-A\-M\-E}}\item[{\em 
\hypertarget{group__key_gga91fb3178848bd682000958089abbaf40ad6127fc38f96410bf7c8f6e93b0397da}{K\-E\-Y\-\_\-\-N\-A\-M\-E}\label{group__key_gga91fb3178848bd682000958089abbaf40ad6127fc38f96410bf7c8f6e93b0397da}
}]Flag for the key name \index{K\-E\-Y\-\_\-\-V\-A\-L\-U\-E@{K\-E\-Y\-\_\-\-V\-A\-L\-U\-E}!Key@{Key}}\index{Key@{Key}!K\-E\-Y\-\_\-\-V\-A\-L\-U\-E@{K\-E\-Y\-\_\-\-V\-A\-L\-U\-E}}\item[{\em 
\hypertarget{group__key_gga91fb3178848bd682000958089abbaf40ac66e4a49d09212b79f5754ca6db5bd2e}{K\-E\-Y\-\_\-\-V\-A\-L\-U\-E}\label{group__key_gga91fb3178848bd682000958089abbaf40ac66e4a49d09212b79f5754ca6db5bd2e}
}]Flag for the key data \index{K\-E\-Y\-\_\-\-O\-W\-N\-E\-R@{K\-E\-Y\-\_\-\-O\-W\-N\-E\-R}!Key@{Key}}\index{Key@{Key}!K\-E\-Y\-\_\-\-O\-W\-N\-E\-R@{K\-E\-Y\-\_\-\-O\-W\-N\-E\-R}}\item[{\em 
\hypertarget{group__key_gga91fb3178848bd682000958089abbaf40a77ca60362fa8daca8d5347db4385068b}{K\-E\-Y\-\_\-\-O\-W\-N\-E\-R}\label{group__key_gga91fb3178848bd682000958089abbaf40a77ca60362fa8daca8d5347db4385068b}
}]Flag for the key user domain \index{K\-E\-Y\-\_\-\-C\-O\-M\-M\-E\-N\-T@{K\-E\-Y\-\_\-\-C\-O\-M\-M\-E\-N\-T}!Key@{Key}}\index{Key@{Key}!K\-E\-Y\-\_\-\-C\-O\-M\-M\-E\-N\-T@{K\-E\-Y\-\_\-\-C\-O\-M\-M\-E\-N\-T}}\item[{\em 
\hypertarget{group__key_gga91fb3178848bd682000958089abbaf40ac29427bb47cc31689d02912e36161ee3}{K\-E\-Y\-\_\-\-C\-O\-M\-M\-E\-N\-T}\label{group__key_gga91fb3178848bd682000958089abbaf40ac29427bb47cc31689d02912e36161ee3}
}]Flag for the key comment \index{K\-E\-Y\-\_\-\-B\-I\-N\-A\-R\-Y@{K\-E\-Y\-\_\-\-B\-I\-N\-A\-R\-Y}!Key@{Key}}\index{Key@{Key}!K\-E\-Y\-\_\-\-B\-I\-N\-A\-R\-Y@{K\-E\-Y\-\_\-\-B\-I\-N\-A\-R\-Y}}\item[{\em 
\hypertarget{group__key_gga91fb3178848bd682000958089abbaf40a1ca18d4e094ae7487d35ecedda2235ff}{K\-E\-Y\-\_\-\-B\-I\-N\-A\-R\-Y}\label{group__key_gga91fb3178848bd682000958089abbaf40a1ca18d4e094ae7487d35ecedda2235ff}
}]Flag if the key is binary \index{K\-E\-Y\-\_\-\-U\-I\-D@{K\-E\-Y\-\_\-\-U\-I\-D}!Key@{Key}}\index{Key@{Key}!K\-E\-Y\-\_\-\-U\-I\-D@{K\-E\-Y\-\_\-\-U\-I\-D}}\item[{\em 
\hypertarget{group__key_gga91fb3178848bd682000958089abbaf40a28f01a87d65f065172f734c9c9446c0e}{K\-E\-Y\-\_\-\-U\-I\-D}\label{group__key_gga91fb3178848bd682000958089abbaf40a28f01a87d65f065172f734c9c9446c0e}
}]Flag for the key U\-I\-D \index{K\-E\-Y\-\_\-\-G\-I\-D@{K\-E\-Y\-\_\-\-G\-I\-D}!Key@{Key}}\index{Key@{Key}!K\-E\-Y\-\_\-\-G\-I\-D@{K\-E\-Y\-\_\-\-G\-I\-D}}\item[{\em 
\hypertarget{group__key_gga91fb3178848bd682000958089abbaf40ac0628bbaba7c837ca73323681393d15f}{K\-E\-Y\-\_\-\-G\-I\-D}\label{group__key_gga91fb3178848bd682000958089abbaf40ac0628bbaba7c837ca73323681393d15f}
}]Flag for the key G\-I\-D \index{K\-E\-Y\-\_\-\-M\-O\-D\-E@{K\-E\-Y\-\_\-\-M\-O\-D\-E}!Key@{Key}}\index{Key@{Key}!K\-E\-Y\-\_\-\-M\-O\-D\-E@{K\-E\-Y\-\_\-\-M\-O\-D\-E}}\item[{\em 
\hypertarget{group__key_gga91fb3178848bd682000958089abbaf40a1b0a91ff3a855d6993930ebf0abaa518}{K\-E\-Y\-\_\-\-M\-O\-D\-E}\label{group__key_gga91fb3178848bd682000958089abbaf40a1b0a91ff3a855d6993930ebf0abaa518}
}]Flag for the key permissions \index{K\-E\-Y\-\_\-\-A\-T\-I\-M\-E@{K\-E\-Y\-\_\-\-A\-T\-I\-M\-E}!Key@{Key}}\index{Key@{Key}!K\-E\-Y\-\_\-\-A\-T\-I\-M\-E@{K\-E\-Y\-\_\-\-A\-T\-I\-M\-E}}\item[{\em 
\hypertarget{group__key_gga91fb3178848bd682000958089abbaf40af303f9ebb4983d7500ba8e06ef3ec178}{K\-E\-Y\-\_\-\-A\-T\-I\-M\-E}\label{group__key_gga91fb3178848bd682000958089abbaf40af303f9ebb4983d7500ba8e06ef3ec178}
}]Flag for the key access time \index{K\-E\-Y\-\_\-\-M\-T\-I\-M\-E@{K\-E\-Y\-\_\-\-M\-T\-I\-M\-E}!Key@{Key}}\index{Key@{Key}!K\-E\-Y\-\_\-\-M\-T\-I\-M\-E@{K\-E\-Y\-\_\-\-M\-T\-I\-M\-E}}\item[{\em 
\hypertarget{group__key_gga91fb3178848bd682000958089abbaf40abfbab4bf55be6c53a7ffb2e43a82b355}{K\-E\-Y\-\_\-\-M\-T\-I\-M\-E}\label{group__key_gga91fb3178848bd682000958089abbaf40abfbab4bf55be6c53a7ffb2e43a82b355}
}]Flag for the key change time \index{K\-E\-Y\-\_\-\-C\-T\-I\-M\-E@{K\-E\-Y\-\_\-\-C\-T\-I\-M\-E}!Key@{Key}}\index{Key@{Key}!K\-E\-Y\-\_\-\-C\-T\-I\-M\-E@{K\-E\-Y\-\_\-\-C\-T\-I\-M\-E}}\item[{\em 
\hypertarget{group__key_gga91fb3178848bd682000958089abbaf40afbad53ecfc1512b1b49ca04b57a628b4}{K\-E\-Y\-\_\-\-C\-T\-I\-M\-E}\label{group__key_gga91fb3178848bd682000958089abbaf40afbad53ecfc1512b1b49ca04b57a628b4}
}]Flag for the key status change time \index{K\-E\-Y\-\_\-\-S\-I\-Z\-E@{K\-E\-Y\-\_\-\-S\-I\-Z\-E}!Key@{Key}}\index{Key@{Key}!K\-E\-Y\-\_\-\-S\-I\-Z\-E@{K\-E\-Y\-\_\-\-S\-I\-Z\-E}}\item[{\em 
\hypertarget{group__key_gga91fb3178848bd682000958089abbaf40a6d531b5c41445d19d0452eebdccbfa01}{K\-E\-Y\-\_\-\-S\-I\-Z\-E}\label{group__key_gga91fb3178848bd682000958089abbaf40a6d531b5c41445d19d0452eebdccbfa01}
}]Flag for maximum size to limit value \index{K\-E\-Y\-\_\-\-D\-I\-R@{K\-E\-Y\-\_\-\-D\-I\-R}!Key@{Key}}\index{Key@{Key}!K\-E\-Y\-\_\-\-D\-I\-R@{K\-E\-Y\-\_\-\-D\-I\-R}}\item[{\em 
\hypertarget{group__key_gga91fb3178848bd682000958089abbaf40a9e43e47c8a21478538e2d20e049981d5}{K\-E\-Y\-\_\-\-D\-I\-R}\label{group__key_gga91fb3178848bd682000958089abbaf40a9e43e47c8a21478538e2d20e049981d5}
}]Flag for the key directories \index{K\-E\-Y\-\_\-\-E\-N\-D@{K\-E\-Y\-\_\-\-E\-N\-D}!Key@{Key}}\index{Key@{Key}!K\-E\-Y\-\_\-\-E\-N\-D@{K\-E\-Y\-\_\-\-E\-N\-D}}\item[{\em 
\hypertarget{group__key_gga91fb3178848bd682000958089abbaf40aa8adb6fcb92dec58fb19410eacfdd403}{K\-E\-Y\-\_\-\-E\-N\-D}\label{group__key_gga91fb3178848bd682000958089abbaf40aa8adb6fcb92dec58fb19410eacfdd403}
}]Used as a parameter terminator to \hyperlink{group__key_gad23c65b44bf48d773759e1f9a4d43b89}{key\-New()} \end{description}
\end{Desc}



\subsection{Function Documentation}
\hypertarget{group__key_gab2242311a36bbc0520e0d36895107ec1}{\index{Key@{Key}!key\-Clear@{key\-Clear}}
\index{key\-Clear@{key\-Clear}!Key@{Key}}
\subsubsection[{key\-Clear}]{\setlength{\rightskip}{0pt plus 5cm}int key\-Clear (
\begin{DoxyParamCaption}
\item[{Key $\ast$}]{key}
\end{DoxyParamCaption}
)}}\label{group__key_gab2242311a36bbc0520e0d36895107ec1}
Key Object Cleaner.

Will reset all internal data.

After this call you will receive a fresh key.

The reference counter will stay unmodified.

\begin{DoxyNote}{Note}
that you might also clear() all aliases with this operation.
\end{DoxyNote}

\begin{DoxyCode}
\textcolor{keywordtype}{int} f (Key *k)
\{
        \hyperlink{group__key_gab2242311a36bbc0520e0d36895107ec1}{keyClear} (k);
        \textcolor{comment}{// you have a fresh key k here}
        \hyperlink{group__keyvalue_ga622bde1eb0e0c4994728331326340ef2}{keySetString} (k, \textcolor{stringliteral}{"value"});
        \textcolor{comment}{// the caller will get an empty key k with an value}
\}
\end{DoxyCode}


\begin{DoxyReturn}{Returns}
returns 0 on success 

-\/1 on null pointer
\end{DoxyReturn}

\begin{DoxyParams}{Parameters}
{\em key} & the key object to work with \\
\hline
\end{DoxyParams}
\hypertarget{group__key_ga6a12cbbe656a1ad9f41b8c681d7a2f92}{\index{Key@{Key}!key\-Copy@{key\-Copy}}
\index{key\-Copy@{key\-Copy}!Key@{Key}}
\subsubsection[{key\-Copy}]{\setlength{\rightskip}{0pt plus 5cm}int key\-Copy (
\begin{DoxyParamCaption}
\item[{Key $\ast$}]{dest, }
\item[{const Key $\ast$}]{source}
\end{DoxyParamCaption}
)}}\label{group__key_ga6a12cbbe656a1ad9f41b8c681d7a2f92}
Copy or Clear a key.

Most often you may prefer \hyperlink{group__key_gae6ec6a60cc4b8c1463fa08623d056ce3}{key\-Dup()} which allocates a new key and returns a duplication of another key.

But when you need to copy into an existing key, e.\-g. because it was passed by a pointer in a function you can do so\-:


\begin{DoxyCode}
\textcolor{keywordtype}{void} h (Key *k)
\{
        \textcolor{comment}{// receive key c}
        \hyperlink{group__key_ga6a12cbbe656a1ad9f41b8c681d7a2f92}{keyCopy} (k, c);
        \textcolor{comment}{// the caller will see the changed key k}
\}
\end{DoxyCode}


The reference counter will not be changed for both keys. Affiliation to keysets are also not affected.

When you pass a N\-U\-L\-L-\/pointer as source the data of dest will be cleaned completely (except reference counter, see \hyperlink{group__key_gab2242311a36bbc0520e0d36895107ec1}{key\-Clear()}) and you get a fresh dest key.


\begin{DoxyCode}
\textcolor{keywordtype}{void} g (Key *k)
\{
        \hyperlink{group__key_ga6a12cbbe656a1ad9f41b8c681d7a2f92}{keyCopy} (k, 0);
        \textcolor{comment}{// k is now an empty and fresh key}
\}
\end{DoxyCode}


The meta data will be duplicated for the destination key. So it will not take much additional space, even with lots of metadata.

If you want to copy all metadata, but keep the old value you can use \hyperlink{group__key_ga6a12cbbe656a1ad9f41b8c681d7a2f92}{key\-Copy()} too.


\begin{DoxyCode}
\textcolor{keywordtype}{void} j (Key *k)
\{
        \textcolor{keywordtype}{size\_t} size = \hyperlink{group__keyvalue_gae326672fffb7474abfe9baf53b73217e}{keyGetValueSize} (k);
        \textcolor{keywordtype}{char} *value = malloc (size);
        \textcolor{keywordtype}{int} bstring = \hyperlink{group__keytest_gaea7670778abd07fee0fe8ac12a149190}{keyIsString} (k);

        \textcolor{comment}{// receive key c}
        memcpy (value, \hyperlink{group__keyvalue_ga6f29609c5da53c6dc26a98678d5752af}{keyValue}(k), size);
        \hyperlink{group__key_ga6a12cbbe656a1ad9f41b8c681d7a2f92}{keyCopy} (k, c);
        \textcolor{keywordflow}{if} (bstring) \hyperlink{group__keyvalue_ga622bde1eb0e0c4994728331326340ef2}{keySetString} (k, value);
        \textcolor{keywordflow}{else} \hyperlink{group__keyvalue_gaa50a5358fd328d373a45f395fa1b99e7}{keySetBinary} (k, value, size);
        free (value);
        \textcolor{comment}{// the caller will see the changed key k}
        \textcolor{comment}{// with the metadata from c}
\}
\end{DoxyCode}


\begin{DoxyNote}{Note}
Next to the value itself we also need to remember if the value was string or binary. So in fact the meta data of the resulting key k in that example is not a complete duplicate, because the meta data \char`\"{}binary\char`\"{} may differ. Similar considerations might be necessary for the type of the key and so on, depending on the concrete situation.
\end{DoxyNote}

\begin{DoxyParams}{Parameters}
{\em dest} & the key which will be written to \\
\hline
{\em source} & the key which should be copied or N\-U\-L\-L to clean the destination key\\
\hline
\end{DoxyParams}
\begin{DoxyReturn}{Returns}
-\/1 on failure when a N\-U\-L\-L pointer was passed for dest or a dynamic property could not be written. Both name and value are empty then. 

0 when dest was cleaned 

1 when source was successfully copied 
\end{DoxyReturn}
\begin{DoxySeeAlso}{See Also}
\hyperlink{group__key_gae6ec6a60cc4b8c1463fa08623d056ce3}{key\-Dup()} to get a duplication of a \hyperlink{group__key}{Key} 
\end{DoxySeeAlso}
\hypertarget{group__key_ga2c6433ca22109e4e141946057eccb283}{\index{Key@{Key}!key\-Dec\-Ref@{key\-Dec\-Ref}}
\index{key\-Dec\-Ref@{key\-Dec\-Ref}!Key@{Key}}
\subsubsection[{key\-Dec\-Ref}]{\setlength{\rightskip}{0pt plus 5cm}ssize\-\_\-t key\-Dec\-Ref (
\begin{DoxyParamCaption}
\item[{Key $\ast$}]{key}
\end{DoxyParamCaption}
)}}\label{group__key_ga2c6433ca22109e4e141946057eccb283}
Decrement the viability of a key object.

The references will be decremented for \hyperlink{group__keyset_gae42530b04defb772059de0600159cf69}{ks\-Pop()} or successful calls of \hyperlink{group__keyset_gaa34fc43a081e6b01e4120daa6c112004}{ks\-Lookup()} with the option K\-D\-B\-\_\-\-O\-\_\-\-P\-O\-P. It will also be decremented with an following \hyperlink{group__key_ga3df95bbc2494e3e6703ece5639be5bb1}{key\-Del()} in the case that an old key is replaced with another key with the same name.

The reference counter can't be decremented once it reached 0. In that situation nothing will happen and 0 will be returned.

\begin{DoxyNote}{Note}
\hyperlink{group__key_gae6ec6a60cc4b8c1463fa08623d056ce3}{key\-Dup()} will reset the references for dupped key.
\end{DoxyNote}
\begin{DoxyReturn}{Returns}
the value of the new reference counter 

-\/1 on null pointer 

0 when the key is ready to be freed 
\end{DoxyReturn}

\begin{DoxyParams}{Parameters}
{\em key} & the key object to work with \\
\hline
\end{DoxyParams}
\begin{DoxySeeAlso}{See Also}
\hyperlink{group__key_ga4aabc4272506dd63161db2bbb42de8ae}{key\-Get\-Ref()}, \hyperlink{group__key_ga3df95bbc2494e3e6703ece5639be5bb1}{key\-Del()}, \hyperlink{group__key_ga6970a6f254d67af7e39f8e469bb162f1}{key\-Inc\-Ref()} 
\end{DoxySeeAlso}
\hypertarget{group__key_ga3df95bbc2494e3e6703ece5639be5bb1}{\index{Key@{Key}!key\-Del@{key\-Del}}
\index{key\-Del@{key\-Del}!Key@{Key}}
\subsubsection[{key\-Del}]{\setlength{\rightskip}{0pt plus 5cm}int key\-Del (
\begin{DoxyParamCaption}
\item[{Key $\ast$}]{key}
\end{DoxyParamCaption}
)}}\label{group__key_ga3df95bbc2494e3e6703ece5639be5bb1}
A destructor for Key objects.

Every key created by \hyperlink{group__key_gad23c65b44bf48d773759e1f9a4d43b89}{key\-New()} must be deleted with \hyperlink{group__key_ga3df95bbc2494e3e6703ece5639be5bb1}{key\-Del()}.

It is save to delete keys which are in a keyset, the number of references will be returned then.

It is save to delete a nullpointer, -\/1 will be returned then.

It is also save to delete a multiple referenced key, nothing will happen then and the reference counter will be returned.


\begin{DoxyParams}{Parameters}
{\em key} & the key object to delete \\
\hline
\end{DoxyParams}
\begin{DoxySeeAlso}{See Also}
\hyperlink{group__key_gad23c65b44bf48d773759e1f9a4d43b89}{key\-New()}, key\-Inc(), \hyperlink{group__key_ga4aabc4272506dd63161db2bbb42de8ae}{key\-Get\-Ref()} 
\end{DoxySeeAlso}
\begin{DoxyReturn}{Returns}
the value of the reference counter if the key is within keyset(s) 

0 when the key was freed 

-\/1 on null pointers 
\end{DoxyReturn}
\hypertarget{group__key_gae6ec6a60cc4b8c1463fa08623d056ce3}{\index{Key@{Key}!key\-Dup@{key\-Dup}}
\index{key\-Dup@{key\-Dup}!Key@{Key}}
\subsubsection[{key\-Dup}]{\setlength{\rightskip}{0pt plus 5cm}Key$\ast$ key\-Dup (
\begin{DoxyParamCaption}
\item[{const Key $\ast$}]{source}
\end{DoxyParamCaption}
)}}\label{group__key_gae6ec6a60cc4b8c1463fa08623d056ce3}
Return a duplicate of a key.

Memory will be allocated as needed for dynamic properties.

The new key will not be member of any Key\-Set and will start with a new reference counter at 0. A subsequent \hyperlink{group__key_ga3df95bbc2494e3e6703ece5639be5bb1}{key\-Del()} will delete the key.


\begin{DoxyCode}
\textcolor{keywordtype}{int} f (\textcolor{keyword}{const} Key * source)
\{
        Key * dup = \hyperlink{group__key_gae6ec6a60cc4b8c1463fa08623d056ce3}{keyDup} (source);
        \textcolor{comment}{// work with duplicate}
        \hyperlink{group__key_ga3df95bbc2494e3e6703ece5639be5bb1}{keyDel} (dup);
        \textcolor{comment}{// everything related to dup is freed}
        \textcolor{comment}{// and source is unchanged}
\}
\end{DoxyCode}


Like for a new key after \hyperlink{group__key_gad23c65b44bf48d773759e1f9a4d43b89}{key\-New()} a subsequent \hyperlink{group__keyset_ga21eb9c3a14a604ee3a8bdc779232e7b7}{ks\-Append()} makes a Key\-Set to take care of the lifecycle of the key.


\begin{DoxyCode}
\textcolor{keywordtype}{int} g (\textcolor{keyword}{const} Key * source, KeySet * ks)
\{
        Key * dup = \hyperlink{group__key_gae6ec6a60cc4b8c1463fa08623d056ce3}{keyDup} (source);
        \textcolor{comment}{// work with duplicate}
        \hyperlink{group__keyset_gaa5a1d467a4d71041edce68ea7748ce45}{ksAppendKey} (ks, dup);
        \textcolor{comment}{// ksDel(ks) will also free the duplicate}
        \textcolor{comment}{// source remains unchanged.}
\}
\end{DoxyCode}


Duplication of keys should be preferred to \hyperlink{group__key_gad23c65b44bf48d773759e1f9a4d43b89}{key\-New()}, because data like owner can be filled with a copy of the key instead of asking the environment. It can also be optimized in the checks, because the keyname is known to be valid.


\begin{DoxyParams}{Parameters}
{\em source} & has to be an initialized source Key \\
\hline
\end{DoxyParams}
\begin{DoxyReturn}{Returns}
0 failure or on N\-U\-L\-L pointer 

a fully copy of source on success 
\end{DoxyReturn}
\begin{DoxySeeAlso}{See Also}
\hyperlink{group__keyset_ga21eb9c3a14a604ee3a8bdc779232e7b7}{ks\-Append()}, \hyperlink{group__key_ga3df95bbc2494e3e6703ece5639be5bb1}{key\-Del()}, \hyperlink{group__key_gad23c65b44bf48d773759e1f9a4d43b89}{key\-New()} 
\end{DoxySeeAlso}
\hypertarget{group__key_ga4aabc4272506dd63161db2bbb42de8ae}{\index{Key@{Key}!key\-Get\-Ref@{key\-Get\-Ref}}
\index{key\-Get\-Ref@{key\-Get\-Ref}!Key@{Key}}
\subsubsection[{key\-Get\-Ref}]{\setlength{\rightskip}{0pt plus 5cm}ssize\-\_\-t key\-Get\-Ref (
\begin{DoxyParamCaption}
\item[{const Key $\ast$}]{key}
\end{DoxyParamCaption}
)}}\label{group__key_ga4aabc4272506dd63161db2bbb42de8ae}
Return how many references the key has.

The references will be incremented on successful calls to \hyperlink{group__keyset_gaa5a1d467a4d71041edce68ea7748ce45}{ks\-Append\-Key()} or \hyperlink{group__keyset_ga21eb9c3a14a604ee3a8bdc779232e7b7}{ks\-Append()}.

\begin{DoxyNote}{Note}
\hyperlink{group__key_gae6ec6a60cc4b8c1463fa08623d056ce3}{key\-Dup()} will reset the references for dupped key.
\end{DoxyNote}
For your own applications you can use \hyperlink{group__key_ga6970a6f254d67af7e39f8e469bb162f1}{key\-Inc\-Ref()} and \hyperlink{group__key_ga2c6433ca22109e4e141946057eccb283}{key\-Dec\-Ref()} for reference counting. Keys with zero references will be deleted when using \hyperlink{group__key_ga3df95bbc2494e3e6703ece5639be5bb1}{key\-Del()}.


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

-\/1 on null pointer 
\end{DoxyReturn}
\begin{DoxySeeAlso}{See Also}
\hyperlink{group__key_ga6970a6f254d67af7e39f8e469bb162f1}{key\-Inc\-Ref()} and \hyperlink{group__key_ga2c6433ca22109e4e141946057eccb283}{key\-Dec\-Ref()} 
\end{DoxySeeAlso}
\hypertarget{group__key_ga6970a6f254d67af7e39f8e469bb162f1}{\index{Key@{Key}!key\-Inc\-Ref@{key\-Inc\-Ref}}
\index{key\-Inc\-Ref@{key\-Inc\-Ref}!Key@{Key}}
\subsubsection[{key\-Inc\-Ref}]{\setlength{\rightskip}{0pt plus 5cm}ssize\-\_\-t key\-Inc\-Ref (
\begin{DoxyParamCaption}
\item[{Key $\ast$}]{key}
\end{DoxyParamCaption}
)}}\label{group__key_ga6970a6f254d67af7e39f8e469bb162f1}
Increment the viability of a key object.

This function is intended for applications using their own reference counter for key objects. With it you can increment the reference and thus avoid destruction of the object in a subsequent \hyperlink{group__key_ga3df95bbc2494e3e6703ece5639be5bb1}{key\-Del()}.


\begin{DoxyCode}
Key *k;
keyInc (k);
function\_that\_keyDec(k);
\textcolor{comment}{// work with k}
\hyperlink{group__key_ga3df95bbc2494e3e6703ece5639be5bb1}{keyDel} (k); \textcolor{comment}{// now really free it}
\end{DoxyCode}


The reference counter can't be incremented once it reached S\-S\-I\-Z\-E\-\_\-\-M\-A\-X. In that situation nothing will happen and S\-S\-I\-Z\-E\-\_\-\-M\-A\-X will be returned.

\begin{DoxyNote}{Note}
\hyperlink{group__key_gae6ec6a60cc4b8c1463fa08623d056ce3}{key\-Dup()} will reset the references for dupped key.
\end{DoxyNote}
\begin{DoxyReturn}{Returns}
the value of the new reference counter 

-\/1 on null pointer 

S\-S\-I\-Z\-E\-\_\-\-M\-A\-X when maximum exceeded 
\end{DoxyReturn}

\begin{DoxyParams}{Parameters}
{\em key} & the key object to work with \\
\hline
\end{DoxyParams}
\begin{DoxySeeAlso}{See Also}
\hyperlink{group__key_ga4aabc4272506dd63161db2bbb42de8ae}{key\-Get\-Ref()}, \hyperlink{group__key_ga2c6433ca22109e4e141946057eccb283}{key\-Dec\-Ref()}, \hyperlink{group__key_ga3df95bbc2494e3e6703ece5639be5bb1}{key\-Del()} 
\end{DoxySeeAlso}
\hypertarget{group__key_gad23c65b44bf48d773759e1f9a4d43b89}{\index{Key@{Key}!key\-New@{key\-New}}
\index{key\-New@{key\-New}!Key@{Key}}
\subsubsection[{key\-New}]{\setlength{\rightskip}{0pt plus 5cm}Key$\ast$ key\-New (
\begin{DoxyParamCaption}
\item[{const char $\ast$}]{name, }
\item[{}]{...}
\end{DoxyParamCaption}
)}}\label{group__key_gad23c65b44bf48d773759e1f9a4d43b89}
A practical way to fully create a Key object in one step.

This function tries to mimic the C++ way for constructors.

To just get a key object, simple do\-: 
\begin{DoxyCode}
Key *k = \hyperlink{group__key_gad23c65b44bf48d773759e1f9a4d43b89}{keyNew}(0);
\textcolor{comment}{// work with it}
\hyperlink{group__key_ga3df95bbc2494e3e6703ece5639be5bb1}{keyDel} (k);
\end{DoxyCode}


If you want the key object to contain a name, value, comment and other meta info read on.

\begin{DoxyNote}{Note}
When you already have a key with similar properties its easier and cheaper to \hyperlink{group__key_gae6ec6a60cc4b8c1463fa08623d056ce3}{key\-Dup()} the key.
\end{DoxyNote}
Due to A\-B\-I compatibility, the {\ttfamily Key} structure is not defined in kdb.\-h, only declared. So you can only declare {\ttfamily pointers} to {\ttfamily Keys} in your program, and allocate and free memory for them with \hyperlink{group__key_gad23c65b44bf48d773759e1f9a4d43b89}{key\-New()} and \hyperlink{group__key_ga3df95bbc2494e3e6703ece5639be5bb1}{key\-Del()} respectively. See \href{http://tldp.org/HOWTO/Program-Library-HOWTO/shared-libraries.html#AEN135}{\tt http\-://tldp.\-org/\-H\-O\-W\-T\-O/\-Program-\/\-Library-\/\-H\-O\-W\-T\-O/shared-\/libraries.\-html\#\-A\-E\-N135}

You can call it in many different ways depending on the attribute tags you pass as parameters. Tags are represented as the \hyperlink{group__key_ga91fb3178848bd682000958089abbaf40}{keyswitch\-\_\-t} values, and tell \hyperlink{group__key_gad23c65b44bf48d773759e1f9a4d43b89}{key\-New()} which Key attribute comes next.

The simplest and minimum way to use it is with no tags, only a key name\-: 
\begin{DoxyCode}
Key *nullKey,*emptyNamedKey;

\textcolor{comment}{// Create a key that has no name, is completely empty, but is initialized}
nullKey=\hyperlink{group__key_gad23c65b44bf48d773759e1f9a4d43b89}{keyNew}(0);
\hyperlink{group__key_ga3df95bbc2494e3e6703ece5639be5bb1}{keyDel} (nullKey);

\textcolor{comment}{// Is the same as above}
nullKey=\hyperlink{group__key_gad23c65b44bf48d773759e1f9a4d43b89}{keyNew}(\textcolor{stringliteral}{""}, \hyperlink{group__key_gga91fb3178848bd682000958089abbaf40aa8adb6fcb92dec58fb19410eacfdd403}{KEY\_END});
\hyperlink{group__key_ga3df95bbc2494e3e6703ece5639be5bb1}{keyDel} (nullKey);

\textcolor{comment}{// Create and initialize a key with a name and nothing else}
emptyNamedKey=\hyperlink{group__key_gad23c65b44bf48d773759e1f9a4d43b89}{keyNew}(\textcolor{stringliteral}{"user/some/example"},\hyperlink{group__key_gga91fb3178848bd682000958089abbaf40aa8adb6fcb92dec58fb19410eacfdd403}{KEY\_END});
\hyperlink{group__key_ga3df95bbc2494e3e6703ece5639be5bb1}{keyDel} (emptyNamedKey);
\end{DoxyCode}


\hyperlink{group__key_gad23c65b44bf48d773759e1f9a4d43b89}{key\-New()} allocates memory for a key object and cleans everything up. After that, it processes the given argument list.

The Key attribute tags are the following\-:
\begin{DoxyItemize}
\item keyswitch\-\_\-t\-::\-K\-E\-Y\-\_\-\-T\-Y\-P\-E \par
 Next parameter is a type of the value. Default assumed is K\-E\-Y\-\_\-\-T\-Y\-P\-E\-\_\-\-U\-N\-D\-E\-F\-I\-N\-E\-D. Set this attribute so that a subsequent K\-E\-Y\-\_\-\-V\-A\-L\-U\-E can toggle to \hyperlink{group__keyvalue_ga622bde1eb0e0c4994728331326340ef2}{key\-Set\-String()} or \hyperlink{group__keyvalue_gaa50a5358fd328d373a45f395fa1b99e7}{key\-Set\-Binary()} regarding to \hyperlink{group__keytest_gaea7670778abd07fee0fe8ac12a149190}{key\-Is\-String()} or \hyperlink{group__keytest_ga9526b371087564e43e3dff8ad0dac949}{key\-Is\-Binary()}. If you don't use K\-E\-Y\-\_\-\-T\-Y\-P\-E but a K\-E\-Y\-\_\-\-V\-A\-L\-U\-E follows afterwards, K\-E\-Y\-\_\-\-T\-Y\-P\-E\-\_\-\-S\-T\-R\-I\-N\-G will be used.
\item keyswitch\-\_\-t\-::\-K\-E\-Y\-\_\-\-S\-I\-Z\-E \par
 Define a maximum length of the value. This is especially useful for setting a binary key. So make sure you use that before you K\-E\-Y\-\_\-\-V\-A\-L\-U\-E for binary keys.
\item keyswitch\-\_\-t\-::\-K\-E\-Y\-\_\-\-V\-A\-L\-U\-E \par
 Next parameter is a pointer to the value that will be set to the key If no keyswitch\-\_\-t\-::\-K\-E\-Y\-\_\-\-T\-Y\-P\-E was used before, keyswitch\-\_\-t\-::\-K\-E\-Y\-\_\-\-T\-Y\-P\-E\-\_\-\-S\-T\-R\-I\-N\-G is assumed. If K\-E\-Y\-\_\-\-T\-Y\-P\-E was previously passed with a K\-E\-Y\-\_\-\-T\-Y\-P\-E\-\_\-\-B\-I\-N\-A\-R\-Y, you should have passed K\-E\-Y\-\_\-\-S\-I\-Z\-E before! Otherwise it will be cut of with first \textbackslash{}0 in string!
\item keyswitch\-\_\-t\-::\-K\-E\-Y\-\_\-\-U\-I\-D, {\ttfamily keyswitch\-\_\-t\-::\-K\-E\-Y\-\_\-\-G\-I\-D} \par
 Next parameter is taken as the U\-I\-D (uid\-\_\-t) or G\-I\-D (gid\-\_\-t) that will be defined on the key. See \hyperlink{group__keymeta_gab5f284f5ecd261e0a290095f50ba1af7}{key\-Set\-U\-I\-D()} and \hyperlink{group__keymeta_ga9e3d0fb3f7ba906e067727b9155d22e3}{key\-Set\-G\-I\-D()}.
\item keyswitch\-\_\-t\-::\-K\-E\-Y\-\_\-\-M\-O\-D\-E \par
 Next parameter is taken as mode permissions (int) to the key. See \hyperlink{group__keymeta_ga8803037e35b9da1ce492323a88ff6bc3}{key\-Set\-Mode()}.
\item keyswitch\-\_\-t\-::\-K\-E\-Y\-\_\-\-D\-I\-R \par
 Define that the key is a directory rather than a ordinary key. This means its executable bits in its mode are set. This option allows the key to have subkeys. See \hyperlink{group__keymeta_gaae575bd86a628a15ee45baa860522e75}{key\-Set\-Dir()}.
\item keyswitch\-\_\-t\-::\-K\-E\-Y\-\_\-\-O\-W\-N\-E\-R \par
 Next parameter is the owner. See \hyperlink{group__keyname_ga88d6ec200ba0707b7c1b4a88133d2be4}{key\-Set\-Owner()}.
\item keyswitch\-\_\-t\-::\-K\-E\-Y\-\_\-\-C\-O\-M\-M\-E\-N\-T \par
 Next parameter is a comment. See \hyperlink{group__keyvalue_ga8863a877a84fa46e6017fe72e49b89c1}{key\-Set\-Comment()}.
\item keyswitch\-\_\-t\-::\-K\-E\-Y\-\_\-\-E\-N\-D \par
 Must be the last parameter passed to \hyperlink{group__key_gad23c65b44bf48d773759e1f9a4d43b89}{key\-New()}. It is always required, unless the {\ttfamily key\-Name} is 0.
\end{DoxyItemize}

\begin{DoxyParagraph}{Example\-:}

\begin{DoxyCode}
KeySet *ks=\hyperlink{group__keyset_ga671e1aaee3ae9dc13b4834a4ddbd2c3c}{ksNew}(0, KS\_END);

\hyperlink{group__keyset_gaa5a1d467a4d71041edce68ea7748ce45}{ksAppendKey}(ks,\hyperlink{group__key_gad23c65b44bf48d773759e1f9a4d43b89}{keyNew}(0));       \textcolor{comment}{// an empty key}

\hyperlink{group__keyset_gaa5a1d467a4d71041edce68ea7748ce45}{ksAppendKey}(ks,\hyperlink{group__key_gad23c65b44bf48d773759e1f9a4d43b89}{keyNew}(\textcolor{stringliteral}{"user/sw"},              \textcolor{comment}{// the name of
       the key}
        \hyperlink{group__key_gga91fb3178848bd682000958089abbaf40aa8adb6fcb92dec58fb19410eacfdd403}{KEY\_END}));                      \textcolor{comment}{// no more args}

\hyperlink{group__keyset_gaa5a1d467a4d71041edce68ea7748ce45}{ksAppendKey}(ks,\hyperlink{group__key_gad23c65b44bf48d773759e1f9a4d43b89}{keyNew}(\textcolor{stringliteral}{"user/tmp/ex1"},
        \hyperlink{group__key_gga91fb3178848bd682000958089abbaf40ac66e4a49d09212b79f5754ca6db5bd2e}{KEY\_VALUE},\textcolor{stringliteral}{"some data"},          \textcolor{comment}{// set a string value}
        \hyperlink{group__key_gga91fb3178848bd682000958089abbaf40aa8adb6fcb92dec58fb19410eacfdd403}{KEY\_END}));                      \textcolor{comment}{// end of args}

\hyperlink{group__keyset_gaa5a1d467a4d71041edce68ea7748ce45}{ksAppendKey}(ks,\hyperlink{group__key_gad23c65b44bf48d773759e1f9a4d43b89}{keyNew}(\textcolor{stringliteral}{"user/tmp/ex2"},
        \hyperlink{group__key_gga91fb3178848bd682000958089abbaf40ac66e4a49d09212b79f5754ca6db5bd2e}{KEY\_VALUE},\textcolor{stringliteral}{"some data"},          \textcolor{comment}{// with a simple value}
        \hyperlink{group__key_gga91fb3178848bd682000958089abbaf40a1b0a91ff3a855d6993930ebf0abaa518}{KEY\_MODE},0777,                  \textcolor{comment}{// permissions}
        \hyperlink{group__key_gga91fb3178848bd682000958089abbaf40aa8adb6fcb92dec58fb19410eacfdd403}{KEY\_END}));                      \textcolor{comment}{// end of args}

\hyperlink{group__keyset_gaa5a1d467a4d71041edce68ea7748ce45}{ksAppendKey}(ks,\hyperlink{group__key_gad23c65b44bf48d773759e1f9a4d43b89}{keyNew}(\textcolor{stringliteral}{"user/tmp/ex4"},
        KEY\_TYPE,KEY\_TYPE\_BINARY,       \textcolor{comment}{// key type}
        \hyperlink{group__key_gga91fb3178848bd682000958089abbaf40a6d531b5c41445d19d0452eebdccbfa01}{KEY\_SIZE},7,                     \textcolor{comment}{// assume binary length 7}
        \hyperlink{group__key_gga91fb3178848bd682000958089abbaf40ac66e4a49d09212b79f5754ca6db5bd2e}{KEY\_VALUE},\textcolor{stringliteral}{"some data"},          \textcolor{comment}{// value that will be
       truncated in 7 bytes}
        \hyperlink{group__key_gga91fb3178848bd682000958089abbaf40ac29427bb47cc31689d02912e36161ee3}{KEY\_COMMENT},\textcolor{stringliteral}{"value is truncated"},
        \hyperlink{group__key_gga91fb3178848bd682000958089abbaf40a77ca60362fa8daca8d5347db4385068b}{KEY\_OWNER},\textcolor{stringliteral}{"root"},               \textcolor{comment}{// owner (not uid) is root}
        \hyperlink{group__key_gga91fb3178848bd682000958089abbaf40a28f01a87d65f065172f734c9c9446c0e}{KEY\_UID},0,                      \textcolor{comment}{// root uid}
        \hyperlink{group__key_gga91fb3178848bd682000958089abbaf40aa8adb6fcb92dec58fb19410eacfdd403}{KEY\_END}));                      \textcolor{comment}{// end of args}

\hyperlink{group__keyset_gaa5a1d467a4d71041edce68ea7748ce45}{ksAppendKey}(ks,\hyperlink{group__key_gad23c65b44bf48d773759e1f9a4d43b89}{keyNew}(\textcolor{stringliteral}{"user/tmp/ex5"},
        KEY\_TYPE,
                KEY\_TYPE\_DIR | KEY\_TYPE\_BINARY,\textcolor{comment}{// dir key with a binary value}
        \hyperlink{group__key_gga91fb3178848bd682000958089abbaf40a6d531b5c41445d19d0452eebdccbfa01}{KEY\_SIZE},7,
        \hyperlink{group__key_gga91fb3178848bd682000958089abbaf40ac66e4a49d09212b79f5754ca6db5bd2e}{KEY\_VALUE},\textcolor{stringliteral}{"some data"},          \textcolor{comment}{// value that will be
       truncated in 7 bytes}
        \hyperlink{group__key_gga91fb3178848bd682000958089abbaf40ac29427bb47cc31689d02912e36161ee3}{KEY\_COMMENT},\textcolor{stringliteral}{"value is truncated"},
        \hyperlink{group__key_gga91fb3178848bd682000958089abbaf40a77ca60362fa8daca8d5347db4385068b}{KEY\_OWNER},\textcolor{stringliteral}{"root"},               \textcolor{comment}{// owner (not uid) is root}
        \hyperlink{group__key_gga91fb3178848bd682000958089abbaf40a28f01a87d65f065172f734c9c9446c0e}{KEY\_UID},0,                      \textcolor{comment}{// root uid}
        \hyperlink{group__key_gga91fb3178848bd682000958089abbaf40aa8adb6fcb92dec58fb19410eacfdd403}{KEY\_END}));                      \textcolor{comment}{// end of args}

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

\end{DoxyParagraph}
The reference counter (see \hyperlink{group__key_ga4aabc4272506dd63161db2bbb42de8ae}{key\-Get\-Ref()}) will be initialized with 0, that means a subsequent call of \hyperlink{group__key_ga3df95bbc2494e3e6703ece5639be5bb1}{key\-Del()} will delete the key. If you append the key to a keyset the reference counter will be incremented by one (see key\-Inc()) and the key can't be be deleted by a \hyperlink{group__key_ga3df95bbc2494e3e6703ece5639be5bb1}{key\-Del()}.


\begin{DoxyCode}
Key *k = \hyperlink{group__key_gad23c65b44bf48d773759e1f9a4d43b89}{keyNew}(0); \textcolor{comment}{// ref counter 0}
\hyperlink{group__keyset_gaa5a1d467a4d71041edce68ea7748ce45}{ksAppendKey}(ks, k); \textcolor{comment}{// ref counter of key 1}
\hyperlink{group__keyset_ga27e5c16473b02a422238c8d970db7ac8}{ksDel}(ks); \textcolor{comment}{// key will be deleted with keyset}
 *
\end{DoxyCode}


If you increment only by one with key\-Inc() the same as said above is valid\-:


\begin{DoxyCode}
Key *k = \hyperlink{group__key_gad23c65b44bf48d773759e1f9a4d43b89}{keyNew}(0); \textcolor{comment}{// ref counter 0}
\hyperlink{group__key_ga6970a6f254d67af7e39f8e469bb162f1}{keyIncRef}(k); \textcolor{comment}{// ref counter of key 1}
\hyperlink{group__key_ga3df95bbc2494e3e6703ece5639be5bb1}{keyDel}(k);    \textcolor{comment}{// has no effect}
\hyperlink{group__key_ga2c6433ca22109e4e141946057eccb283}{keyDecRef}(k); \textcolor{comment}{// ref counter back to 0}
\hyperlink{group__key_ga3df95bbc2494e3e6703ece5639be5bb1}{keyDel}(k);    \textcolor{comment}{// key is now deleted}
 *
\end{DoxyCode}


If you add the key to more key\-Sets\-:


\begin{DoxyCode}
Key *k = \hyperlink{group__key_gad23c65b44bf48d773759e1f9a4d43b89}{keyNew}(0); \textcolor{comment}{// ref counter 0}
\hyperlink{group__keyset_gaa5a1d467a4d71041edce68ea7748ce45}{ksAppendKey}(ks1, k); \textcolor{comment}{// ref counter of key 1}
\hyperlink{group__keyset_gaa5a1d467a4d71041edce68ea7748ce45}{ksAppendKey}(ks2, k); \textcolor{comment}{// ref counter of key 2}
\hyperlink{group__keyset_ga27e5c16473b02a422238c8d970db7ac8}{ksDel}(ks1); \textcolor{comment}{// ref counter of key 1}
\hyperlink{group__keyset_ga27e5c16473b02a422238c8d970db7ac8}{ksDel}(ks2); \textcolor{comment}{// k is now deleted}
 *
\end{DoxyCode}


or use key\-Inc() more than once\-:


\begin{DoxyCode}
Key *k = \hyperlink{group__key_gad23c65b44bf48d773759e1f9a4d43b89}{keyNew}(0); \textcolor{comment}{// ref counter 0}
\hyperlink{group__key_ga6970a6f254d67af7e39f8e469bb162f1}{keyIncRef}(k); \textcolor{comment}{// ref counter of key 1}
\hyperlink{group__key_ga3df95bbc2494e3e6703ece5639be5bb1}{keyDel} (k);   \textcolor{comment}{// has no effect}
\hyperlink{group__key_ga6970a6f254d67af7e39f8e469bb162f1}{keyIncRef}(k); \textcolor{comment}{// ref counter of key 2}
\hyperlink{group__key_ga3df95bbc2494e3e6703ece5639be5bb1}{keyDel} (k);   \textcolor{comment}{// has no effect}
\hyperlink{group__key_ga2c6433ca22109e4e141946057eccb283}{keyDecRef}(k); \textcolor{comment}{// ref counter of key 1}
\hyperlink{group__key_ga3df95bbc2494e3e6703ece5639be5bb1}{keyDel} (k);   \textcolor{comment}{// has no effect}
\hyperlink{group__key_ga2c6433ca22109e4e141946057eccb283}{keyDecRef}(k); \textcolor{comment}{// ref counter is now 0}
\hyperlink{group__key_ga3df95bbc2494e3e6703ece5639be5bb1}{keyDel} (k); \textcolor{comment}{// k is now deleted}
 *
\end{DoxyCode}


they key won't be deleted by a \hyperlink{group__key_ga3df95bbc2494e3e6703ece5639be5bb1}{key\-Del()} as long refcounter is not 0.

The key's sync bit will always be set for any call, except\-: 
\begin{DoxyCode}
Key *k = \hyperlink{group__key_gad23c65b44bf48d773759e1f9a4d43b89}{keyNew}(0);
\textcolor{comment}{// keyNeedSync() will be false}
\end{DoxyCode}



\begin{DoxyParams}{Parameters}
{\em name} & a valid name to the key, or N\-U\-L\-L to get a simple initialized, but really empty, object \\
\hline
\end{DoxyParams}
\begin{DoxySeeAlso}{See Also}
\hyperlink{group__key_ga3df95bbc2494e3e6703ece5639be5bb1}{key\-Del()} 
\end{DoxySeeAlso}
\begin{DoxyReturn}{Returns}
a pointer to a new allocated and initialized Key object. 
\end{DoxyReturn}

\begin{DoxyRetVals}{Return values}
{\em N\-U\-L\-L} & on malloc error or if an invalid {\ttfamily name} was passed (see \hyperlink{group__keyname_ga7699091610e7f3f43d2949514a4b35d9}{key\-Set\-Name()}). \\
\hline
\end{DoxyRetVals}
