xref: /PHP-8.1/ext/dba/libcdb/uint32.c (revision 01b3fc03)
1 /*
2    +----------------------------------------------------------------------+
3    | Copyright (c) The PHP Group                                          |
4    +----------------------------------------------------------------------+
5    | This source file is subject to version 3.01 of the PHP license,      |
6    | that is bundled with this package in the file LICENSE, and is        |
7    | available through the world-wide-web at the following url:           |
8    | https://www.php.net/license/3_01.txt                                 |
9    | If you did not receive a copy of the PHP license and are unable to   |
10    | obtain it through the world-wide-web, please send a note to          |
11    | license@php.net so we can mail you a copy immediately.               |
12    +----------------------------------------------------------------------+
13    | Author: Marcus Boerger <helly@php.net>                               |
14    +----------------------------------------------------------------------+
15  */
16 
17 /* incorporated from D.J.Bernstein's cdb-0.75 (http://cr.yp.to/cdb.html)*/
18 
19 #ifdef HAVE_CONFIG_H
20 #include "config.h"
21 #endif
22 
23 #include "php.h"
24 
25 #include "uint32.h"
26 
27 /* {{{ uint32_pack */
uint32_pack(char * out,uint32 in)28 void uint32_pack(char *out, uint32 in)
29 {
30 	out[0] = in&0xff; in>>=8;
31 	out[1] = in&0xff; in>>=8;
32 	out[2] = in&0xff; in>>=8;
33 	out[3] = in&0xff;
34 }
35 /* }}} */
36 
37 /* {{{ uint32_unpack */
uint32_unpack(const char * in,uint32 * out)38 void uint32_unpack(const char *in, uint32 *out)
39 {
40 	*out = (((uint32)(unsigned char)in[3])<<24) |
41 	       (((uint32)(unsigned char)in[2])<<16) |
42 	       (((uint32)(unsigned char)in[1])<<8) |
43 	       (((uint32)(unsigned char)in[0]));
44 }
45 /* }}} */
46