Make the sim buildable with mingw again
[kugel-rb.git] / apps / plugins / lua / rockaux.c
blob1f832d4cc774153d597675c36de48df1cf426bea
1 /***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
10 * Copyright (C) 2008 Dan Everton (safetydan)
11 * String function implementations taken from dietlibc 0.31 (GPLv2 License)
13 * This program is free software; you can redistribute it and/or
14 * modify it under the terms of the GNU General Public License
15 * as published by the Free Software Foundation; either version 2
16 * of the License, or (at your option) any later version.
18 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
19 * KIND, either express or implied.
21 ****************************************************************************/
23 #include "plugin.h"
24 #define _ROCKCONF_H_ /* Protect against unwanted include */
25 #include "lua.h"
27 #if !defined(SIMULATOR)
28 int errno = 0;
29 #endif
31 char *strerror(int errnum)
33 (void) errnum;
35 DEBUGF("strerror(%d)\n", errnum);
37 return NULL;
40 long rb_pow(long x, long n)
42 long pow = 1;
43 unsigned long u;
45 if(n <= 0)
47 if(n == 0 || x == 1)
48 return 1;
50 if(x != -1)
51 return x != 0 ? 1/x : 0;
53 n = -n;
56 u = n;
57 while(1)
59 if(u & 01)
60 pow *= x;
62 if(u >>= 1)
63 x *= x;
64 else
65 break;
68 return pow;
71 int strcoll(const char * str1, const char * str2)
73 return rb->strcmp(str1, str2);
76 const char* get_current_path(lua_State *L, int level)
78 static char buffer[MAX_PATH];
79 lua_Debug ar;
81 if(lua_getstack(L, level, &ar))
83 /* Try determining the base path of the current Lua chunk
84 and write it to dest. */
85 lua_getinfo(L, "S", &ar);
87 char* curfile = (char*) &ar.source[1];
88 char* pos = rb->strrchr(curfile, '/');
89 if(pos != NULL)
91 unsigned int len = (unsigned int)(pos - curfile);
92 len = len + 1 > sizeof(buffer) ? sizeof(buffer) - 1 : len;
94 if(len > 0)
95 memcpy(buffer, curfile, len);
97 buffer[len] = '/';
98 buffer[len+1] = '\0';
100 return buffer;
104 return NULL;