comparison xrogue/state.c @ 207:3def5e487faa

XRogue: fix md_htonl() and md_ntohl(). xcrypt requires them. The implementations in state.c used htonl() and ntohl(), which aren't available on Windows. So the Advanced Rogue 7 versions were copied over. This implementation could be problematic on other systems where sizeof(long) == 8. Maybe someday I can convert everything to C99 and use stdint.h.
author John "Elwin" Edwards
date Thu, 13 Aug 2015 17:17:40 -0400
parents a3d90e31a001
children f54901b9c39b
comparison
equal deleted inserted replaced
206:a3d90e31a001 207:3def5e487faa
3325 return(_tty.c_cc[VKILL]); 3325 return(_tty.c_cc[VKILL]);
3326 */ 3326 */
3327 return(killchar()); 3327 return(killchar());
3328 } 3328 }
3329 3329
3330 long 3330 int md_endian = 0x01020304;
3331 md_ntohl(netlong) 3331
3332 long netlong; 3332 unsigned long int
3333 { 3333 md_ntohl(unsigned long int x)
3334 return( ntohl(netlong) ); 3334 {
3335 } 3335 #ifdef _WIN32
3336 3336 if ( *((char *)&md_endian) == 0x01 )
3337 long 3337 return(x);
3338 md_htonl(netlong) 3338 else
3339 long netlong; 3339 return( ((x & 0x000000ffU) << 24) |
3340 { 3340 ((x & 0x0000ff00U) << 8) |
3341 return(htonl(netlong)); 3341 ((x & 0x00ff0000U) >> 8) |
3342 ((x & 0xff000000U) >> 24) );
3343 #else
3344 return( ntohl(x) );
3345 #endif
3346 }
3347
3348 unsigned long int
3349 md_htonl(unsigned long int x)
3350 {
3351 #ifdef _WIN32
3352 if ( *((char *)&md_endian) == 0x01 )
3353 return(x);
3354 else
3355 return( ((x & 0x000000ffU) << 24) |
3356 ((x & 0x0000ff00U) << 8) |
3357 ((x & 0x00ff0000U) >> 8) |
3358 ((x & 0xff000000U) >> 24) );
3359 #else
3360 return( htonl(x) );
3361 #endif
3342 } 3362 }
3343 3363
3344 void 3364 void
3345 md_init() 3365 md_init()
3346 { 3366 {
3491 return( _unlink(file) ); 3511 return( _unlink(file) );
3492 #else 3512 #else
3493 return(unlink(file)); 3513 return(unlink(file));
3494 #endif 3514 #endif
3495 } 3515 }
3496