1 /*
2  * %CopyrightBegin%
3  *
4  * Copyright Ericsson AB 1998-2017. All Rights Reserved.
5  *
6  * Licensed under the Apache License, Version 2.0 (the "License");
7  * you may not use this file except in compliance with the License.
8  * You may obtain a copy of the License at
9  *
10  *     http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17  *
18  * %CopyrightEnd%
19  */
20 #include <string.h>
21 #include "eidef.h"
22 #include "eiext.h"
23 #include "putget.h"
24 
ei_encode_boolean(char * buf,int * index,int p)25 int ei_encode_boolean(char *buf, int *index, int p)
26 {
27   char *s = buf + *index;
28   char *s0 = s;
29   char *val;
30   int len;
31 
32   val = p ? "true" : "false";
33   len = strlen(val);
34 
35   if (!buf) s += 2;
36   else {
37       put8(s, ERL_SMALL_ATOM_UTF8_EXT);
38       put8(s, len);
39 
40       memcpy(s,val,len); /* unterminated string */
41   }
42   s += len;
43 
44   *index += s-s0;
45 
46   return 0;
47 }
48 
49