File: endian.c

package info (click to toggle)
s3d 0.2.3-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 5,708 kB
  • sloc: ansic: 23,609; python: 488; perl: 98; makefile: 31; sh: 29
file content (61 lines) | stat: -rw-r--r-- 1,382 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
// SPDX-License-Identifier: GPL-2.0-or-later
/* SPDX-FileCopyrightText: 2004-2015  S3D contributors
 */

#include <arpa/inet.h>		/*  htonl(),htons() */
#include <stdint.h>
#include "global.h"

/* convert buffer with floats from host to network endianess */
void htonfb(float *netfloat, int num)
{
	int i;
	for (i = 0; i < num; i++) {
		*(uint32_t *) & netfloat[i] = htonl(*(uint32_t *) & netfloat[i]);
	}
}

/* convert buffer with floats from network to host endianess */
void ntohfb(float *netfloat, int num)
{
	int i;
	for (i = 0; i < num; i++) {
		*(uint32_t *) & netfloat[i] = ntohl(*(uint32_t *) & netfloat[i]);
	}
}

/* convert buffer with uint32_ts from host to network endianess */
void htonlb(uint32_t * netint32, int num)
{
	int i;
	for (i = 0; i < num; i++) {
		netint32[i] = htonl(netint32[i]);
	}
}

/* convert buffer with uint32_ts from network to host endianess */
void ntohlb(uint32_t * netint32, int num)
{
	int i;
	for (i = 0; i < num; i++) {
		netint32[i] = ntohl(netint32[i]);
	}
}

/* convert buffer with uint16_ts from host to network endianess */
void htonsb(uint16_t * netint16, int num)
{
	int i;
	for (i = 0; i < num; i++) {
		netint16[i] = htons(netint16[i]);
	}
}

/* convert buffer with uint16_ts from network to host endianess */
void ntohsb(uint16_t * netint16, int num)
{
	int i;
	for (i = 0; i < num; i++) {
		netint16[i] = ntohs(netint16[i]);
	}
}