2017-12-19 19:42:05 +01:00
|
|
|
#include "defines.h"
|
2017-11-30 21:00:47 +01:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
2017-12-19 21:00:02 +01:00
|
|
|
#ifndef _WIN32
|
2017-11-30 21:00:47 +01:00
|
|
|
#include <unistd.h>
|
2017-12-19 21:00:02 +01:00
|
|
|
#endif // _WIN32
|
2017-11-30 21:00:47 +01:00
|
|
|
#include <string.h>
|
|
|
|
|
|
|
|
#include "util.h"
|
|
|
|
|
2017-12-19 21:00:02 +01:00
|
|
|
void
|
|
|
|
_strcpy(char *restrict dest, size_t destsz, char *restrict src)
|
|
|
|
{
|
|
|
|
#ifndef _WIN32
|
|
|
|
UNUSED(destsz);
|
|
|
|
strcpy(dest, src);
|
|
|
|
#else
|
|
|
|
strcpy_s(dest, destsz, src);
|
|
|
|
#endif // _WIN32
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
_strncat(char *restrict dest,
|
|
|
|
size_t destsz,
|
|
|
|
char *restrict src,
|
|
|
|
size_t srcsz)
|
|
|
|
{
|
|
|
|
#ifndef _WIN32
|
|
|
|
UNUSED(destsz);
|
|
|
|
UNUSED(srcsz);
|
|
|
|
strncat(dest, src, srcsz);
|
|
|
|
#else
|
|
|
|
strncat_s(dest, destsz, src, srcsz);
|
|
|
|
#endif // _WIN32
|
|
|
|
}
|
|
|
|
|
2017-11-30 21:00:47 +01:00
|
|
|
void fatal(char *message)
|
|
|
|
{
|
|
|
|
char error_message[100];
|
|
|
|
|
2017-12-19 21:00:02 +01:00
|
|
|
_strcpy(error_message, 100, "[!!] Fatal Error ");
|
|
|
|
_strncat(error_message, 100, message, 83);
|
2017-11-30 21:00:47 +01:00
|
|
|
perror(error_message);
|
|
|
|
exit(-1);
|
|
|
|
}
|
|
|
|
|
|
|
|
void *ec_malloc(unsigned int size)
|
|
|
|
{
|
|
|
|
void *ptr;
|
|
|
|
ptr = malloc(size);
|
|
|
|
if (ptr == NULL)
|
|
|
|
fatal("in ec_malloc() on memory allocation");
|
|
|
|
return ptr;
|
|
|
|
}
|