mirror of
https://github.com/esp8266/Arduino.git
synced 2025-06-12 01:53:07 +03:00
new trunk
git-svn-id: svn://svn.code.sf.net/p/axtls/code/trunk@78 9a5d90b5-6617-0410-8a86-bb477d3ed2e3
This commit is contained in:
142
ssl/os_port.c
Normal file
142
ssl/os_port.c
Normal file
@ -0,0 +1,142 @@
|
||||
/*
|
||||
* Copyright(C) 2006 Cameron Rich
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*/
|
||||
|
||||
/**
|
||||
* @file os_port.c
|
||||
*
|
||||
* OS specific functions.
|
||||
*/
|
||||
#include <time.h>
|
||||
#include <stdlib.h>
|
||||
#include <errno.h>
|
||||
#include <stdarg.h>
|
||||
#include "os_port.h"
|
||||
|
||||
#ifdef WIN32
|
||||
/**
|
||||
* gettimeofday() not in Win32
|
||||
*/
|
||||
EXP_FUNC void STDCALL gettimeofday(struct timeval* t, void* timezone)
|
||||
{
|
||||
#if defined(_WIN32_WCE)
|
||||
t->tv_sec = time(NULL);
|
||||
t->tv_usec = 0; /* 1sec precision only */
|
||||
#else
|
||||
struct _timeb timebuffer;
|
||||
_ftime(&timebuffer);
|
||||
t->tv_sec = (long)timebuffer.time;
|
||||
t->tv_usec = 1000 * timebuffer.millitm; /* 1ms precision */
|
||||
#endif
|
||||
}
|
||||
|
||||
/**
|
||||
* strcasecmp() not in Win32
|
||||
*/
|
||||
EXP_FUNC int STDCALL strcasecmp(const char *s1, const char *s2)
|
||||
{
|
||||
while (tolower(*s1) == tolower(*s2++))
|
||||
{
|
||||
if (*s1++ == '\0')
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
return *(unsigned char *)s1 - *(unsigned char *)(s2 - 1);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
#undef malloc
|
||||
#undef realloc
|
||||
#undef calloc
|
||||
#undef open
|
||||
#undef fopen
|
||||
|
||||
static const char * out_of_mem_str = "out of memory";
|
||||
static const char * file_open_str = "Could not open file \"%s\"";
|
||||
|
||||
/*
|
||||
* Some functions that call display some error trace and then call abort().
|
||||
* This just makes life much easier on embedded systems, since we're
|
||||
* suffering major trauma...
|
||||
*/
|
||||
EXP_FUNC void * STDCALL ax_malloc(size_t s)
|
||||
{
|
||||
void *x;
|
||||
|
||||
if ((x = malloc(s)) == NULL)
|
||||
exit_now(out_of_mem_str);
|
||||
|
||||
return x;
|
||||
}
|
||||
|
||||
EXP_FUNC void * STDCALL ax_realloc(void *y, size_t s)
|
||||
{
|
||||
void *x;
|
||||
|
||||
if ((x = realloc(y, s)) == NULL)
|
||||
exit_now(out_of_mem_str);
|
||||
|
||||
return x;
|
||||
}
|
||||
|
||||
EXP_FUNC void * STDCALL ax_calloc(size_t n, size_t s)
|
||||
{
|
||||
void *x;
|
||||
|
||||
if ((x = calloc(n, s)) == NULL)
|
||||
exit_now(out_of_mem_str);
|
||||
|
||||
return x;
|
||||
}
|
||||
|
||||
EXP_FUNC FILE * STDCALL ax_fopen(const char *pathname, const char *type)
|
||||
{
|
||||
FILE *f;
|
||||
|
||||
if ((f = fopen(pathname, type)) == NULL)
|
||||
exit_now(file_open_str, pathname);
|
||||
|
||||
return f;
|
||||
}
|
||||
|
||||
EXP_FUNC int STDCALL ax_open(const char *pathname, int flags)
|
||||
{
|
||||
int x;
|
||||
|
||||
if ((x = open(pathname, flags)) < 0)
|
||||
exit_now(file_open_str, pathname);
|
||||
|
||||
return x;
|
||||
}
|
||||
|
||||
/**
|
||||
* This is a call which will deliberately exit an application, but will
|
||||
* display some information before dying.
|
||||
*/
|
||||
void exit_now(const char *format, ...)
|
||||
{
|
||||
va_list argp;
|
||||
|
||||
va_start(argp, format);
|
||||
vfprintf(stderr, format, argp);
|
||||
va_end(argp);
|
||||
abort();
|
||||
}
|
||||
|
Reference in New Issue
Block a user