LCOV - code coverage report
Current view: top level - basic - unaligned.h (source / functions) Hit Total Coverage
Test: systemd test coverage Lines: 27 27 100.0 %
Date: 2015-07-29 18:47:03 Functions: 6 6 100.0 %

          Line data    Source code
       1             : /*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
       2             : 
       3             : #pragma once
       4             : 
       5             : /***
       6             :   This file is part of systemd.
       7             : 
       8             :   Copyright 2014 Tom Gundersen
       9             : 
      10             :   systemd is free software; you can redistribute it and/or modify it
      11             :   under the terms of the GNU Lesser General Public License as published by
      12             :   the Free Software Foundation; either version 2.1 of the License, or
      13             :   (at your option) any later version.
      14             : 
      15             :   systemd is distributed in the hope that it will be useful, but
      16             :   WITHOUT ANY WARRANTY; without even the implied warranty of
      17             :   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
      18             :   Lesser General Public License for more details.
      19             : 
      20             :   You should have received a copy of the GNU Lesser General Public License
      21             :   along with systemd; If not, see <http://www.gnu.org/licenses/>.
      22             : ***/
      23             : 
      24             : #include <stdint.h>
      25             : 
      26          46 : static inline uint16_t unaligned_read_be16(const void *_u) {
      27          46 :         const uint8_t *u = _u;
      28             : 
      29          92 :         return (((uint16_t) u[0]) << 8) |
      30          46 :                 ((uint16_t) u[1]);
      31             : }
      32             : 
      33          22 : static inline uint32_t unaligned_read_be32(const void *_u) {
      34          22 :         const uint8_t *u = _u;
      35             : 
      36          44 :         return (((uint32_t) unaligned_read_be16(u)) << 16) |
      37          22 :                 ((uint32_t) unaligned_read_be16(u + 2));
      38             : }
      39             : 
      40           8 : static inline uint64_t unaligned_read_be64(const void *_u) {
      41           8 :         const uint8_t *u = _u;
      42             : 
      43          16 :         return (((uint64_t) unaligned_read_be32(u)) << 32) |
      44           8 :                 ((uint64_t) unaligned_read_be32(u + 4));
      45             : }
      46             : 
      47          72 : static inline void unaligned_write_be16(void *_u, uint16_t a) {
      48          72 :         uint8_t *u = _u;
      49             : 
      50          72 :         u[0] = (uint8_t) (a >> 8);
      51          72 :         u[1] = (uint8_t) a;
      52          72 : }
      53             : 
      54          32 : static inline void unaligned_write_be32(void *_u, uint32_t a) {
      55          32 :         uint8_t *u = _u;
      56             : 
      57          32 :         unaligned_write_be16(u, (uint16_t) (a >> 16));
      58          32 :         unaligned_write_be16(u + 2, (uint16_t) a);
      59          32 : }
      60             : 
      61           8 : static inline void unaligned_write_be64(void *_u, uint64_t a) {
      62           8 :         uint8_t *u = _u;
      63             : 
      64           8 :         unaligned_write_be32(u, (uint32_t) (a >> 32));
      65           8 :         unaligned_write_be32(u + 4, (uint32_t) a);
      66           8 : }

Generated by: LCOV version 1.11