/* XDS - OSSP Extensible Data Serialization Library Copyright (c) 2001 The OSSP Project (http://www.ossp.org/) Copyright (c) 2001 Cable & Wireless Deutschland (http://www.cw.com/de/) This file is part of OSSP XDS, an extensible data serialization library which can be found at http://www.ossp.com/pkg/xds/. Permission to use, copy, modify, and distribute this software for any purpose with or without fee is hereby granted, provided that the above copyright notice and this permission notice appear in all copies. THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS AND COPYRIGHT HOLDERS AND THEIR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #include #include "xds.h" int xml_encode_int32(xds_t* xds, void* engine_context, void* buffer, size_t buffer_size, size_t* used_buffer_size, va_list* args) { xds_int32_t value; char buf[32]; size_t i, j; char* p; int negative; xds_init_encoding_engine(7 + 8 + 11); /* Get the value and format it into our buffer. Keep track of the length of the formatted result. */ value = va_arg(*args, xds_int32_t); if (value < 0) { negative = XDS_TRUE; value = 0 - value; } else negative = XDS_FALSE; i = 0; do { unsigned char remainder = value % 10; value = value / 10; buf[i++] = '0' + remainder; } while (value != 0); if (negative) buf[i++] = '-'; /* Now that we know the correct size of our data's representation, write it into the buffer. */ *used_buffer_size = 7 + 8 + i; p = buffer; memmove(p, "", 7); p += 7; for (j = i; j > 0; ) { *p++ = buf[--j]; } memmove(p, "", 8); return XDS_OK; }