⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 byteord.c

📁 CFL是Unix下的通用抽象库,以简化Unix下的系统软件开发,CFL库中包含几个分组的函数和宏
💻 C
字号:
/* ----------------------------------------------------------------------------   CFL - A C Foundation Library   Copyright (C) 1994-2003  Mark A Lindner   This file is part of CFL.      This library is free software; you can redistribute it and/or   modify it under the terms of the GNU Library General Public   License as published by the Free Software Foundation; either   version 2 of the License, or (at your option) any later version.      This library is distributed in the hope that it will be useful,   but WITHOUT ANY WARRANTY; without even the implied warranty of   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU   Library General Public License for more details.      You should have received a copy of the GNU Library General Public   License along with this library; if not, write to the Free   Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.   ----------------------------------------------------------------------------   $Log: byteord.c,v $   Revision 1.3  2003/06/23 01:32:32  markl   removed unnecessary header   Revision 1.2  2003/06/22 09:42:03  markl   Fixed compatiblity probems with int??_t types.   Revision 1.1  2003/06/15 06:30:41  markl   New file   ----------------------------------------------------------------------------*//* Feature test switches */#include "config.h"/* System headers */#include <sys/types.h>#include <netinet/in.h>/* Local headers */#include "cfl/defs.h"#include "cfl/system.h"/* Structs and unions */union un32  {  float f;  uint32_t l;  };union un64  {  double d;  uint64_t ll;  };/* File scope variables */#define __C_byteord_big_endian ((c_bool_t)(htonl(1) == 1))/* Functions */uint16_t C_byteord_htons(uint16_t val)  {  return(htons(val));  }/* */uint16_t C_byteord_ntohs(uint16_t val)  {  return(ntohs(val));  }/* */uint32_t C_byteord_htonl(uint32_t val)  {  return(htonl(val));  }/* */uint32_t C_byteord_ntohl(uint32_t val)  {  return(ntohl(val));  }/* */uint64_t C_byteord_htonll(uint64_t val)  {  if(__C_byteord_big_endian)    return(val);  else    return((((uint64_t)htonl((uint32_t)val)) << 32)           + htonl((uint32_t)(val >> 32)));  }/* */uint64_t C_byteord_ntohll(uint64_t val)  {  if(__C_byteord_big_endian)    return(val);  else    return((((uint64_t)ntohl((uint32_t)val)) << 32)           + ntohl((uint32_t)(val >> 32)));  }/* */float C_byteord_htonf(float val)  {  union un32 u;    u.f = val;  u.l = C_byteord_htonl(u.l);    return(u.f);  }/* */float C_byteord_ntohf(float val)  {  union un32 u;    u.f = val;  u.l = C_byteord_ntohl(u.l);  return(u.f);  }/* */double C_byteord_htond(double val)  {  union un64 u;  u.d = val;  u.ll = C_byteord_htonll(u.ll);  return(u.d);  }/* */double C_byteord_ntohd(double val)  {  union un64 u;  u.d = val;  u.ll = C_byteord_ntohll(u.ll);  return(u.d);  }/* end of source file */

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -