OpenCores
URL https://opencores.org/ocsvn/thor/thor/trunk

Subversion Repositories thor

[/] [thor/] [trunk/] [FT64v5/] [software/] [CC64/] [source/] [compat.h] - Blame information for rev 48

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 48 robfinch
#ifndef _COMPAT_H
2
#define _COMPAT_H
3
 
4
// Compatibility definitions for compiling with GCC on Linux
5
// David Banks (hoglet) 2017
6
 
7
#ifndef __GNUC__
8
 
9
// On Windows use Rob's FPP pre processor
10
// The -b option supresses the banner text
11
#define PREPROCESSOR_CMD "fpp -b %s %s"
12
 
13
#else
14
 
15
// On Linux use gcc's cpp
16
// the -P option inhibits line markers, as these causes errors in C64
17
#define PREPROCESSOR_CMD "cpp -P %s %s"
18
 
19
#include <unistd.h>
20
#include <stdlib.h>
21
#include <stdarg.h>
22
#include <string.h>
23
#include <libgen.h>
24
#include <errno.h>
25
 
26
#define _strdup strdup
27
#define _access access
28
#define  __int8 char
29
#define __int16 short
30
#define __int64 long long
31
 
32
static inline int min (int a, int b) { return a < b ? a : b; }
33
 
34
static inline int max (int a, int b) { return a > b ? a : b; }
35
 
36
static inline int _dupenv_s(char **buffer, size_t *numberOfElements, const char *varname) {
37
   if (buffer == NULL || numberOfElements == NULL || varname == NULL) {
38
      return EINVAL;
39
   }
40
   char *env = getenv(varname);
41
   if (env == NULL) {
42
      *buffer = NULL;
43
      *numberOfElements = 0;
44
   } else {
45
      *numberOfElements = strlen(env);
46
      *buffer = (char *)malloc(*numberOfElements);
47
      strcpy(*buffer, env);
48
   }
49
   return 0;
50
}
51
 
52
static inline void _splitpath(char *path, char *drive, char *dir, char *name, char *ext) {
53
   char *base = basename(path);
54
   char *dot = rindex(base, '.');
55
   if (drive) {
56
      *drive = '\0';
57
   }
58
   if (dir) {
59
      strcpy(dir, dirname(path));
60
   }
61
   if (base) {
62
      strcpy(name, base);
63
      if (dot) {
64
         *(name + (dot - base)) = '\0';
65
      }
66
   }
67
   if (ext) {
68
      if (dot) {
69
         strcpy(ext, dot + 1);
70
      } else {
71
         *ext = '\0';
72
      }
73
   }
74
}
75
 
76
static inline int _splitpath_s(
77
   char * path,
78
   char * drive, size_t driveNumberOfElements,
79
   char * dir, size_t dirNumberOfElements,
80
   char * name, size_t nameNumberOfElements,
81
   char * ext, size_t extNumberOfElements
82
   ) {
83
   _splitpath(path, drive, dir, name, ext);
84
   // TODO: Add error handling
85
   return 0;
86
}
87
 
88
static inline void ZeroMemory (void *dst, size_t length) {
89
   memset(dst, 0, length);
90
}
91
 
92
static inline unsigned int _rotl(
93
   unsigned int value,
94
   int shift
95
   ) {
96
   return (value << shift) | (value >> (32 - shift));
97
}
98
 
99
static inline unsigned int _rotr(
100
   unsigned int value,
101
   int shift
102
   ) {
103
   return (value >> shift) | (value << (32 - shift));
104
}
105
 
106
static inline char *strtok_s(
107
   char *strToken,
108
   const char *strDelimit,
109
   char **context
110
   ) {
111
}
112
 
113
static inline int strncpy_s(
114
   char *strDestination,
115
   size_t numberOfElements,
116
   const char *strSource,
117
   size_t count
118
   ) {
119
   strncpy(strDestination, strSource, count);
120
   return 0;
121
 
122
}
123
 
124
static inline int strcpy_s(
125
   char *strDestination,
126
   size_t numberOfElements,
127
   const char *strSource
128
   ) {
129
   // TODO: Add error handling
130
   strncpy(strDestination, strSource, numberOfElements);
131
   return 0;
132
}
133
 
134
static inline int strcat_s(
135
   char *strDestination,
136
   size_t numberOfElements,
137
   const char *strSource
138
   ) {
139
   // TODO: Add error handling
140
   strncat(strDestination, strSource, numberOfElements);
141
   return 0;
142
}
143
 
144
static inline int sprintf_s(char* buffer, size_t sizeOfBuffer, const char* format, ...)
145
{
146
    va_list ap;
147
    va_start(ap, format);
148
    int result = vsnprintf(buffer, sizeOfBuffer, format, ap);
149
    va_end(ap);
150
    return result;
151
}
152
 
153
#endif
154
 
155
#endif
156
 

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.