]>
git.saurik.com Git - redis.git/blob - src/endianconv.c
   1 /* endinconv.c -- Endian conversions utilities. 
   3  * This functions are never called directly, but always using the macros 
   4  * defined into endianconv.h, this way we define everything is a non-operation 
   5  * if the arch is already little endian. 
   7  * Redis tries to encode everything as little endian (but a few things that need 
   8  * to be backward compatible are still in big endian) because most of the 
   9  * production environments are little endian, and we have a lot of conversions 
  10  * in a few places because ziplists, intsets, zipmaps, need to be endian-neutral 
  11  * even in memory, since they are serialied on RDB files directly with a single 
  12  * write(2) without other additional steps. 
  14  * ---------------------------------------------------------------------------- 
  16  * Copyright (c) 2011-2012, Salvatore Sanfilippo <antirez at gmail dot com> 
  17  * All rights reserved. 
  19  * Redistribution and use in source and binary forms, with or without 
  20  * modification, are permitted provided that the following conditions are met: 
  22  *   * Redistributions of source code must retain the above copyright notice, 
  23  *     this list of conditions and the following disclaimer. 
  24  *   * Redistributions in binary form must reproduce the above copyright 
  25  *     notice, this list of conditions and the following disclaimer in the 
  26  *     documentation and/or other materials provided with the distribution. 
  27  *   * Neither the name of Redis nor the names of its contributors may be used 
  28  *     to endorse or promote products derived from this software without 
  29  *     specific prior written permission. 
  31  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 
  32  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 
  33  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 
  34  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 
  35  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 
  36  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 
  37  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 
  38  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 
  39  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 
  40  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 
  41  * POSSIBILITY OF SUCH DAMAGE. 
  47 /* Toggle the 16 bit unsigned integer pointed by *p from little endian to 
  49 void memrev16(void *p
) { 
  50     unsigned char *x 
= p
, t
; 
  57 /* Toggle the 32 bit unsigned integer pointed by *p from little endian to 
  59 void memrev32(void *p
) { 
  60     unsigned char *x 
= p
, t
; 
  70 /* Toggle the 64 bit unsigned integer pointed by *p from little endian to 
  72 void memrev64(void *p
) { 
  73     unsigned char *x 
= p
, t
; 
  89 uint16_t intrev16(uint16_t v
) { 
  94 uint32_t intrev32(uint32_t v
) { 
  99 uint64_t intrev64(uint64_t v
) { 
 110     sprintf(buf
,"ciaoroma"); 
 114     sprintf(buf
,"ciaoroma"); 
 118     sprintf(buf
,"ciaoroma");