cscg24-guacamole

CSCG 2024 Challenge 'Guacamole Mashup'
git clone https://git.sinitax.com/sinitax/cscg24-guacamole
Log | Files | Refs | sfeed.txt

crt.h (4521B)


      1/**
      2 * WinPR: Windows Portable Runtime
      3 * C Run-Time Library Routines
      4 *
      5 * Copyright 2012 Marc-Andre Moreau <marcandre.moreau@gmail.com>
      6 *
      7 * Licensed under the Apache License, Version 2.0 (the "License");
      8 * you may not use this file except in compliance with the License.
      9 * You may obtain a copy of the License at
     10 *
     11 *     http://www.apache.org/licenses/LICENSE-2.0
     12 *
     13 * Unless required by applicable law or agreed to in writing, software
     14 * distributed under the License is distributed on an "AS IS" BASIS,
     15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     16 * See the License for the specific language governing permissions and
     17 * limitations under the License.
     18 */
     19
     20#ifndef WINPR_CRT_H
     21#define WINPR_CRT_H
     22
     23#include <stdio.h>
     24#include <stdlib.h>
     25#include <string.h>
     26
     27#include <winpr/winpr.h>
     28
     29#include <winpr/spec.h>
     30#include <winpr/string.h>
     31#include <winpr/heap.h>
     32
     33#ifndef _WIN32
     34
     35#include <unistd.h>
     36
     37#ifndef _write
     38#define _write write
     39#endif
     40
     41#ifndef _strtoui64
     42#define _strtoui64 strtoull
     43#endif /* _strtoui64 */
     44
     45#ifndef _strtoi64
     46#define _strtoi64 strtoll
     47#endif /* _strtoi64 */
     48
     49#ifndef _rotl
     50static INLINE UINT32 _rotl(UINT32 value, int shift)
     51{
     52	return (value << shift) | (value >> (32 - shift));
     53}
     54#endif /* _rotl */
     55
     56#ifndef _rotl64
     57static INLINE UINT64 _rotl64(UINT64 value, int shift)
     58{
     59	return (value << shift) | (value >> (64 - shift));
     60}
     61#endif /* _rotl64 */
     62
     63#ifndef _rotr
     64static INLINE UINT32 _rotr(UINT32 value, int shift)
     65{
     66	return (value >> shift) | (value << (32 - shift));
     67}
     68#endif /* _rotr */
     69
     70#ifndef _rotr64
     71static INLINE UINT64 _rotr64(UINT64 value, int shift)
     72{
     73	return (value >> shift) | (value << (64 - shift));
     74}
     75#endif /* _rotr64 */
     76
     77#if (__GNUC__ > 4) || ((__GNUC__ == 4) && (__GNUC_MINOR__ >= 2))
     78
     79#define _byteswap_ulong(_val) __builtin_bswap32(_val)
     80#define _byteswap_uint64(_val) __builtin_bswap64(_val)
     81
     82#else
     83
     84static INLINE UINT32 _byteswap_ulong(UINT32 _val)
     85{
     86	return (((_val) >> 24) | (((_val)&0x00FF0000) >> 8) | (((_val)&0x0000FF00) << 8) |
     87	        ((_val) << 24));
     88}
     89
     90static INLINE UINT64 _byteswap_uint64(UINT64 _val)
     91{
     92	return (((_val) << 56) | (((_val) << 40) & 0xFF000000000000) |
     93	        (((_val) << 24) & 0xFF0000000000) | (((_val) << 8) & 0xFF00000000) |
     94	        (((_val) >> 8) & 0xFF000000) | (((_val) >> 24) & 0xFF0000) | (((_val) >> 40) & 0xFF00) |
     95	        ((_val) >> 56));
     96}
     97
     98#endif /* (__GNUC__ > 4) || ... */
     99
    100#if (__GNUC__ > 4) || ((__GNUC__ == 4) && (__GNUC_MINOR__ >= 8))
    101
    102#define _byteswap_ushort(_val) __builtin_bswap16(_val)
    103
    104#else
    105
    106static INLINE UINT16 _byteswap_ushort(UINT16 _val)
    107{
    108	return (((_val) >> 8) | ((_val) << 8));
    109}
    110
    111#endif /* (__GNUC__ > 4) || ... */
    112
    113#define CopyMemory(Destination, Source, Length) memcpy((Destination), (Source), (Length))
    114#define MoveMemory(Destination, Source, Length) memmove((Destination), (Source), (Length))
    115#define FillMemory(Destination, Length, Fill) memset((Destination), (Fill), (Length))
    116#define ZeroMemory(Destination, Length) memset((Destination), 0, (Length))
    117
    118#ifdef __cplusplus
    119extern "C"
    120{
    121#endif
    122
    123	WINPR_API PVOID SecureZeroMemory(PVOID ptr, SIZE_T cnt);
    124
    125#ifdef __cplusplus
    126}
    127#endif
    128
    129/* Data Alignment */
    130
    131#ifndef _ERRNO_T_DEFINED
    132#define _ERRNO_T_DEFINED
    133typedef int errno_t;
    134#endif /* _ERRNO_T_DEFINED */
    135
    136#ifdef __cplusplus
    137extern "C"
    138{
    139#endif
    140
    141	WINPR_API void* _aligned_malloc(size_t size, size_t alignment);
    142	WINPR_API void* _aligned_realloc(void* memblock, size_t size, size_t alignment);
    143	WINPR_API void* _aligned_recalloc(void* memblock, size_t num, size_t size, size_t alignment);
    144
    145	WINPR_API void* _aligned_offset_malloc(size_t size, size_t alignment, size_t offset);
    146	WINPR_API void* _aligned_offset_realloc(void* memblock, size_t size, size_t alignment,
    147	                                        size_t offset);
    148	WINPR_API void* _aligned_offset_recalloc(void* memblock, size_t num, size_t size,
    149	                                         size_t alignment, size_t offset);
    150
    151	WINPR_API size_t _aligned_msize(void* memblock, size_t alignment, size_t offset);
    152
    153	WINPR_API void _aligned_free(void* memblock);
    154
    155	/* Data Conversion */
    156
    157	WINPR_API errno_t _itoa_s(int value, char* buffer, size_t sizeInCharacters, int radix);
    158
    159	/* Buffer Manipulation */
    160
    161	WINPR_API errno_t memmove_s(void* dest, size_t numberOfElements, const void* src, size_t count);
    162	WINPR_API errno_t wmemmove_s(WCHAR* dest, size_t numberOfElements, const WCHAR* src,
    163	                             size_t count);
    164
    165#ifdef __cplusplus
    166}
    167#endif
    168
    169#endif /* _WIN32 */
    170
    171#endif /* WINPR_CRT_H */