00001 /* 00002 00003 Copyright (C) 2000, 2001 Silicon Graphics, Inc. All Rights Reserved. 00004 00005 This program is free software; you can redistribute it and/or modify it 00006 under the terms of version 2.1 of the GNU Lesser General Public License 00007 as published by the Free Software Foundation. 00008 00009 This program is distributed in the hope that it would be useful, but 00010 WITHOUT ANY WARRANTY; without even the implied warranty of 00011 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 00012 00013 Further, this software is distributed without any warranty that it is 00014 free of the rightful claim of any third person regarding infringement 00015 or the like. Any license provided herein, whether implied or 00016 otherwise, applies only to this software file. Patent licenses, if 00017 any, provided herein do not apply to combinations of this program with 00018 other software, or any other product whatsoever. 00019 00020 You should have received a copy of the GNU Lesser General Public 00021 License along with this program; if not, write the Free Software 00022 Foundation, Inc., 59 Temple Place - Suite 330, Boston MA 02111-1307, 00023 USA. 00024 00025 Contact information: Silicon Graphics, Inc., 1600 Amphitheatre Pky, 00026 Mountain View, CA 94043, or: 00027 00028 http://www.sgi.com 00029 00030 For further information regarding this notice, see: 00031 00032 http://oss.sgi.com/projects/GenInfo/NoticeExplan 00033 00034 */ 00035 00036 00037 /* 00038 lebdecodeu32.c 00039 00040 $Revision: 1.1.1.1 $ 00041 $Date: 2005/10/21 19:00:00 $ 00042 */ 00043 00044 00045 #ifndef _LP64 00046 #include <sgidefs.h> 00047 #endif /* _LP64 */ 00048 #include <cmplrs/leb128.h> 00049 00050 /* 00051 This routine takes a pointer to an encoded unsigned leb128 00052 number, and returns the number of bytes in the encoding. 00053 In other words, it returns the length of the leb128 number. 00054 It also returns the number itself in *value. The details 00055 of the leb128 encoding are in the Dwarf document. 00056 */ 00057 int 00058 _leb128_unsigned_decode32(char *data, __uint32_t *value) 00059 { 00060 __uint32_t lvalue; 00061 unsigned char byte; 00062 00063 byte = *data; 00064 if ((byte & 0x80) == 0) { 00065 *value = byte; 00066 return 1; 00067 } 00068 else if ((*(data + 1) & 0x80) == 0) { 00069 lvalue = byte & 0x7f; 00070 lvalue |= (*(data + 1) & 0x7f) << 7; 00071 *value = lvalue; 00072 return 2; 00073 } 00074 else if ((*(data + 2) & 0x80) == 0) { 00075 lvalue = byte & 0x7f; 00076 lvalue |= (*(data + 1) & 0x7f) << 7; 00077 lvalue |= (*(data + 2) & 0x7f) << 14; 00078 00079 *value = lvalue; 00080 return 3; 00081 } 00082 else if ((*(data + 3) & 0x80) == 0) { 00083 lvalue = byte & 0x7f; 00084 lvalue |= (*(data + 1) & 0x7f) << 7; 00085 lvalue |= (*(data + 2) & 0x7f) << 14; 00086 lvalue |= (*(data + 3) & 0x7f) << 21; 00087 00088 *value = lvalue; 00089 return 4; 00090 } 00091 { 00092 lvalue = byte & 0x7f; 00093 lvalue |= (*(data + 1) & 0x7f) << 7; 00094 lvalue |= (*(data + 2) & 0x7f) << 14; 00095 lvalue |= (*(data + 3) & 0x7f) << 21; 00096 lvalue |= (*(data + 4) & 0x7f) << 28; 00097 00098 *value = lvalue; 00099 return 5; 00100 } 00101 } 00102
1.5.6