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 lebencodes32.c 00039 00040 $Revision: 1.1.1.1 $ 00041 $Date: 2005/10/21 19:00:00 $ 00042 */ 00043 00044 #ifndef _LP64 00045 #include <sgidefs.h> 00046 #endif /* _LP64 */ 00047 #include <cmplrs/leb128.h> 00048 00049 00050 /* 00051 This routine encodes the given signed number in leb128 mode, 00052 and stores the bytes at address buffer. It returns the number 00053 of bytes in the encoding. It is the user's responsibility to 00054 make sure there is enough storage at buffer. The details of 00055 leb128 encoding are in the Dwarf document. 00056 00057 This relies on right shifting of negative values preserving 00058 the sign. Implementation defined according to ISO C. 00059 00060 5 bytes in buffer are all that is needed. 00061 */ 00062 int 00063 _leb128_signed_encode32(__int32_t number, char *buffer) 00064 { 00065 int sign; 00066 char *bufPtr; 00067 char byte; 00068 00069 sign = (number < 0) ? -1 : 0; 00070 bufPtr = buffer; 00071 00072 for(;;) { 00073 byte = (number & 0x7f); 00074 number >>= 7; 00075 00076 if (number == sign && (byte & 0x40) == ((char)sign & 0x40)) { 00077 *bufPtr = byte; 00078 bufPtr++; 00079 return bufPtr - buffer; 00080 } 00081 byte |= 0x80; 00082 *bufPtr = byte; 00083 bufPtr++; 00084 } 00085 00086 }
1.5.6