LCOV - code coverage report
Current view: top level - common - host2net.h (source / functions) Hit Total Coverage
Test: coverage.info Lines: 12 24 50.0 %
Date: 2016-09-12 13:01:59 Functions: 4 8 50.0 %

          Line data    Source code
       1             : /* host2net.h - Endian conversion macros
       2             :  * Copyright (C) 1998, 2014, 2015  Werner Koch
       3             :  *
       4             :  * This file is part of GnuPG.
       5             :  *
       6             :  * This file is free software; you can redistribute it and/or modify
       7             :  * it under the terms of either
       8             :  *
       9             :  *   - the GNU Lesser General Public License as published by the Free
      10             :  *     Software Foundation; either version 3 of the License, or (at
      11             :  *     your option) any later version.
      12             :  *
      13             :  * or
      14             :  *
      15             :  *   - the GNU General Public License as published by the Free
      16             :  *     Software Foundation; either version 2 of the License, or (at
      17             :  *     your option) any later version.
      18             :  *
      19             :  * or both in parallel, as here.
      20             :  *
      21             :  * This file is distributed in the hope that it will be useful,
      22             :  * but WITHOUT ANY WARRANTY; without even the implied warranty of
      23             :  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      24             :  * GNU General Public License for more details.
      25             :  *
      26             :  * You should have received a copy of the GNU General Public License
      27             :  * along with this program; if not, see <http://www.gnu.org/licenses/>.
      28             :  */
      29             : 
      30             : #ifndef GNUPG_COMMON_HOST2NET_H
      31             : #define GNUPG_COMMON_HOST2NET_H
      32             : 
      33             : #include "types.h"
      34             : 
      35             : #define ulongtobuf( p, a ) do {                           \
      36             :                             ((byte*)p)[0] = a >> 24;      \
      37             :                             ((byte*)p)[1] = a >> 16;      \
      38             :                             ((byte*)p)[2] = a >>  8;      \
      39             :                             ((byte*)p)[3] = a      ;    \
      40             :                         } while(0)
      41             : #define ushorttobuf( p, a ) do {                           \
      42             :                             ((byte*)p)[0] = a >>  8;      \
      43             :                             ((byte*)p)[1] = a      ;    \
      44             :                         } while(0)
      45             : 
      46             : 
      47             : static inline unsigned long
      48      272398 : buf16_to_ulong (const void *buffer)
      49             : {
      50      272398 :   const unsigned char *p = buffer;
      51             : 
      52      272398 :   return (((unsigned long)p[0] << 8) | p[1]);
      53             : }
      54             : 
      55             : static inline unsigned int
      56           0 : buf16_to_uint (const void *buffer)
      57             : {
      58           0 :   const unsigned char *p = buffer;
      59             : 
      60           0 :   return (((unsigned int)p[0] << 8) | p[1]);
      61             : }
      62             : 
      63             : static inline unsigned short
      64           0 : buf16_to_ushort (const void *buffer)
      65             : {
      66           0 :   const unsigned char *p = buffer;
      67             : 
      68           0 :   return (((unsigned short)p[0] << 8) | p[1]);
      69             : }
      70             : 
      71             : static inline u16
      72         265 : buf16_to_u16 (const void *buffer)
      73             : {
      74         265 :   const unsigned char *p = buffer;
      75             : 
      76         265 :   return (((u16)p[0] << 8) | p[1]);
      77             : }
      78             : 
      79             : static inline size_t
      80           0 : buf32_to_size_t (const void *buffer)
      81             : {
      82           0 :   const unsigned char *p = buffer;
      83             : 
      84           0 :   return (((size_t)p[0] << 24) | (p[1] << 16) | (p[2] << 8) | p[3]);
      85             : }
      86             : 
      87             : static inline unsigned long
      88       49264 : buf32_to_ulong (const void *buffer)
      89             : {
      90       49264 :   const unsigned char *p = buffer;
      91             : 
      92       49264 :   return (((unsigned long)p[0] << 24) | (p[1] << 16) | (p[2] << 8) | p[3]);
      93             : }
      94             : 
      95             : static inline unsigned int
      96           0 : buf32_to_uint (const void *buffer)
      97             : {
      98           0 :   const unsigned char *p = buffer;
      99             : 
     100           0 :   return (((unsigned int)p[0] << 24) | (p[1] << 16) | (p[2] << 8) | p[3]);
     101             : }
     102             : 
     103             : static inline u32
     104       34787 : buf32_to_u32 (const void *buffer)
     105             : {
     106       34787 :   const unsigned char *p = buffer;
     107             : 
     108       34787 :   return (((u32)p[0] << 24) | (p[1] << 16) | (p[2] << 8) | p[3]);
     109             : }
     110             : 
     111             : 
     112             : #endif /*GNUPG_COMMON_HOST2NET_H*/

Generated by: LCOV version 1.11