xref: /freebsd/lib/libc/string/swab.c (revision 8aac90f18aef7c9eea906c3ff9a001ca7b94f375)
1 /*-
2  * SPDX-License-Identifier: BSD-2-Clause
3  * Copyright (c) 2024 rilysh <nightquick@proton.me>
4  */
5 
6 #include <unistd.h>
7 
8 void
9 swab(const void * __restrict from, void * __restrict to, ssize_t len)
10 {
11 	const unsigned char *f = from;
12 	unsigned char *t = to;
13 
14 	while (len > 1) {
15 		t[0] = f[1];
16 		t[1] = f[0];
17 
18 		f += 2;
19 		t += 2;
20 		len -= 2;
21 	}
22 }
23