aboutsummaryrefslogtreecommitdiff
path: root/libc/src/unistd/swab.cpp
blob: 643079a40ab5cb6ee80f92af6201790b3ffb9eb1 (plain)
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
//===-- Implementation of swab --------------------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//

#include "src/unistd/swab.h"

#include "src/__support/common.h"
#include "src/__support/macros/config.h"

namespace LIBC_NAMESPACE_DECL {

LLVM_LIBC_FUNCTION(void, swab,
                   (const void *__restrict from, void *__restrict to,
                    ssize_t n)) {
  const unsigned char *f = static_cast<const unsigned char *>(from);
  unsigned char *t = static_cast<unsigned char *>(to);
  for (ssize_t i = 1; i < n; i += 2) {
    t[i - 1] = f[i];
    t[i] = f[i - 1];
  }
}

} // namespace LIBC_NAMESPACE_DECL