Reactos
at master 34 lines 753 B view raw
1// 2// swab.cpp 3// 4// Copyright (c) Microsoft Corporation. All rights reserved. 5// 6// Defines the _swab function, which copies a source buffer into a destination 7// buffer, swapping the odd and even bytes of each word as it does so. 8// 9#include <corecrt_internal.h> 10#include <stdlib.h> 11 12 13 14extern "C" void __cdecl _swab( 15 char* source, 16 char* destination, 17 int bytes 18 ) 19{ 20 _VALIDATE_RETURN_VOID(source != nullptr, EINVAL); 21 _VALIDATE_RETURN_VOID(destination != nullptr, EINVAL); 22 _VALIDATE_RETURN_VOID(bytes >= 0, EINVAL); 23 24 while (bytes > 1) 25 { 26 char const b1 = *source++; 27 char const b2 = *source++; 28 29 *destination++ = b2; 30 *destination++ = b1; 31 32 bytes -= 2; 33 } 34}