Endian madness

Tom Coleman tcoleman at autowares.com
Fri Jul 21 16:52:47 EDT 2000



The token datastream length in a query packet (0x0f) is apparently a long.

This turned up on a port to the RS-6000.

This code fragment from tds_submit_query will work on either big or
little endian machines:


if (IS_TDS50(tds)) {
   bufsize = strlen(query)+6;		
   buf = (unsigned char *) malloc(bufsize);	
   memset(buf,'\0',bufsize);		
   buf[0]=TDS_LANG_TOKEN;		

/* send 4-byte token datastream length */
   { 
   TDS_INT qlen = strlen(query) + 1;
   memcpy(buf+1, (void *)&qlen, 4);
   }

/*       original code
   buf[1]=(strlen(query)+1)%256;		               
buf[2]=(strlen(query)+1)/256;
*/
}
else...



More information about the FreeTDS mailing list