breakhack/src/util.c

55 lines
870 B
C
Raw Normal View History

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>
#ifndef _WIN32
2017-11-30 21:00:47 +01:00
#include <unistd.h>
#endif // _WIN32
2017-11-30 21:00:47 +01:00
#include <string.h>
#include "util.h"
void
2017-12-19 22:51:00 +01:00
m_strcpy(char *dest, size_t destsz, char *src)
{
#ifndef _WIN32
UNUSED(destsz);
strcpy(dest, src);
#else
strcpy_s(dest, destsz, src);
#endif // _WIN32
}
void
2017-12-19 22:51:00 +01:00
m_strncat(char *dest,
size_t destsz,
2017-12-19 22:51:00 +01:00
char *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 22:51:00 +01:00
m_strcpy(error_message, 100, "[!!] Fatal Error ");
m_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;
}