Back to home page

Redis cross reference

 
 

    


0001 /* See endianconv.c top comments for more information
0002  *
0003  * ----------------------------------------------------------------------------
0004  *
0005  * Copyright (c) 2011-2012, Salvatore Sanfilippo <antirez at gmail dot com>
0006  * All rights reserved.
0007  *
0008  * Redistribution and use in source and binary forms, with or without
0009  * modification, are permitted provided that the following conditions are met:
0010  *
0011  *   * Redistributions of source code must retain the above copyright notice,
0012  *     this list of conditions and the following disclaimer.
0013  *   * Redistributions in binary form must reproduce the above copyright
0014  *     notice, this list of conditions and the following disclaimer in the
0015  *     documentation and/or other materials provided with the distribution.
0016  *   * Neither the name of Redis nor the names of its contributors may be used
0017  *     to endorse or promote products derived from this software without
0018  *     specific prior written permission.
0019  *
0020  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
0021  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
0022  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
0023  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
0024  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
0025  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
0026  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
0027  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
0028  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
0029  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
0030  * POSSIBILITY OF SUCH DAMAGE.
0031  */ 
0032 
0033 #ifndef __ENDIANCONV_H
0034 #define __ENDIANCONV_H
0035 
0036 #include "config.h"
0037 #include <stdint.h>
0038 
0039 void memrev16(void *p);
0040 void memrev32(void *p);
0041 void memrev64(void *p);
0042 uint16_t intrev16(uint16_t v);
0043 uint32_t intrev32(uint32_t v);
0044 uint64_t intrev64(uint64_t v);
0045 
0046 /* variants of the function doing the actual convertion only if the target
0047  * host is big endian */
0048 #if (BYTE_ORDER == LITTLE_ENDIAN)
0049 #define memrev16ifbe(p)
0050 #define memrev32ifbe(p)
0051 #define memrev64ifbe(p)
0052 #define intrev16ifbe(v) (v)
0053 #define intrev32ifbe(v) (v)
0054 #define intrev64ifbe(v) (v)
0055 #else
0056 #define memrev16ifbe(p) memrev16(p)
0057 #define memrev32ifbe(p) memrev32(p)
0058 #define memrev64ifbe(p) memrev64(p)
0059 #define intrev16ifbe(v) intrev16(v)
0060 #define intrev32ifbe(v) intrev32(v)
0061 #define intrev64ifbe(v) intrev64(v)
0062 #endif
0063 
0064 #endif