/*
 * GENERATED FILE, DO NOT EDIT. Generated by mkcast.py
 */

#include "cast.h"
#include <stdarg.h>
#include <stdio.h>
#include <stdlib.h>
void
cast_assert(int must, const char* fmt, ...)
{
    va_list ap;
    va_start(ap, fmt);
    if (!must) {
        fprintf(stderr, "arping: runtime check: ");
        vfprintf(stderr, fmt, ap);
        fprintf(stderr, "\n");
        exit(1);
    }
    va_end(ap);
}

uint16_t
cast_int16_uint16(int16_t from, const char* fmt, ...)
{
    va_list ap;
    va_start(ap, fmt);
    cast_assert(from >= 0, "cast_int16_uint16(%"PRIdMAX"): %s", (intmax_t)from, "need >= 0");    const uint16_t to = (uint16_t)from;    if (from != (int16_t)to) {
        fprintf(stderr, "arping: ");
        if (fmt) {
          vfprintf(stderr, fmt, ap);
          fprintf(stderr, ": value won't fit in uint16_t");
        } else {
          fprintf(stderr, "cast_int16_uint16(%"PRIdMAX"): %s", (intmax_t)from, "value won't fit in uint16_t\n");
        }
        fprintf(stderr, "\n");
        exit(1);
    }
    va_end(ap);
    return to;
}
size_t
cast_ssize_size(ssize_t from, const char* fmt, ...)
{
    va_list ap;
    va_start(ap, fmt);
    cast_assert(from >= 0, "cast_ssize_size(%"PRIdMAX"): %s", (intmax_t)from, "need >= 0");    const size_t to = (size_t)from;    if (from != (ssize_t)to) {
        fprintf(stderr, "arping: ");
        if (fmt) {
          vfprintf(stderr, fmt, ap);
          fprintf(stderr, ": value won't fit in size_t");
        } else {
          fprintf(stderr, "cast_ssize_size(%"PRIdMAX"): %s", (intmax_t)from, "value won't fit in size_t\n");
        }
        fprintf(stderr, "\n");
        exit(1);
    }
    va_end(ap);
    return to;
}
ssize_t
cast_size_ssize(size_t from, const char* fmt, ...)
{
    va_list ap;
    va_start(ap, fmt);
    const ssize_t to = (ssize_t)from;    cast_assert(to >= 0, "cast_size_ssize(%"PRIuMAX"): %s", (uintmax_t)from, "wrapped after casting");    if (from != (size_t)to) {
        fprintf(stderr, "arping: ");
        if (fmt) {
          vfprintf(stderr, fmt, ap);
          fprintf(stderr, ": value won't fit in ssize_t");
        } else {
          fprintf(stderr, "cast_size_ssize(%"PRIuMAX"): %s", (uintmax_t)from, "value won't fit in ssize_t\n");
        }
        fprintf(stderr, "\n");
        exit(1);
    }
    va_end(ap);
    return to;
}
uint16_t
cast_size_uint16(size_t from, const char* fmt, ...)
{
    va_list ap;
    va_start(ap, fmt);
    const uint16_t to = (uint16_t)from;    if (from != (size_t)to) {
        fprintf(stderr, "arping: ");
        if (fmt) {
          vfprintf(stderr, fmt, ap);
          fprintf(stderr, ": value won't fit in uint16_t");
        } else {
          fprintf(stderr, "cast_size_uint16(%"PRIuMAX"): %s", (uintmax_t)from, "value won't fit in uint16_t\n");
        }
        fprintf(stderr, "\n");
        exit(1);
    }
    va_end(ap);
    return to;
}
uint32_t
cast_size_uint32(size_t from, const char* fmt, ...)
{
    va_list ap;
    va_start(ap, fmt);
    const uint32_t to = (uint32_t)from;    if (from != (size_t)to) {
        fprintf(stderr, "arping: ");
        if (fmt) {
          vfprintf(stderr, fmt, ap);
          fprintf(stderr, ": value won't fit in uint32_t");
        } else {
          fprintf(stderr, "cast_size_uint32(%"PRIuMAX"): %s", (uintmax_t)from, "value won't fit in uint32_t\n");
        }
        fprintf(stderr, "\n");
        exit(1);
    }
    va_end(ap);
    return to;
}
unsigned int
cast_ulong_uint(unsigned long from, const char* fmt, ...)
{
    va_list ap;
    va_start(ap, fmt);
    const unsigned int to = (unsigned int)from;    if (from != (unsigned long)to) {
        fprintf(stderr, "arping: ");
        if (fmt) {
          vfprintf(stderr, fmt, ap);
          fprintf(stderr, ": value won't fit in unsigned int");
        } else {
          fprintf(stderr, "cast_ulong_uint(%"PRIuMAX"): %s", (uintmax_t)from, "value won't fit in unsigned int\n");
        }
        fprintf(stderr, "\n");
        exit(1);
    }
    va_end(ap);
    return to;
}
int16_t
cast_long_int16(long from, const char* fmt, ...)
{
    va_list ap;
    va_start(ap, fmt);
    const int16_t to = (int16_t)from;    if (from != (long)to) {
        fprintf(stderr, "arping: ");
        if (fmt) {
          vfprintf(stderr, fmt, ap);
          fprintf(stderr, ": value won't fit in int16_t");
        } else {
          fprintf(stderr, "cast_long_int16(%"PRIdMAX"): %s", (intmax_t)from, "value won't fit in int16_t\n");
        }
        fprintf(stderr, "\n");
        exit(1);
    }
    va_end(ap);
    return to;
}
uint8_t
cast_int16_uint8(int16_t from, const char* fmt, ...)
{
    va_list ap;
    va_start(ap, fmt);
    cast_assert(from >= 0, "cast_int16_uint8(%"PRIdMAX"): %s", (intmax_t)from, "need >= 0");    const uint8_t to = (uint8_t)from;    if (from != (int16_t)to) {
        fprintf(stderr, "arping: ");
        if (fmt) {
          vfprintf(stderr, fmt, ap);
          fprintf(stderr, ": value won't fit in uint8_t");
        } else {
          fprintf(stderr, "cast_int16_uint8(%"PRIdMAX"): %s", (intmax_t)from, "value won't fit in uint8_t\n");
        }
        fprintf(stderr, "\n");
        exit(1);
    }
    va_end(ap);
    return to;
}
unsigned int
cast_int_uint(int from, const char* fmt, ...)
{
    va_list ap;
    va_start(ap, fmt);
    cast_assert(from >= 0, "cast_int_uint(%"PRIdMAX"): %s", (intmax_t)from, "need >= 0");    const unsigned int to = (unsigned int)from;    if (from != (int)to) {
        fprintf(stderr, "arping: ");
        if (fmt) {
          vfprintf(stderr, fmt, ap);
          fprintf(stderr, ": value won't fit in unsigned int");
        } else {
          fprintf(stderr, "cast_int_uint(%"PRIdMAX"): %s", (intmax_t)from, "value won't fit in unsigned int\n");
        }
        fprintf(stderr, "\n");
        exit(1);
    }
    va_end(ap);
    return to;
}
uint16_t
cast_int_uint16(int from, const char* fmt, ...)
{
    va_list ap;
    va_start(ap, fmt);
    cast_assert(from >= 0, "cast_int_uint16(%"PRIdMAX"): %s", (intmax_t)from, "need >= 0");    const uint16_t to = (uint16_t)from;    if (from != (int)to) {
        fprintf(stderr, "arping: ");
        if (fmt) {
          vfprintf(stderr, fmt, ap);
          fprintf(stderr, ": value won't fit in uint16_t");
        } else {
          fprintf(stderr, "cast_int_uint16(%"PRIdMAX"): %s", (intmax_t)from, "value won't fit in uint16_t\n");
        }
        fprintf(stderr, "\n");
        exit(1);
    }
    va_end(ap);
    return to;
}
int
cast_long_int(long from, const char* fmt, ...)
{
    va_list ap;
    va_start(ap, fmt);
    const int to = (int)from;    if (from != (long)to) {
        fprintf(stderr, "arping: ");
        if (fmt) {
          vfprintf(stderr, fmt, ap);
          fprintf(stderr, ": value won't fit in int");
        } else {
          fprintf(stderr, "cast_long_int(%"PRIdMAX"): %s", (intmax_t)from, "value won't fit in int\n");
        }
        fprintf(stderr, "\n");
        exit(1);
    }
    va_end(ap);
    return to;
}
uint8_t
cast_long_uint8(long from, const char* fmt, ...)
{
    va_list ap;
    va_start(ap, fmt);
    cast_assert(from >= 0, "cast_long_uint8(%"PRIdMAX"): %s", (intmax_t)from, "need >= 0");    const uint8_t to = (uint8_t)from;    if (from != (long)to) {
        fprintf(stderr, "arping: ");
        if (fmt) {
          vfprintf(stderr, fmt, ap);
          fprintf(stderr, ": value won't fit in uint8_t");
        } else {
          fprintf(stderr, "cast_long_uint8(%"PRIdMAX"): %s", (intmax_t)from, "value won't fit in uint8_t\n");
        }
        fprintf(stderr, "\n");
        exit(1);
    }
    va_end(ap);
    return to;
}
gid_t
cast_ulong_gid(unsigned long from, const char* fmt, ...)
{
    va_list ap;
    va_start(ap, fmt);
    const gid_t to = (gid_t)from;    if (from != (unsigned long)to) {
        fprintf(stderr, "arping: ");
        if (fmt) {
          vfprintf(stderr, fmt, ap);
          fprintf(stderr, ": value won't fit in gid_t");
        } else {
          fprintf(stderr, "cast_ulong_gid(%"PRIuMAX"): %s", (uintmax_t)from, "value won't fit in gid_t\n");
        }
        fprintf(stderr, "\n");
        exit(1);
    }
    va_end(ap);
    return to;
}
unsigned long long
cast_longlong_ulonglong(long long from, const char* fmt, ...)
{
    va_list ap;
    va_start(ap, fmt);
    cast_assert(from >= 0, "cast_longlong_ulonglong(%"PRIdMAX"): %s", (intmax_t)from, "need >= 0");    const unsigned long long to = (unsigned long long)from;    if (from != (long long)to) {
        fprintf(stderr, "arping: ");
        if (fmt) {
          vfprintf(stderr, fmt, ap);
          fprintf(stderr, ": value won't fit in unsigned long long");
        } else {
          fprintf(stderr, "cast_longlong_ulonglong(%"PRIdMAX"): %s", (intmax_t)from, "value won't fit in unsigned long long\n");
        }
        fprintf(stderr, "\n");
        exit(1);
    }
    va_end(ap);
    return to;
}
unsigned int
cast_longlong_uint(long long from, const char* fmt, ...)
{
    va_list ap;
    va_start(ap, fmt);
    cast_assert(from >= 0, "cast_longlong_uint(%"PRIdMAX"): %s", (intmax_t)from, "need >= 0");    const unsigned int to = (unsigned int)from;    if (from != (long long)to) {
        fprintf(stderr, "arping: ");
        if (fmt) {
          vfprintf(stderr, fmt, ap);
          fprintf(stderr, ": value won't fit in unsigned int");
        } else {
          fprintf(stderr, "cast_longlong_uint(%"PRIdMAX"): %s", (intmax_t)from, "value won't fit in unsigned int\n");
        }
        fprintf(stderr, "\n");
        exit(1);
    }
    va_end(ap);
    return to;
}
int16_t
cast_int_int16(int from, const char* fmt, ...)
{
    va_list ap;
    va_start(ap, fmt);
    const int16_t to = (int16_t)from;    if (from != (int)to) {
        fprintf(stderr, "arping: ");
        if (fmt) {
          vfprintf(stderr, fmt, ap);
          fprintf(stderr, ": value won't fit in int16_t");
        } else {
          fprintf(stderr, "cast_int_int16(%"PRIdMAX"): %s", (intmax_t)from, "value won't fit in int16_t\n");
        }
        fprintf(stderr, "\n");
        exit(1);
    }
    va_end(ap);
    return to;
}