1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247
|
/* OpenCP Module Player
* copyright (c) '94-'10 Niklas Beisert <nbeisert@physik.tu-muenchen.de>
*
* Some functions not present in POSIX that is needed
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*
* revision history: (please note changes here)
* -ss040614 Stian Skjelstad <stian@nixia.no>
* -first release
* -ss040709 Stian Skjelstad <stian@nixia.no>
* -added dos_clock since the linux one returnes cpu_time
* -ss040816 Stian Skjelstad <stian@nixia.no>
* -started on nasty hack to implement .tar.* files better
*/
#include "config.h"
#include <ctype.h>
#include <string.h>
#include <sys/stat.h>
#include <sys/time.h>
#include <sys/types.h>
#include <unistd.h>
#include "types.h"
#include "boot/plinkman.h"
#include "compat.h"
int memicmp(const void *_s1, const void *_s2, size_t n)
{
const uint8_t *s1=_s1;
const uint8_t *s2=_s2;
size_t i;
for (i=0;i<n;i++,s1++,s2++)
{
unsigned char u1=toupper(*s1);
unsigned char u2=toupper(*s2);
if (u1<u2) return -1;
if (u2<u1) return 1;
}
return 0;
}
time_t dos_clock(void)
{
struct timeval t;
gettimeofday(&t, NULL);
return t.tv_sec*0x10000+t.tv_usec*1024/15625;
}
void _splitpath(const char *src, char *drive, char *path, char *file, char *ext)
/* , NAME_MAX+1, PATH_MAX+1, NAME_MAX+1, NAME_MAX+1
drive : /path/ name.egon .tar.gz */
{
int len=0;
const char *ref1;
if (*src!='/')
if ((ref1=strchr(src, ':')))
{
if (((ref1+1)==strchr(src, '/'))||(!ref1[1]))
while (src<=ref1)
{
if (drive)
{
len++;
if (len<=NAME_MAX)
{
*drive=*src;
drive++;
}
}
if (*src==':')
{
src++;
break;
}
src++;
}
}
len=0;
if ((ref1=rindex(src, '/')))
while (src<=ref1)
{
if (path)
{
len++;
if (len<=PATH_MAX)
{
*path=*src;
path++;
}
}
src++;
}
len=0;
if (!(ref1=rindex(src, '.')))
ref1=src+strlen(src);
while (/*(*src)*/(src<ref1))
{
/*
if (!strchr(src+1, '.'))
break;
*/
if (!strcasecmp(src, ".tar.gz")) /* I am a bad boy */
break;
if (!strcasecmp(src, ".tar.bz2")) /* very bad */
break;
if (!strcasecmp(src, ".tar.Z")) /* and this is creepy */
break;
if (file)
{
len++;
if (len<=NAME_MAX)
{
*file=*src;
file++;
}
}
src++;
}
len=0;
while (*src)
{
if (ext)
{
len++;
if (len<=NAME_MAX)
{
*ext=*src;
ext++;
}
}
src++;
}
if (drive)
*drive=0;
if (path)
*path=0;
if (file)
*file=0;
if (ext)
*ext=0;
}
void _makepath(char *dst, const char *drive, const char *path, const char *file, const char *ext)
{
unsigned int left=PATH_MAX;
unsigned int cache;
*dst=0;
if (drive)
{
cache=strlen(drive);
if (cache<=left)
{
strcat(dst, drive);
left-=cache;
}
}
if (path)
{
cache=strlen(path);
if (cache<=left)
{
strcat(dst, path);
left-=cache;
if (left)
if (dst[PATH_MAX-left-1]!='/')
{
strcat(dst, "/");
left--;
}
}
}
if (file)
{
cache=strlen(file);
if (cache<=left)
{
strcat(dst, file);
left-=cache;
}
}
if (ext)
if (strlen(ext)<=left)
strcat(dst, ext);
}
#ifndef HAVE_STRUPR
char *strupr(char *src)
{
char *retval = src;
while (*src)
{
*src=toupper(*src);
src++;
}
return retval;
}
#endif
size_t filelength(int fd)
{
off_t cur=lseek(fd, 0, SEEK_CUR);
size_t retval;
lseek(fd, 0, SEEK_END);
retval=lseek(fd, 0, SEEK_CUR);
lseek(fd, cur, SEEK_SET);
return retval;
}
size_t _filelength(const char *path)
{
struct stat st;
if (stat(path, &st))
return 0;
return st.st_size;
}
#ifndef HAVE_MEMMEM
void *memmem(const void *haystack, size_t haystacklen,
const void *needle, size_t needlelen)
{
while (haystacklen>=needlelen)
{
if (!memcmp(haystack, needle, needlelen))
return (void *)haystack;
haystack++;
haystacklen--;
}
return NULL;
}
#endif
DLLEXTINFO_PREFIX struct linkinfostruct dllextinfo = {"compat", "OpenCP DOS compatible function-wrappers (c) 2004-09 Stian Skjelstad", DLLVERSION, 0 LINKINFOSTRUCT_NOEVENTS};
|