int __glXPointParameterfvReqSize( const GLbyte * pc, Bool swap ) { GLenum pname = * (GLenum *)(pc + 0); GLsizei compsize; if (swap) { pname = bswap_32(pname); } compsize = __glPointParameterfv_size(pname); return __GLX_PAD((compsize * 4)); }
int __glXConvolutionParameterfvReqSize( const GLbyte * pc, Bool swap, int reqlen ) { GLenum pname = * (GLenum *)(pc + 4); GLsizei compsize; if (swap) { pname = bswap_32(pname); } compsize = __glConvolutionParameterfv_size(pname); return safe_pad(safe_mul(compsize , 4)); }
int __glXTexGenfvReqSize( const GLbyte * pc, Bool swap ) { GLenum pname = * (GLenum *)(pc + 4); GLsizei compsize; if (swap) { pname = bswap_32(pname); } compsize = __glTexGenfv_size(pname); return __GLX_PAD((compsize * 4)); }
int __glXFogfvReqSize( const GLbyte * pc, Bool swap, int reqlen ) { GLenum pname = * (GLenum *)(pc + 0); GLsizei compsize; if (swap) { pname = bswap_32(pname); } compsize = __glFogfv_size(pname); return safe_pad(safe_mul(compsize , 4)); }
int mp_get_chroma_shift(int format, int *x_shift, int *y_shift, int *component_bits) { int xs = 0, ys = 0; int bpp; int err = 0; int bits = 8; if ((format & 0xff0000f0) == 0x34000050) format = bswap_32(format); if ((format & 0xf00000ff) == 0x50000034) { switch (format >> 24) { case 0x50: break; case 0x51: bits = 16; break; case 0x52: bits = 10; break; case 0x53: bits = 9; break; default: err = 1; break; } switch (format & 0x00ffffff) { case 0x00343434: // 444 xs = 0; ys = 0; break; case 0x00323234: // 422 xs = 1; ys = 0; break; case 0x00303234: // 420 xs = 1; ys = 1; break; case 0x00313134: // 411 xs = 2; ys = 0; break; case 0x00303434: // 440 xs = 0; ys = 1; break; default: err = 1; break; } } else switch (format) {
void _gnutls_write_uint24 (uint32_t num, opaque * data) { uint24 tmp; #ifndef WORDS_BIGENDIAN num = bswap_32 (num); #endif tmp = _gnutls_uint32touint24 (num); data[0] = tmp.pint[0]; data[1] = tmp.pint[1]; data[2] = tmp.pint[2]; }
Bool16 QTAtom::ReadInt32To64Signed(UInt64 Offset, SInt64 * Datum) { // General vars UInt32 tempDatum; // // Read and flip. if( !ReadBytes(Offset, (char *)&tempDatum, 4) ) return false; tempDatum = bswap_32(tempDatum); *Datum = (SInt64) (SInt32) tempDatum; return true; }
/** * Copy a memory block with simultaneous exchanging byte order. * The byte order is changed from little-endian 32-bit integers * to big-endian (or vice-versa). * * @param to the pointer where to copy memory block * @param index the index to start writing from * @param from the source block to copy * @param length length of the memory block */ void rhash_swap_copy_str_to_u32(void* to, int index, const void* from, size_t length) { /* if all pointers and length are 32-bits aligned */ if ( 0 == (( (int)((char*)to - (char*)0) | ((char*)from - (char*)0) | index | length ) & 3) ) { /* copy memory as 32-bit words */ const uint32_t* src = (const uint32_t*)from; const uint32_t* end = (const uint32_t*)((const char*)src + length); uint32_t* dst = (uint32_t*)((char*)to + index); while (src < end) *(dst++) = bswap_32( *(src++) ); } else { const char* src = (const char*)from; for (length += index; (size_t)index < length; index++) ((char*)to)[index ^ 3] = *(src++); } }
int __glXBitmapReqSize( const GLbyte * pc, Bool swap ) { GLint row_length = * (GLint *)(pc + 4); GLint image_height = 0; GLint skip_images = 0; GLint skip_rows = * (GLint *)(pc + 8); GLint alignment = * (GLint *)(pc + 16); GLsizei width = *(GLsizei *)(pc + 20); GLsizei height = *(GLsizei *)(pc + 24); if (swap) { row_length = bswap_32(row_length); skip_rows = bswap_32(skip_rows); alignment = bswap_32(alignment); width = bswap_32(width); height = bswap_32(height); } return __glXImageSize(GL_COLOR_INDEX, GL_BITMAP, 0, width, height, 1, image_height, row_length, skip_images, skip_rows, alignment); }
void ocfs2_swap_group_desc(struct ocfs2_group_desc *gd) { if (cpu_is_little_endian) return; gd->bg_size = bswap_16(gd->bg_size); gd->bg_bits = bswap_16(gd->bg_bits); gd->bg_free_bits_count = bswap_16(gd->bg_free_bits_count); gd->bg_chain = bswap_16(gd->bg_chain); gd->bg_generation = bswap_32(gd->bg_generation); gd->bg_next_group = bswap_64(gd->bg_next_group); gd->bg_parent_dinode = bswap_64(gd->bg_parent_dinode); gd->bg_blkno = bswap_64(gd->bg_blkno); }
Bool16 QTAtom::ReadInt32(UInt64 Offset, UInt32 * Datum) { // General vars UInt32 tempDatum; // // Read and flip. if( !ReadBytes(Offset, (char *)&tempDatum, 4) ) return false; *Datum = bswap_32(tempDatum); return true; }
int fulltest(const unsigned char *hash, const unsigned char *target) { uint32_t *hash32 = (uint32_t *)hash; uint32_t *target32 = (uint32_t *)target; int rc = 1; int i; for (i = 28 / 4; i >= 0; i--) { uint32_t h32tmp = bswap_32(hash32[i]); uint32_t t32tmp = bswap_32(target32[i]); if (h32tmp > t32tmp) { rc = NONCE_VALID; break; } if (h32tmp < t32tmp) { rc = NONCE_DIFF; break; } } return rc; }
Bool16 QTAtom::ReadSubAtomInt32(const char * AtomPath, UInt32 * Datum) { // General vars UInt32 tempDatum; // // Read and flip. if( !ReadSubAtomBytes(AtomPath, (char *)&tempDatum, 4) ) return false; *Datum = bswap_32(tempDatum); return true; }
char* errormsg(int* sbufLen,uint32_t transaction_id,char* error_msg) { int32_t action; int msgLen; action=3; msgLen = strlen(error_msg); *sbufLen = msgLen+8; char* sbuffer = malloc(*sbufLen); /* convert them to network order */ #ifdef LITTLE_ENDIAN action = bswap_32(action); transaction_id = bswap_32(transaction_id); #endif memcpy(sbuffer,&action,4); memcpy(sbuffer+4,&transaction_id,4); memcpy(sbuffer+8,&error_msg,msgLen); LOGMSG(LOG_INFO,"ERRORTransaction ID: %u Text: %s",transaction_id,error_msg); return sbuffer; }
Word LD_FILE_GETWORD() { Word tmp; if(sizeof(tmp)!=read(fd,&tmp,sizeof(tmp))) EM_THROW(LD_FILE_ReadError); #if BYTE_ORDER == LITTLE_ENDIAN # if __WORDSIZE == 32 return (Word)bswap_32((unsigned int)tmp); # elif __WORDSIZE == 64 return bswap_64(tmp); # endif #elif BYTE_ORDER == BIG_ENDIAN return tmp; #endif }
/* de-serialize channels data from the parcel. return number of sources */ static int ParcelDtor(struct Manifest *manifest, char *parcel) { struct NSParcel *p = (void*)parcel; int64_t end = bswap_32(p->bind_number) + bswap_32(p->connect_number); int64_t m = 0, n = 0; int64_t i; /* update channels sources from the parcel */ for(i = 0; i < end; ++i) { struct Connection *c; NEXT_SRC(); /* skip "binds" */ if(i < bswap_32(p->bind_number)) continue; /* ip is already in network format for inet_ntoa */ c->host = p->records[i].host; c->port = bswap_16(p->records[i].port); } g_free(parcel); return end; }
void DeepStarComponent::byteSwap( starData *stardata ) { stardata->RA = bswap_32( stardata->RA ); stardata->Dec = bswap_32( stardata->Dec ); stardata->dRA = bswap_32( stardata->dRA ); stardata->dDec = bswap_32( stardata->dDec ); stardata->parallax = bswap_32( stardata->parallax ); stardata->HD = bswap_32( stardata->HD ); stardata->mag = bswap_16( stardata->mag ); stardata->bv_index = bswap_16( stardata->bv_index ); }
static int decode(const void *ptr) { #if defined(sun) && defined(__SVR4) if (sizeof(int) == 4) { #if defined(_BIG_ENDIAN) return *(const int *)ptr; #else return BSWAP_32(*(const int *)ptr); #endif #else if ((BYTE_ORDER == BIG_ENDIAN) && sizeof(int) == 4) { return *(const int *)ptr; } else if (BYTE_ORDER == LITTLE_ENDIAN && sizeof(int) == 4) { return (int)bswap_32(*(const unsigned int *)ptr); #endif } else { const unsigned char *p = ptr; int result = *p & (1 << (CHAR_BIT - 1)) ? ~0 : 0; /* cppcheck-suppress shiftNegative */ result = (result << 8) | *p++; result = (result << 8) | *p++; result = (result << 8) | *p++; result = (result << 8) | *p++; return result; } } static char *zname_from_stridx(char *str, size_t idx) { size_t i; size_t size; char *ret; i = idx; while (str[i] != '\0') { i++; } size = i - idx; str += idx; ret = (char *)malloc(size + 1); ret = strncpy(ret, str, size); ret[size] = '\0'; return ret; }
void FirewirePort::StopCycleStartPacket(void) { // IMPORTANT: Disable Cycle Start Packet, no isochronous int rc = 0; // return code quadlet_t data_stop_cmc = bswap_32(0x100); rc = raw1394_write(handle, raw1394_get_local_id(handle), CSR_REGISTER_BASE + CSR_STATE_CLEAR, 4, &data_stop_cmc); if (rc) { outStr << "*****Error: can NOT disable cycle start packet" << std::endl; } else { outStr << "FirewirePort: successfully disabled cycle start packet" << std::endl; } }
/* data should be at least 3 bytes */ uint32_t _gnutls_read_uint24 (const opaque * data) { uint32_t res; uint24 num; num.pint[0] = data[0]; num.pint[1] = data[1]; num.pint[2] = data[2]; res = _gnutls_uint24touint32 (num); #ifndef WORDS_BIGENDIAN res = bswap_32 (res); #endif return res; }
/** * Copy a memory block with simultanious exchanging byte order. * The byte order is changed from little-endian 32-bit integers * to big-endian (or vice-versa). * * @param to the pointer where to copy memory block * @param from the source block to copy * @param length length of the memory block */ void u32_swap_copy(void* to, const void* from, size_t length) { // if all pointers and length are 32-bits aligned if( 0 == (( (int)((char*)to - (char*)0) | ((char*)from - (char*)0) | length ) & 3) ) { /* copy memory as dwords */ const unsigned* src = (const unsigned*)from; const unsigned* end = (const unsigned*)((const char*)src + length); unsigned* dst = (unsigned*)to; while(src<end) *(dst++) = bswap_32( *(src++) ); } else { int index = (int)((char*)to - (char*)0) & 3; const char* src = (const char*)from; const char* end = src + length; char* dst = (char*)to - index; for(; src<end; index++) dst[index^3] = *src++; } }
int get_local_address(int skt, int *port) { #if !defined(sparc) && !defined(SGI) && !defined(WIN32) unsigned #endif int nAddrSize = sizeof(struct sockaddr_in); struct sockaddr_in remAddr; int status; remAddr.sin_addr.s_addr = INADDR_ANY; status = getsockname(skt, (struct sockaddr*)&remAddr, &nAddrSize); if (status >= 0) { if (port) *port = bswap_16(remAddr.sin_port); return bswap_32(remAddr.sin_addr.s_addr); } return -1; }
LOCAL int stream_head_read(unsigned char *hbuf,uint32_t *newhead){ if(mp3_read(hbuf,4) != 4) return FALSE; #ifdef ARCH_X86 *newhead = bswap_32(*((uint32_t*)hbuf)); #else /* * we may not be able to address unaligned 32-bit data on non-x86 cpus. * Fall back to some portable code. */ *newhead = hbuf[0] << 24 | hbuf[1] << 16 | hbuf[2] << 8 | hbuf[3]; #endif return TRUE; }
int recv_udp(int socket, char *buf, int amt, int *fromip, int *fromport) { struct sockaddr_in sin; int ret; unsigned int len; len = sizeof(sin); memset(&sin, 0, sizeof(sin)); ret = recvfrom(socket, buf, (size_t) amt, 0, (struct sockaddr*)&sin, &len); if (ret != -1) { if (fromip) *fromip = bswap_32(sin.sin_addr.s_addr); if (fromport) *fromport = bswap_16(sin.sin_port); } return ret; }
void trace(unsigned int pc, unsigned int sp, unsigned int top) { unsigned int *spalign = (unsigned int*)&_stack[0]; // if (pc < 0x40 || pc >=0x400) { if (sp > sizeof(_stack)) { printf("Access beyond end of stack 0x%08x\n",sp); fflush(stdout); abort(); } printf("0x%07X 0x%02X 0x%08X 0x%08X 0x%08X 0x?u 0x%016x\n", pc, _memory[pc], sp, top, bswap_32(spalign[ (sp/4) + 1] ),//*(unsigned int*)&_stack[sp+4]), zpuino_get_tick_count() ); fflush(stdout); // } }
int main( int argc, char *argv[] ) { tInt32 value = 0x42aa1234; tInt32 swap = bswap_32( value ); tInt32 result; unsigned int s = Demarshal( MarshalByteOrder() ? 0 : 1, &Int32Type, &result, &swap ); if ( s != sizeof( tInt32 ) ) return 1; if ( value != result ) return 1; return 0; }
td_err_e _td_check_sizeof (td_thragent_t *ta, uint32_t *sizep, int sizep_name) { if (*sizep == 0) { psaddr_t descptr; ps_err_e err = td_lookup (ta->ph, sizep_name, &descptr); if (err == PS_NOSYM) return TD_NOCAPAB; if (err == PS_OK) err = ps_pdread (ta->ph, descptr, sizep, sizeof *sizep); if (err != PS_OK) return TD_ERR; if (*sizep & 0xff000000U) *sizep = bswap_32 (*sizep); } return TD_OK; }
/* KColumnBlobValidate * runs checksum validation on unmodified blob */ static rc_t KColumnBlobValidateCRC32 ( const KColumnBlob *self ) { rc_t rc; const KColumn *col = self -> col; uint8_t buffer [ 8 * 1024 ]; size_t to_read, num_read, total, size; uint32_t cs, crc32 = 0; /* calculate checksum */ for ( size = self -> loc . u . blob . size, total = 0; total < size; total += num_read ) { to_read = size - total; if ( to_read > sizeof buffer ) to_read = sizeof buffer; rc = KColumnDataRead ( & col -> df, & self -> pmorig, total, buffer, to_read, & num_read ); if ( rc != 0 ) return rc; if ( num_read == 0 ) return RC ( rcDB, rcBlob, rcValidating, rcTransfer, rcIncomplete ); crc32 = CRC32 ( crc32, buffer, num_read ); } /* read stored checksum */ rc = KColumnDataRead ( & col -> df, & self -> pmorig, size, & cs, sizeof cs, & num_read ); if ( rc != 0 ) return rc; if ( num_read != sizeof cs ) return RC ( rcDB, rcBlob, rcValidating, rcTransfer, rcIncomplete ); if ( self -> bswap ) cs = bswap_32 ( cs ); if ( cs != crc32 ) return RC ( rcDB, rcBlob, rcValidating, rcBlob, rcCorrupt ); return 0; }
const uint8_t* SHA_final(SHA_CTX* ctx) { uint64_t cnt = ctx->count * 8; int i; SHA_update(ctx, (uint8_t*)"\x80", 1); while ((ctx->count % sizeof(ctx->buf)) != (sizeof(ctx->buf) - 8)) { SHA_update(ctx, (uint8_t*)"\0", 1); } for (i = 0; i < 8; ++i) { uint8_t tmp = cnt >> ((7 - i) * 8); SHA_update(ctx, &tmp, 1); } for (i = 0; i < 5; i++) { ctx->buf.w[i] = bswap_32(ctx->state[i]); } return ctx->buf.b; }
static void pci_config_write_long( unsigned char bus, unsigned char dev, int func, unsigned cmd, long val) { char path[100]; int fd; val = bswap_32(val); sprintf(path,"/proc/bus/pci/%02d/%02x.0", bus, dev); fd = open(path,O_RDONLY|O_SYNC); if (fd == -1) { retval=0; } else pwrite(fd, &val, 4, cmd); if (fd > 0) { close(fd); } }