Skip to content

Commit

Permalink
Build fixes for usage in other projects than OpenSSL
Browse files Browse the repository at this point in the history
- if WinCE provides core I/O make assert a makro to not get linker errors
- check for predefined makros
- some headers need to predeclare functions available by the system itself. This screams for a cleaner solution
  • Loading branch information
Maurice Kalinowski committed Oct 30, 2008
1 parent ba15e42 commit ffe7dd7
Show file tree
Hide file tree
Showing 8 changed files with 50 additions and 8 deletions.
6 changes: 6 additions & 0 deletions include/assert.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
#ifndef __wcecompat__ASSERT_H__
#define __wcecompat__ASSERT_H__

#include <ceconfig.h>
#include <stdio.h>

#ifdef __cplusplus
extern "C" {
Expand All @@ -31,7 +33,11 @@ extern "C" {
#ifdef NDEBUG
#define assert(exp) ((void)0)
#else
#ifndef COREDLL_CORESIOA
void _assert(void*, void*, unsigned);
#else
#define _assert(exp,file,line) fprintf(stderr, "Assertion failed: %s, file %s, line %d\n", (char*)exp, file, line)
#endif
#define assert(exp) (void)( (exp) || (_assert(#exp, __FILE__, __LINE__), 0) )
#endif

Expand Down
16 changes: 14 additions & 2 deletions include/errno.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,25 @@ extern "C" {


extern int errno;

#ifndef ENOENT
#define ENOENT (2)
#endif

#ifndef EBADF
#define EBADF (9)
#endif

#ifndef EAGAIN
#define EAGAIN (11)
#endif

#ifndef ENOMEM
#define ENOMEM (12)
#define EINVAL (22)
#endif

#ifndef EINVAL
#define EINVAL (22)
#endif

#ifdef __cplusplus
}
Expand Down
6 changes: 4 additions & 2 deletions include/stddef.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
#ifdef __cplusplus
extern "C" {
#endif

#if 0
/* Define _CRTAPI1 (for compatibility with the NT SDK) */
#ifndef _CRTAPI1
#if _MSC_VER >= 800 && _M_IX86 >= 300
Expand All @@ -43,7 +43,7 @@ extern "C" {
#define _CRTAPI2
#endif
#endif

#endif
#ifndef _CRTIMP
#define _CRTIMP
#endif
Expand Down Expand Up @@ -77,7 +77,9 @@ typedef unsigned long time_t;
#endif
#endif

#ifndef offsetof
#define offsetof(s,m) ((size_t)&(((s*)0)->m))
#endif

#ifdef __cplusplus
}
Expand Down
6 changes: 6 additions & 0 deletions include/stdio.h
Original file line number Diff line number Diff line change
Expand Up @@ -157,9 +157,15 @@ _CRTIMP int __cdecl vfwprintf(FILE *, const wchar_t *, va_list);

void perror(const char *prefix);

#ifndef _IOFBF
#define _IOFBF 0
#endif
#ifndef _IOLBF
#define _IOLBF 1
#endif
#ifndef _IONBF
#define _IONBF 2
#endif
int setvbuf(FILE* stream, char* buffer, int mode, size_t size);

#ifdef __cplusplus
Expand Down
7 changes: 7 additions & 0 deletions include/stdlib.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,18 @@
#include "stddef.h"
#include "malloc.h"
#include "memory.h"
#include "float.h"

#ifdef __cplusplus
extern "C" {
#endif

extern float ceilf(float); /* inside default stdlib.h */
extern float fabsf(float);
extern float floorf(float);
extern float sqrtf(float);
extern float fmodf(float);

extern int _fmode; /* default file translation mode */

void abort(void);
Expand Down
1 change: 1 addition & 0 deletions include/string.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
#define __wcecompat__STRING_H__

#include "stddef.h"
#include "memory.h"

#ifdef __cplusplus
extern "C" {
Expand Down
13 changes: 10 additions & 3 deletions include/time.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,21 +22,29 @@
#ifndef __wcecompat__TIME_H__
#define __wcecompat__TIME_H__

#include <stdlib.h> // time_t defined there

extern size_t wcsftime(wchar_t *, size_t, const char *,const struct tm *);

#ifdef __cplusplus
extern "C" {
#endif


#include <stdlib.h> // time_t defined there
//typedef int time_t;

#ifndef _CLOCK_T_DEFINED
typedef unsigned long clock_t;
#endif
#ifndef CLOCKS_PER_SEC
#define CLOCKS_PER_SEC (1000)
#endif

time_t time(time_t* t);
clock_t __cdecl clock(void);

#ifndef _TM_DEFINED
#define _TM_DEFINED
struct tm
{
int tm_sec;
Expand All @@ -49,11 +57,10 @@ struct tm
int tm_yday;
int tm_isdst;
};
#endif

struct tm* localtime(const time_t* clock);
struct tm * __cdecl gmtime(const time_t *clock);


#ifdef __cplusplus
}
#endif
Expand Down
3 changes: 2 additions & 1 deletion src/assert.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,10 @@
#include <stdio.h>
#include <stdlib.h>


#ifndef COREDLL_CORESIOA
void _assert(void* expression, void* file, unsigned line)
{
fprintf(stderr, "Assertion failed: %s, file %s, line %d\n", (char*)expression, file, line);
exit(3);
}
#endif

0 comments on commit ffe7dd7

Please sign in to comment.