isc_portable_integer()

From InterBase

Go Up to API Function Reference


Reverses the byte order of an integer. This supports INT64 (8 byte integer) values and is a superset of isc_vax_integer(), which supports only up to LONG (4 bytes) values.

Syntax

 ISC_INT64 isc_portable_integer(
 char *buffer, 
 short length);
Parameter Type Description

buffer

char *

Pointer to the integer to convert

length

short

Length, in bytes, of the integer to convert

Valid lengths are 1, 2, 4, and 8 bytes.

Description

isc_portable_integer() reverses the byte order of an integer, specified in buffer, and returns the newly ordered value.

A typical use for this function is to convert integer values passed into a database parameter buffer to a format where the least significant byte must be first and the most significant byte last. In InterBase, integer values must be represented in input parameter buffers (for example, the DPB) and are returned in result buffers in a generic format where the least significant byte is first, and the most significant byte last. isc_portable_integer() is used to convert integers to and from this format.

Example

The following code fragment converts a 2-byte value, stored in a character buffer that is the result buffer returned by a function such as isc_database_info():

#include <ibase.h>
char *p;
. . .
for(p = res_buffer; *p != isc_info_end;) {
/* Read item type of next cluster in the result buffer. */
item = *p++;
/* Read length of next value in result buffer, and convert. */
len = isc_portable_integer(p, 2);
p += len;
/* Now process the actual value, len bytes in size. */
}

Return value

isc_portable_integer() always returns a byte-reversed INT64 (8 byte) value.

See Also

Advance To: