mirror of
https://github.com/TES3MP/openmw-tes3mp.git
synced 2025-06-28 09:21:35 +00:00
DIE TABS, DIE!!!!!!!1
This commit is contained in:
parent
9abd4e5a16
commit
64b5638d40
14 changed files with 630 additions and 617 deletions
|
@ -14,10 +14,10 @@ using namespace std;
|
|||
#ifdef _WIN32
|
||||
int setenv(const char *name, const char *value, int overwrite)
|
||||
{
|
||||
std::unique_ptr<char> tmp(new char[strlen(name) + strlen(value) + 1]);
|
||||
sprintf(tmp.get(), "%s=%s", name, value);
|
||||
std::unique_ptr<char> tmp(new char[strlen(name) + strlen(value) + 1]);
|
||||
sprintf(tmp.get(), "%s=%s", name, value);
|
||||
|
||||
printf("%s\n",tmp.get());
|
||||
printf("%s\n",tmp.get());
|
||||
|
||||
return putenv((const char*)tmp.get());
|
||||
}
|
||||
|
@ -35,7 +35,7 @@ std::string Utils::convertPath(std::string str)
|
|||
#if defined(_WIN32) || defined(__APPLE__)
|
||||
for (auto &ch : str)
|
||||
if (ch == '/')
|
||||
ch = _SEP_;
|
||||
ch = _SEP_;
|
||||
#endif //defined(_WIN32) || defined(__APPLE__)
|
||||
return str;
|
||||
|
||||
|
@ -150,7 +150,7 @@ long int Utils::FileLength(const char* file)
|
|||
*/
|
||||
|
||||
#define UPDC32(octet,crc) (crc_32_tab[((crc)\
|
||||
^ ((unsigned char)octet)) & 0xff] ^ ((crc) >> 8))
|
||||
^ ((unsigned char)octet)) & 0xff] ^ ((crc) >> 8))
|
||||
|
||||
static unsigned int crc_32_tab[] = /* CRC polynomial 0xedb88320 */
|
||||
{
|
||||
|
|
|
@ -558,7 +558,7 @@ int AMXAPI amx_Callback(AMX *amx, cell index, cell *result, const cell *params)
|
|||
* behind the SYSREQ(.N) instruction and its parameter(s)
|
||||
*/
|
||||
unsigned char *code=amx->code+(int)amx->cip-sizeof(cell);
|
||||
if (amx->flags & AMX_FLAG_SYSREQN) /* SYSREQ.N has 2 parameters */
|
||||
if (amx->flags & AMX_FLAG_SYSREQN) /* SYSREQ.N has 2 parameters */
|
||||
code-=sizeof(cell);
|
||||
assert(amx->code!=NULL);
|
||||
assert(amx->cip>=4 && amx->cip<(hdr->dat - hdr->cod));
|
||||
|
|
|
@ -69,7 +69,7 @@
|
|||
typedef unsigned long int uint32_t;
|
||||
#endif
|
||||
#if defined __WIN32__ || defined _WIN32 || defined WIN32
|
||||
typedef __int64 int64_t;
|
||||
typedef __int64 int64_t;
|
||||
typedef unsigned __int64 uint64_t;
|
||||
#define HAVE_I64
|
||||
#endif
|
||||
|
|
|
@ -531,9 +531,9 @@
|
|||
void CreateConsole(void)
|
||||
{ static int createdconsole=0;
|
||||
if (!createdconsole) {
|
||||
AllocConsole();
|
||||
createdconsole=1;
|
||||
} /* if */
|
||||
AllocConsole();
|
||||
createdconsole=1;
|
||||
} /* if */
|
||||
}
|
||||
#elif defined CURSES && CURSES != 0
|
||||
// The Mac OS X build variant uses curses.
|
||||
|
@ -577,19 +577,19 @@ enum {
|
|||
|
||||
static TCHAR *reverse(TCHAR *string,int stop)
|
||||
{
|
||||
int start=0;
|
||||
TCHAR temp;
|
||||
int start=0;
|
||||
TCHAR temp;
|
||||
|
||||
/* swap the string */
|
||||
stop--; /* avoid swapping the '\0' byte to the first position */
|
||||
while (stop - start > 0) {
|
||||
temp = string[start];
|
||||
string[start] = string[stop];
|
||||
string[stop] = temp;
|
||||
start++;
|
||||
stop--;
|
||||
} /* while */
|
||||
return string;
|
||||
/* swap the string */
|
||||
stop--; /* avoid swapping the '\0' byte to the first position */
|
||||
while (stop - start > 0) {
|
||||
temp = string[start];
|
||||
string[start] = string[stop];
|
||||
string[stop] = temp;
|
||||
start++;
|
||||
stop--;
|
||||
} /* while */
|
||||
return string;
|
||||
}
|
||||
|
||||
/* Converts an integral value to a string, with optional padding with spaces or
|
||||
|
@ -602,48 +602,48 @@ static TCHAR *reverse(TCHAR *string,int stop)
|
|||
*/
|
||||
static TCHAR *amx_strval(TCHAR buffer[], long value, int format, int width)
|
||||
{
|
||||
int start, stop;
|
||||
TCHAR temp;
|
||||
int start, stop;
|
||||
TCHAR temp;
|
||||
|
||||
start = stop = 0;
|
||||
if (format == SV_DECIMAL) {
|
||||
if (value < 0) {
|
||||
buffer[0] = __T('-');
|
||||
start = stop = 1;
|
||||
value = -value;
|
||||
} /* if */
|
||||
do {
|
||||
buffer[stop++] = (TCHAR)((value % 10) + __T('0'));
|
||||
value /= 10;
|
||||
} while (value > 0);
|
||||
} else {
|
||||
/* hexadecimal */
|
||||
unsigned long v = (unsigned long)value; /* copy to unsigned value for shifting */
|
||||
do {
|
||||
buffer[stop] = (TCHAR)((v & 0x0f) + __T('0'));
|
||||
if (buffer[stop] > __T('9'))
|
||||
buffer[stop] += (TCHAR)(__T('A') - __T('0') - 10);
|
||||
v >>= 4;
|
||||
stop++;
|
||||
} while (v != 0);
|
||||
} /* if */
|
||||
start = stop = 0;
|
||||
if (format == SV_DECIMAL) {
|
||||
if (value < 0) {
|
||||
buffer[0] = __T('-');
|
||||
start = stop = 1;
|
||||
value = -value;
|
||||
} /* if */
|
||||
do {
|
||||
buffer[stop++] = (TCHAR)((value % 10) + __T('0'));
|
||||
value /= 10;
|
||||
} while (value > 0);
|
||||
} else {
|
||||
/* hexadecimal */
|
||||
unsigned long v = (unsigned long)value; /* copy to unsigned value for shifting */
|
||||
do {
|
||||
buffer[stop] = (TCHAR)((v & 0x0f) + __T('0'));
|
||||
if (buffer[stop] > __T('9'))
|
||||
buffer[stop] += (TCHAR)(__T('A') - __T('0') - 10);
|
||||
v >>= 4;
|
||||
stop++;
|
||||
} while (v != 0);
|
||||
} /* if */
|
||||
|
||||
/* pad to given width */
|
||||
if (width < 0) {
|
||||
temp = __T('0');
|
||||
width = -width;
|
||||
} else {
|
||||
temp = __T(' ');
|
||||
} /* if */
|
||||
while (stop < width)
|
||||
buffer[stop++] = temp;
|
||||
/* pad to given width */
|
||||
if (width < 0) {
|
||||
temp = __T('0');
|
||||
width = -width;
|
||||
} else {
|
||||
temp = __T(' ');
|
||||
} /* if */
|
||||
while (stop < width)
|
||||
buffer[stop++] = temp;
|
||||
|
||||
buffer[stop] = __T('\0');
|
||||
buffer[stop] = __T('\0');
|
||||
|
||||
/* swap the string, and we are done */
|
||||
reverse(buffer+start,stop-start);
|
||||
return buffer;
|
||||
}
|
||||
/* swap the string, and we are done */
|
||||
reverse(buffer+start,stop-start);
|
||||
return buffer;
|
||||
}
|
||||
|
||||
#if defined FIXEDPOINT
|
||||
#define FIXEDMULT 1000
|
||||
|
@ -996,8 +996,8 @@ int amx_printstring(AMX *amx,cell *cstr,AMX_FMTINFO *info)
|
|||
} else {
|
||||
/* unpacked string */
|
||||
for (i=0; cstr[i]!=0; i++) {
|
||||
if (skip-->0)
|
||||
continue;
|
||||
if (skip-->0)
|
||||
continue;
|
||||
assert(idx<sizeof cache);
|
||||
cache[idx++]=(TCHAR)cstr[i];
|
||||
if (idx==sizeof cache - 1) {
|
||||
|
@ -1144,7 +1144,7 @@ static cell AMX_NATIVE_CALL n_getchar(AMX *amx,const cell *params)
|
|||
c=amx_getch();
|
||||
if (params[1]) {
|
||||
#if defined(SUPPRESS_ECHO)
|
||||
/* For Mac OS X, non-Curses, don't echo the character */
|
||||
/* For Mac OS X, non-Curses, don't echo the character */
|
||||
#else
|
||||
amx_putchar((TCHAR)c);
|
||||
amx_fflush();
|
||||
|
@ -1176,7 +1176,7 @@ static cell AMX_NATIVE_CALL n_getstring(AMX *amx,const cell *params)
|
|||
while (c!=EOF && c!=EOL_CHAR && chars<max-1) {
|
||||
str[chars++]=(TCHAR)c;
|
||||
#if defined(SUPPRESS_ECHO)
|
||||
/* For Mac OS X, non-Curses, don't echo the character */
|
||||
/* For Mac OS X, non-Curses, don't echo the character */
|
||||
#else
|
||||
amx_putchar((TCHAR)c);
|
||||
amx_fflush();
|
||||
|
@ -1216,7 +1216,7 @@ static void acceptchar(int c,int *num)
|
|||
break;
|
||||
default:
|
||||
#if defined(SUPPRESS_ECHO)
|
||||
/* For Mac OS X, non-Curses, don't echo the character */
|
||||
/* For Mac OS X, non-Curses, don't echo the character */
|
||||
#else
|
||||
amx_putchar((TCHAR)c);
|
||||
#endif
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
#ifndef AMXCONS_H_INCLUDED
|
||||
#ifndef AMXCONS_H_INCLUDED
|
||||
#define AMXCONS_H_INCLUDED
|
||||
|
||||
typedef struct tagFMTINFO {
|
||||
|
|
|
@ -218,8 +218,8 @@ void amx_swapcell(cell *pc)
|
|||
uchar b[4];
|
||||
#elif PAWN_CELL_SIZE==64
|
||||
uchar b[8];
|
||||
#else
|
||||
#error Unsupported cell size
|
||||
#else
|
||||
#error Unsupported cell size
|
||||
#endif
|
||||
} value;
|
||||
uchar t;
|
||||
|
@ -241,13 +241,13 @@ void amx_swapcell(cell *pc)
|
|||
t = value.b[0];
|
||||
value.b[0] = value.b[7];
|
||||
value.b[7] = t;
|
||||
t = value.b[1];
|
||||
value.b[1] = value.b[6];
|
||||
value.b[6] = t;
|
||||
t = value.b[2];
|
||||
value.b[2] = value.b[5];
|
||||
value.b[5] = t;
|
||||
t = value.b[3];
|
||||
t = value.b[1];
|
||||
value.b[1] = value.b[6];
|
||||
value.b[6] = t;
|
||||
t = value.b[2];
|
||||
value.b[2] = value.b[5];
|
||||
value.b[5] = t;
|
||||
t = value.b[3];
|
||||
value.b[3] = value.b[4];
|
||||
value.b[4] = t;
|
||||
#else
|
||||
|
|
|
@ -26,10 +26,10 @@
|
|||
|
||||
#define CELLMIN (-1 << (8*sizeof(cell) - 1))
|
||||
|
||||
#define SECONDS_PER_MINUTE 60
|
||||
#define SECONDS_PER_HOUR 3600
|
||||
#define SECONDS_PER_DAY 86400
|
||||
#define SECONDS_PER_YEAR 31556952 /* based on 365.2425 days per year */
|
||||
#define SECONDS_PER_MINUTE 60
|
||||
#define SECONDS_PER_HOUR 3600
|
||||
#define SECONDS_PER_DAY 86400
|
||||
#define SECONDS_PER_YEAR 31556952 /* based on 365.2425 days per year */
|
||||
|
||||
#if !defined CLOCKS_PER_SEC
|
||||
#define CLOCKS_PER_SEC CLK_TCK
|
||||
|
@ -310,9 +310,9 @@ static cell AMX_NATIVE_CALL n_tickcount(AMX *amx, const cell *params)
|
|||
INIT_TIMER();
|
||||
cptr=amx_Address(amx,params[1]);
|
||||
#if defined __WIN32__ || defined _WIN32 || defined WIN32
|
||||
*cptr=1000; /* granularity = 1 ms */
|
||||
*cptr=1000; /* granularity = 1 ms */
|
||||
#else
|
||||
*cptr=(cell)CLOCKS_PER_SEC; /* in Unix/Linux, this is often 100 */
|
||||
*cptr=(cell)CLOCKS_PER_SEC; /* in Unix/Linux, this is often 100 */
|
||||
#endif
|
||||
return gettimestamp() & 0x7fffffff;
|
||||
}
|
||||
|
|
|
@ -64,9 +64,9 @@
|
|||
|
||||
/* System includes */
|
||||
#if defined TEST
|
||||
#include <assert.h>
|
||||
#include <assert.h>
|
||||
#elif !defined assert
|
||||
#define assert(e)
|
||||
#define assert(e)
|
||||
#endif
|
||||
#include <string.h>
|
||||
|
||||
|
@ -1151,8 +1151,8 @@ int main(int argc, char **argv)
|
|||
test(1, "a`x", "a``x");
|
||||
test(1, "*`?", "`*```?");
|
||||
test(1, "a*x", "a`*x");
|
||||
test(1, "a€", "a`80");
|
||||
test(0, "a€", "a`8");
|
||||
test(1, "a<EFBFBD>", "a`80");
|
||||
test(0, "a<EFBFBD>", "a`8");
|
||||
|
||||
#if defined FPAT_DELIM
|
||||
test(0, "", "/");
|
||||
|
|
|
@ -1,138 +1,138 @@
|
|||
/******************************************************************************
|
||||
* fpattern.h
|
||||
* Functions for matching filename patterns to filenames.
|
||||
* Functions for matching filename patterns to filenames.
|
||||
*
|
||||
* Usage
|
||||
* Filename patterns are composed of regular (printable) characters which
|
||||
* may comprise a filename as well as special pattern matching characters:
|
||||
* Filename patterns are composed of regular (printable) characters which
|
||||
* may comprise a filename as well as special pattern matching characters:
|
||||
*
|
||||
* . Matches a period (.).
|
||||
* Note that a period in a filename is not treated any
|
||||
* differently than any other character.
|
||||
* . Matches a period (.).
|
||||
* Note that a period in a filename is not treated any
|
||||
* differently than any other character.
|
||||
*
|
||||
* ? Any.
|
||||
* Matches any single character except '/' or '\'.
|
||||
* ? Any.
|
||||
* Matches any single character except '/' or '\'.
|
||||
*
|
||||
* * Closure.
|
||||
* Matches zero or more occurences of any characters other
|
||||
* than '/' or '\'.
|
||||
* Leading '*' characters are allowed.
|
||||
* * Closure.
|
||||
* Matches zero or more occurences of any characters other
|
||||
* than '/' or '\'.
|
||||
* Leading '*' characters are allowed.
|
||||
*
|
||||
* SUB Substitute (^Z); optionally supported.
|
||||
* Similar to '*', this matches zero or more occurences of
|
||||
* any characters other than '/', '\', or '.'.
|
||||
* Leading '^Z' characters are allowed.
|
||||
* SUB Substitute (^Z); optionally supported.
|
||||
* Similar to '*', this matches zero or more occurences of
|
||||
* any characters other than '/', '\', or '.'.
|
||||
* Leading '^Z' characters are allowed.
|
||||
*
|
||||
* [ab] Set.
|
||||
* Matches the single character 'a' or 'b'.
|
||||
* If the dash '-' character is to be included, it must
|
||||
* immediately follow the opening bracket '['.
|
||||
* If the closing bracket ']' character is to be included,
|
||||
* it must be preceded by a quote '`'.
|
||||
* [ab] Set.
|
||||
* Matches the single character 'a' or 'b'.
|
||||
* If the dash '-' character is to be included, it must
|
||||
* immediately follow the opening bracket '['.
|
||||
* If the closing bracket ']' character is to be included,
|
||||
* it must be preceded by a quote '`'.
|
||||
*
|
||||
* [a-z] Range.
|
||||
* Matches a single character in the range 'a' to 'z'.
|
||||
* Ranges and sets may be combined within the same set of
|
||||
* brackets.
|
||||
* [a-z] Range.
|
||||
* Matches a single character in the range 'a' to 'z'.
|
||||
* Ranges and sets may be combined within the same set of
|
||||
* brackets.
|
||||
*
|
||||
* [!R] Exclusive range.
|
||||
* Matches a single character not in the range 'R'.
|
||||
* If range 'R' includes the dash '-' character, the dash
|
||||
* must immediately follow the caret '!'.
|
||||
* [!R] Exclusive range.
|
||||
* Matches a single character not in the range 'R'.
|
||||
* If range 'R' includes the dash '-' character, the dash
|
||||
* must immediately follow the caret '!'.
|
||||
*
|
||||
* ! Not; optionally supported.
|
||||
* Makes the following pattern (up to the next '/') match
|
||||
* any filename except those what it would normally match.
|
||||
* ! Not; optionally supported.
|
||||
* Makes the following pattern (up to the next '/') match
|
||||
* any filename except those what it would normally match.
|
||||
*
|
||||
* / Path separator (UNIX and DOS).
|
||||
* Matches a '/' or '\' pathname (directory) separator.
|
||||
* Multiple separators are treated like a single
|
||||
* separator.
|
||||
* A leading separator indicates an absolute pathname.
|
||||
* / Path separator (UNIX and DOS).
|
||||
* Matches a '/' or '\' pathname (directory) separator.
|
||||
* Multiple separators are treated like a single
|
||||
* separator.
|
||||
* A leading separator indicates an absolute pathname.
|
||||
*
|
||||
* \ Path separator (DOS).
|
||||
* Same as the '/' character.
|
||||
* Note that this character must be escaped if used within
|
||||
* string constants ("\\").
|
||||
* \ Path separator (DOS).
|
||||
* Same as the '/' character.
|
||||
* Note that this character must be escaped if used within
|
||||
* string constants ("\\").
|
||||
*
|
||||
* \ Quote (UNIX).
|
||||
* Makes the next character a regular (nonspecial)
|
||||
* character.
|
||||
* Note that to match the quote character itself, it must
|
||||
* be quoted.
|
||||
* Note that this character must be escaped if used within
|
||||
* string constants ("\\").
|
||||
* \ Quote (UNIX).
|
||||
* Makes the next character a regular (nonspecial)
|
||||
* character.
|
||||
* Note that to match the quote character itself, it must
|
||||
* be quoted.
|
||||
* Note that this character must be escaped if used within
|
||||
* string constants ("\\").
|
||||
*
|
||||
* ` Quote (DOS).
|
||||
* Makes the next character a regular (nonspecial)
|
||||
* character.
|
||||
* Note that to match the quote character itself, it must
|
||||
* be quoted.
|
||||
* ` Quote (DOS).
|
||||
* Makes the next character a regular (nonspecial)
|
||||
* character.
|
||||
* Note that to match the quote character itself, it must
|
||||
* be quoted.
|
||||
*
|
||||
* Upper and lower case alphabetic characters are considered identical,
|
||||
* i.e., 'a' and 'A' match each other.
|
||||
* (What constitutes a lowercase letter depends on the current locale
|
||||
* settings.)
|
||||
* Upper and lower case alphabetic characters are considered identical,
|
||||
* i.e., 'a' and 'A' match each other.
|
||||
* (What constitutes a lowercase letter depends on the current locale
|
||||
* settings.)
|
||||
*
|
||||
* Spaces and control characters are treated as normal characters.
|
||||
* Spaces and control characters are treated as normal characters.
|
||||
*
|
||||
* Examples
|
||||
* The following patterns in the left column will match the filenames in
|
||||
* the middle column and will not match filenames in the right column:
|
||||
* The following patterns in the left column will match the filenames in
|
||||
* the middle column and will not match filenames in the right column:
|
||||
*
|
||||
* Pattern Will Match Will Not Match
|
||||
* ------- ---------- --------------
|
||||
* a a (only) (anything else)
|
||||
* a. a. (only) (anything else)
|
||||
* a?c abc, acc, arc, a.c a, ac, abbc
|
||||
* a*c ac, abc, abbc, acc, a.c a, ab, acb, bac
|
||||
* a* a, ab, abb, a., a.b b, ba
|
||||
* * a, ab, abb, a., .foo, a.foo (nothing)
|
||||
* *. a., ab., abb., a.foo. a, ab, a.foo, .foo
|
||||
* *.* a., a.b, ah.bc.foo a
|
||||
* ^Z a, ab, abb a., .foo, a.foo
|
||||
* ^Z. a., ab., abb. a, .foo, a.foo
|
||||
* ^Z.* a, a., .foo, a.foo ab, abb
|
||||
* *2.c 2.c, 12.c, foo2.c, foo.12.c 2x.c
|
||||
* a[b-z]c abc, acc, azc (only) (anything else)
|
||||
* [ab0-9]x ax, bx, 0x, 9x zx
|
||||
* a[-.]b a-b, a.b (only) (anything else)
|
||||
* a[!a-z]b a0b, a.b, a@b aab, azb, aa0b
|
||||
* a[!-b]x a0x, a+x, acx a-x, abx, axxx
|
||||
* a[-!b]x a-x, a!x, abx (only) (anything else)
|
||||
* a[`]]x a]x (only) (anything else)
|
||||
* a``x a`x (only) (anything else)
|
||||
* oh`! oh! (only) (anything else)
|
||||
* is`?it is?it (only) (anything else)
|
||||
* !a?c a, ac, ab, abb, acb, a.foo abc, a.c, azc
|
||||
* Pattern Will Match Will Not Match
|
||||
* ------- ---------- --------------
|
||||
* a a (only) (anything else)
|
||||
* a. a. (only) (anything else)
|
||||
* a?c abc, acc, arc, a.c a, ac, abbc
|
||||
* a*c ac, abc, abbc, acc, a.c a, ab, acb, bac
|
||||
* a* a, ab, abb, a., a.b b, ba
|
||||
* * a, ab, abb, a., .foo, a.foo (nothing)
|
||||
* *. a., ab., abb., a.foo. a, ab, a.foo, .foo
|
||||
* *.* a., a.b, ah.bc.foo a
|
||||
* ^Z a, ab, abb a., .foo, a.foo
|
||||
* ^Z. a., ab., abb. a, .foo, a.foo
|
||||
* ^Z.* a, a., .foo, a.foo ab, abb
|
||||
* *2.c 2.c, 12.c, foo2.c, foo.12.c 2x.c
|
||||
* a[b-z]c abc, acc, azc (only) (anything else)
|
||||
* [ab0-9]x ax, bx, 0x, 9x zx
|
||||
* a[-.]b a-b, a.b (only) (anything else)
|
||||
* a[!a-z]b a0b, a.b, a@b aab, azb, aa0b
|
||||
* a[!-b]x a0x, a+x, acx a-x, abx, axxx
|
||||
* a[-!b]x a-x, a!x, abx (only) (anything else)
|
||||
* a[`]]x a]x (only) (anything else)
|
||||
* a``x a`x (only) (anything else)
|
||||
* oh`! oh! (only) (anything else)
|
||||
* is`?it is?it (only) (anything else)
|
||||
* !a?c a, ac, ab, abb, acb, a.foo abc, a.c, azc
|
||||
*
|
||||
* History
|
||||
* 1.00 1997-01-03 David Tribble.
|
||||
* First cut.
|
||||
* 1.01 1997-01-03 David Tribble.
|
||||
* Added '^Z' pattern character.
|
||||
* Added fpattern_matchn().
|
||||
* 1.02 1997-01-26 David Tribble.
|
||||
* Changed range negation character from '^' to '!', ala Unix.
|
||||
* 1.03 1997-08-02 David Tribble.
|
||||
* Added 'FPAT_XXX' macro constants.
|
||||
* 1.00 1997-01-03 David Tribble.
|
||||
* First cut.
|
||||
* 1.01 1997-01-03 David Tribble.
|
||||
* Added '^Z' pattern character.
|
||||
* Added fpattern_matchn().
|
||||
* 1.02 1997-01-26 David Tribble.
|
||||
* Changed range negation character from '^' to '!', ala Unix.
|
||||
* 1.03 1997-08-02 David Tribble.
|
||||
* Added 'FPAT_XXX' macro constants.
|
||||
*
|
||||
* Limitations
|
||||
* This code is copyrighted by the author, but permission is hereby
|
||||
* granted for its unlimited use provided that the original copyright
|
||||
* and authorship notices are retained intact.
|
||||
* This code is copyrighted by the author, but permission is hereby
|
||||
* granted for its unlimited use provided that the original copyright
|
||||
* and authorship notices are retained intact.
|
||||
*
|
||||
* Other queries can be sent to:
|
||||
* dtribble@technologist.com
|
||||
* david.tribble@beasys.com
|
||||
* dtribble@flash.net
|
||||
* Other queries can be sent to:
|
||||
* dtribble@technologist.com
|
||||
* david.tribble@beasys.com
|
||||
* dtribble@flash.net
|
||||
*
|
||||
* Copyright ©1997 by David R. Tribble, all rights reserved.
|
||||
* Copyright <EFBFBD>1997 by David R. Tribble, all rights reserved.
|
||||
*/
|
||||
|
||||
|
||||
#ifndef fpattern_h
|
||||
#define fpattern_h 1
|
||||
#define fpattern_h 1
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
|
@ -150,32 +150,32 @@ extern "C"
|
|||
|
||||
/* Manifest constants */
|
||||
|
||||
#define FPAT_QUOTE '`' /* Quotes a special char */
|
||||
#define FPAT_DEL '/' /* Path delimiter (used only when FPAT_DELIM is true) */
|
||||
#define FPAT_DEL2 '\\' /* Path delimiter (used only when FPAT_DELIM is true) */
|
||||
#define FPAT_DOT '.' /* Dot char */
|
||||
#define FPAT_NOT '!' /* Exclusion (also used for sets) */
|
||||
#define FPAT_ANY '?' /* Any one char */
|
||||
#define FPAT_CLOS '*' /* Zero or more chars */
|
||||
#define FPAT_CLOSP '\x1A' /* Zero or more nondelimiters (used only when FPAT_SUBCLOS is true) */
|
||||
#define FPAT_SET_L '[' /* Set/range open bracket */
|
||||
#define FPAT_SET_R ']' /* Set/range close bracket */
|
||||
#define FPAT_MSET_L '{' /* Multi-set/range open bracket */
|
||||
#define FPAT_MSET_R '}' /* Multi-set/range close bracket*/
|
||||
#define FPAT_SET_THRU '-' /* Set range of chars */
|
||||
#define FPAT_QUOTE '`' /* Quotes a special char */
|
||||
#define FPAT_DEL '/' /* Path delimiter (used only when FPAT_DELIM is true) */
|
||||
#define FPAT_DEL2 '\\' /* Path delimiter (used only when FPAT_DELIM is true) */
|
||||
#define FPAT_DOT '.' /* Dot char */
|
||||
#define FPAT_NOT '!' /* Exclusion (also used for sets) */
|
||||
#define FPAT_ANY '?' /* Any one char */
|
||||
#define FPAT_CLOS '*' /* Zero or more chars */
|
||||
#define FPAT_CLOSP '\x1A' /* Zero or more nondelimiters (used only when FPAT_SUBCLOS is true) */
|
||||
#define FPAT_SET_L '[' /* Set/range open bracket */
|
||||
#define FPAT_SET_R ']' /* Set/range close bracket */
|
||||
#define FPAT_MSET_L '{' /* Multi-set/range open bracket */
|
||||
#define FPAT_MSET_R '}' /* Multi-set/range close bracket*/
|
||||
#define FPAT_SET_THRU '-' /* Set range of chars */
|
||||
|
||||
|
||||
#define FPAT_INVALID 0 /* invalid pattern */
|
||||
#define FPAT_CLOSED 1 /* valid pattern */
|
||||
#define FPAT_OPEN 2 /* valid pattern */
|
||||
#define FPAT_INVALID 0 /* invalid pattern */
|
||||
#define FPAT_CLOSED 1 /* valid pattern */
|
||||
#define FPAT_OPEN 2 /* valid pattern */
|
||||
|
||||
|
||||
/* Public functions */
|
||||
|
||||
extern int fpattern_isvalid(const char *pat);
|
||||
extern int fpattern_match(const char *pat, const char *fname, int flength, int keepcase);
|
||||
extern int fpattern_matchn(const char *pat, const char *fname, int flength, int keepcase);
|
||||
extern int fpattern_matchcount(const char *pat, const char *fname, int flength, int minlength, int keepcase);
|
||||
extern int fpattern_isvalid(const char *pat);
|
||||
extern int fpattern_match(const char *pat, const char *fname, int flength, int keepcase);
|
||||
extern int fpattern_matchn(const char *pat, const char *fname, int flength, int keepcase);
|
||||
extern int fpattern_matchcount(const char *pat, const char *fname, int flength, int minlength, int keepcase);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
|
|
@ -14,10 +14,11 @@
|
|||
#define __BINRELOC_C__
|
||||
|
||||
#ifdef ENABLE_BINRELOC
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#include <unistd.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#include <unistd.h>
|
||||
#endif /* ENABLE_BINRELOC */
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <limits.h>
|
||||
|
@ -29,143 +30,142 @@ extern "C" {
|
|||
#endif /* __cplusplus */
|
||||
|
||||
|
||||
|
||||
/** @internal
|
||||
* Find the canonical filename of the executable. Returns the filename
|
||||
* (which must be freed) or NULL on error. If the parameter 'error' is
|
||||
* not NULL, the error code will be stored there, if an error occured.
|
||||
*/
|
||||
static char *
|
||||
_br_find_exe (BrInitError *error)
|
||||
_br_find_exe(BrInitError *error)
|
||||
{
|
||||
#ifndef ENABLE_BINRELOC
|
||||
if (error)
|
||||
*error = BR_INIT_ERROR_DISABLED;
|
||||
return NULL;
|
||||
if (error)
|
||||
*error = BR_INIT_ERROR_DISABLED;
|
||||
return NULL;
|
||||
#else
|
||||
char *path, *path2, *line, *result;
|
||||
size_t buf_size;
|
||||
ssize_t size;
|
||||
struct stat stat_buf;
|
||||
FILE *f;
|
||||
char *path, *path2, *line, *result;
|
||||
size_t buf_size;
|
||||
ssize_t size;
|
||||
struct stat stat_buf;
|
||||
FILE *f;
|
||||
|
||||
/* Read from /proc/self/exe (symlink) */
|
||||
if (sizeof (path) > SSIZE_MAX)
|
||||
buf_size = SSIZE_MAX - 1;
|
||||
else
|
||||
buf_size = PATH_MAX - 1;
|
||||
path = (char *) malloc (buf_size);
|
||||
if (path == NULL) {
|
||||
/* Cannot allocate memory. */
|
||||
if (error)
|
||||
*error = BR_INIT_ERROR_NOMEM;
|
||||
return NULL;
|
||||
}
|
||||
path2 = (char *) malloc (buf_size);
|
||||
if (path2 == NULL) {
|
||||
/* Cannot allocate memory. */
|
||||
if (error)
|
||||
*error = BR_INIT_ERROR_NOMEM;
|
||||
free (path);
|
||||
return NULL;
|
||||
}
|
||||
/* Read from /proc/self/exe (symlink) */
|
||||
if (sizeof (path) > SSIZE_MAX)
|
||||
buf_size = SSIZE_MAX - 1;
|
||||
else
|
||||
buf_size = PATH_MAX - 1;
|
||||
path = (char *) malloc (buf_size);
|
||||
if (path == NULL) {
|
||||
/* Cannot allocate memory. */
|
||||
if (error)
|
||||
*error = BR_INIT_ERROR_NOMEM;
|
||||
return NULL;
|
||||
}
|
||||
path2 = (char *) malloc (buf_size);
|
||||
if (path2 == NULL) {
|
||||
/* Cannot allocate memory. */
|
||||
if (error)
|
||||
*error = BR_INIT_ERROR_NOMEM;
|
||||
free (path);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
strncpy (path2, "/proc/self/exe", buf_size - 1);
|
||||
strncpy (path2, "/proc/self/exe", buf_size - 1);
|
||||
|
||||
while (1) {
|
||||
int i;
|
||||
while (1) {
|
||||
int i;
|
||||
|
||||
size = readlink (path2, path, buf_size - 1);
|
||||
if (size == -1) {
|
||||
/* Error. */
|
||||
free (path2);
|
||||
break;
|
||||
}
|
||||
size = readlink (path2, path, buf_size - 1);
|
||||
if (size == -1) {
|
||||
/* Error. */
|
||||
free (path2);
|
||||
break;
|
||||
}
|
||||
|
||||
/* readlink() success. */
|
||||
path[size] = '\0';
|
||||
/* readlink() success. */
|
||||
path[size] = '\0';
|
||||
|
||||
/* Check whether the symlink's target is also a symlink.
|
||||
* We want to get the final target. */
|
||||
i = stat (path, &stat_buf);
|
||||
if (i == -1) {
|
||||
/* Error. */
|
||||
free (path2);
|
||||
break;
|
||||
}
|
||||
/* Check whether the symlink's target is also a symlink.
|
||||
* We want to get the final target. */
|
||||
i = stat (path, &stat_buf);
|
||||
if (i == -1) {
|
||||
/* Error. */
|
||||
free (path2);
|
||||
break;
|
||||
}
|
||||
|
||||
/* stat() success. */
|
||||
if (!S_ISLNK (stat_buf.st_mode)) {
|
||||
/* path is not a symlink. Done. */
|
||||
free (path2);
|
||||
return path;
|
||||
}
|
||||
/* stat() success. */
|
||||
if (!S_ISLNK (stat_buf.st_mode)) {
|
||||
/* path is not a symlink. Done. */
|
||||
free (path2);
|
||||
return path;
|
||||
}
|
||||
|
||||
/* path is a symlink. Continue loop and resolve this. */
|
||||
strncpy (path, path2, buf_size - 1);
|
||||
}
|
||||
/* path is a symlink. Continue loop and resolve this. */
|
||||
strncpy (path, path2, buf_size - 1);
|
||||
}
|
||||
|
||||
|
||||
/* readlink() or stat() failed; this can happen when the program is
|
||||
* running in Valgrind 2.2. Read from /proc/self/maps as fallback. */
|
||||
/* readlink() or stat() failed; this can happen when the program is
|
||||
* running in Valgrind 2.2. Read from /proc/self/maps as fallback. */
|
||||
|
||||
buf_size = PATH_MAX + 128;
|
||||
line = (char *) realloc (path, buf_size);
|
||||
if (line == NULL) {
|
||||
/* Cannot allocate memory. */
|
||||
free (path);
|
||||
if (error)
|
||||
*error = BR_INIT_ERROR_NOMEM;
|
||||
return NULL;
|
||||
}
|
||||
buf_size = PATH_MAX + 128;
|
||||
line = (char *) realloc (path, buf_size);
|
||||
if (line == NULL) {
|
||||
/* Cannot allocate memory. */
|
||||
free (path);
|
||||
if (error)
|
||||
*error = BR_INIT_ERROR_NOMEM;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
f = fopen ("/proc/self/maps", "r");
|
||||
if (f == NULL) {
|
||||
free (line);
|
||||
if (error)
|
||||
*error = BR_INIT_ERROR_OPEN_MAPS;
|
||||
return NULL;
|
||||
}
|
||||
f = fopen ("/proc/self/maps", "r");
|
||||
if (f == NULL) {
|
||||
free (line);
|
||||
if (error)
|
||||
*error = BR_INIT_ERROR_OPEN_MAPS;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/* The first entry should be the executable name. */
|
||||
result = fgets (line, (int) buf_size, f);
|
||||
if (result == NULL) {
|
||||
fclose (f);
|
||||
free (line);
|
||||
if (error)
|
||||
*error = BR_INIT_ERROR_READ_MAPS;
|
||||
return NULL;
|
||||
}
|
||||
/* The first entry should be the executable name. */
|
||||
result = fgets (line, (int) buf_size, f);
|
||||
if (result == NULL) {
|
||||
fclose (f);
|
||||
free (line);
|
||||
if (error)
|
||||
*error = BR_INIT_ERROR_READ_MAPS;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/* Get rid of newline character. */
|
||||
buf_size = strlen (line);
|
||||
if (buf_size <= 0) {
|
||||
/* Huh? An empty string? */
|
||||
fclose (f);
|
||||
free (line);
|
||||
if (error)
|
||||
*error = BR_INIT_ERROR_INVALID_MAPS;
|
||||
return NULL;
|
||||
}
|
||||
if (line[buf_size - 1] == 10)
|
||||
line[buf_size - 1] = 0;
|
||||
/* Get rid of newline character. */
|
||||
buf_size = strlen (line);
|
||||
if (buf_size <= 0) {
|
||||
/* Huh? An empty string? */
|
||||
fclose (f);
|
||||
free (line);
|
||||
if (error)
|
||||
*error = BR_INIT_ERROR_INVALID_MAPS;
|
||||
return NULL;
|
||||
}
|
||||
if (line[buf_size - 1] == 10)
|
||||
line[buf_size - 1] = 0;
|
||||
|
||||
/* Extract the filename; it is always an absolute path. */
|
||||
path = strchr (line, '/');
|
||||
/* Extract the filename; it is always an absolute path. */
|
||||
path = strchr (line, '/');
|
||||
|
||||
/* Sanity check. */
|
||||
if (strstr (line, " r-xp ") == NULL || path == NULL) {
|
||||
fclose (f);
|
||||
free (line);
|
||||
if (error)
|
||||
*error = BR_INIT_ERROR_INVALID_MAPS;
|
||||
return NULL;
|
||||
}
|
||||
/* Sanity check. */
|
||||
if (strstr (line, " r-xp ") == NULL || path == NULL) {
|
||||
fclose (f);
|
||||
free (line);
|
||||
if (error)
|
||||
*error = BR_INIT_ERROR_INVALID_MAPS;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
path = strdup (path);
|
||||
free (line);
|
||||
fclose (f);
|
||||
return path;
|
||||
path = strdup (path);
|
||||
free (line);
|
||||
fclose (f);
|
||||
return path;
|
||||
#endif /* ENABLE_BINRELOC */
|
||||
}
|
||||
|
||||
|
@ -175,112 +175,112 @@ _br_find_exe (BrInitError *error)
|
|||
* Returns a filename which must be freed, or NULL on error.
|
||||
*/
|
||||
static char *
|
||||
_br_find_exe_for_symbol (const void *symbol, BrInitError *error)
|
||||
_br_find_exe_for_symbol(const void *symbol, BrInitError *error)
|
||||
{
|
||||
#ifndef ENABLE_BINRELOC
|
||||
if (error)
|
||||
*error = BR_INIT_ERROR_DISABLED;
|
||||
return (char *) NULL;
|
||||
if (error)
|
||||
*error = BR_INIT_ERROR_DISABLED;
|
||||
return (char *) NULL;
|
||||
#else
|
||||
#define SIZE PATH_MAX + 100
|
||||
FILE *f;
|
||||
size_t address_string_len;
|
||||
char *address_string, line[SIZE], *found;
|
||||
#define SIZE PATH_MAX + 100
|
||||
FILE *f;
|
||||
size_t address_string_len;
|
||||
char *address_string, line[SIZE], *found;
|
||||
|
||||
if (symbol == NULL)
|
||||
return (char *) NULL;
|
||||
if (symbol == NULL)
|
||||
return (char *) NULL;
|
||||
|
||||
f = fopen ("/proc/self/maps", "r");
|
||||
if (f == NULL)
|
||||
return (char *) NULL;
|
||||
f = fopen ("/proc/self/maps", "r");
|
||||
if (f == NULL)
|
||||
return (char *) NULL;
|
||||
|
||||
address_string_len = 4;
|
||||
address_string = (char *) malloc (address_string_len);
|
||||
found = (char *) NULL;
|
||||
address_string_len = 4;
|
||||
address_string = (char *) malloc (address_string_len);
|
||||
found = (char *) NULL;
|
||||
|
||||
while (!feof (f)) {
|
||||
char *start_addr, *end_addr, *end_addr_end, *file;
|
||||
void *start_addr_p, *end_addr_p;
|
||||
size_t len;
|
||||
while (!feof (f)) {
|
||||
char *start_addr, *end_addr, *end_addr_end, *file;
|
||||
void *start_addr_p, *end_addr_p;
|
||||
size_t len;
|
||||
|
||||
if (fgets (line, SIZE, f) == NULL)
|
||||
break;
|
||||
if (fgets (line, SIZE, f) == NULL)
|
||||
break;
|
||||
|
||||
/* Sanity check. */
|
||||
if (strstr (line, " r-xp ") == NULL || strchr (line, '/') == NULL)
|
||||
continue;
|
||||
/* Sanity check. */
|
||||
if (strstr (line, " r-xp ") == NULL || strchr (line, '/') == NULL)
|
||||
continue;
|
||||
|
||||
/* Parse line. */
|
||||
start_addr = line;
|
||||
end_addr = strchr (line, '-');
|
||||
file = strchr (line, '/');
|
||||
/* Parse line. */
|
||||
start_addr = line;
|
||||
end_addr = strchr (line, '-');
|
||||
file = strchr (line, '/');
|
||||
|
||||
/* More sanity check. */
|
||||
if (!(file > end_addr && end_addr != NULL && end_addr[0] == '-'))
|
||||
continue;
|
||||
/* More sanity check. */
|
||||
if (!(file > end_addr && end_addr != NULL && end_addr[0] == '-'))
|
||||
continue;
|
||||
|
||||
end_addr[0] = '\0';
|
||||
end_addr++;
|
||||
end_addr_end = strchr (end_addr, ' ');
|
||||
if (end_addr_end == NULL)
|
||||
continue;
|
||||
end_addr[0] = '\0';
|
||||
end_addr++;
|
||||
end_addr_end = strchr (end_addr, ' ');
|
||||
if (end_addr_end == NULL)
|
||||
continue;
|
||||
|
||||
end_addr_end[0] = '\0';
|
||||
len = strlen (file);
|
||||
if (len == 0)
|
||||
continue;
|
||||
if (file[len - 1] == '\n')
|
||||
file[len - 1] = '\0';
|
||||
end_addr_end[0] = '\0';
|
||||
len = strlen (file);
|
||||
if (len == 0)
|
||||
continue;
|
||||
if (file[len - 1] == '\n')
|
||||
file[len - 1] = '\0';
|
||||
|
||||
/* Get rid of "(deleted)" from the filename. */
|
||||
len = strlen (file);
|
||||
if (len > 10 && strcmp (file + len - 10, " (deleted)") == 0)
|
||||
file[len - 10] = '\0';
|
||||
/* Get rid of "(deleted)" from the filename. */
|
||||
len = strlen (file);
|
||||
if (len > 10 && strcmp (file + len - 10, " (deleted)") == 0)
|
||||
file[len - 10] = '\0';
|
||||
|
||||
/* I don't know whether this can happen but better safe than sorry. */
|
||||
len = strlen (start_addr);
|
||||
if (len != strlen (end_addr))
|
||||
continue;
|
||||
/* I don't know whether this can happen but better safe than sorry. */
|
||||
len = strlen (start_addr);
|
||||
if (len != strlen (end_addr))
|
||||
continue;
|
||||
|
||||
|
||||
/* Transform the addresses into a string in the form of 0xdeadbeef,
|
||||
* then transform that into a pointer. */
|
||||
if (address_string_len < len + 3) {
|
||||
address_string_len = len + 3;
|
||||
address_string = (char *) realloc (address_string, address_string_len);
|
||||
}
|
||||
/* Transform the addresses into a string in the form of 0xdeadbeef,
|
||||
* then transform that into a pointer. */
|
||||
if (address_string_len < len + 3) {
|
||||
address_string_len = len + 3;
|
||||
address_string = (char *) realloc (address_string, address_string_len);
|
||||
}
|
||||
|
||||
memcpy (address_string, "0x", 2);
|
||||
memcpy (address_string + 2, start_addr, len);
|
||||
address_string[2 + len] = '\0';
|
||||
sscanf (address_string, "%p", &start_addr_p);
|
||||
memcpy (address_string, "0x", 2);
|
||||
memcpy (address_string + 2, start_addr, len);
|
||||
address_string[2 + len] = '\0';
|
||||
sscanf (address_string, "%p", &start_addr_p);
|
||||
|
||||
memcpy (address_string, "0x", 2);
|
||||
memcpy (address_string + 2, end_addr, len);
|
||||
address_string[2 + len] = '\0';
|
||||
sscanf (address_string, "%p", &end_addr_p);
|
||||
memcpy (address_string, "0x", 2);
|
||||
memcpy (address_string + 2, end_addr, len);
|
||||
address_string[2 + len] = '\0';
|
||||
sscanf (address_string, "%p", &end_addr_p);
|
||||
|
||||
|
||||
if (symbol >= start_addr_p && symbol < end_addr_p) {
|
||||
found = file;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (symbol >= start_addr_p && symbol < end_addr_p) {
|
||||
found = file;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
free (address_string);
|
||||
fclose (f);
|
||||
free (address_string);
|
||||
fclose (f);
|
||||
|
||||
if (found == NULL)
|
||||
return (char *) NULL;
|
||||
else
|
||||
return strdup (found);
|
||||
if (found == NULL)
|
||||
return (char *) NULL;
|
||||
else
|
||||
return strdup (found);
|
||||
#endif /* ENABLE_BINRELOC */
|
||||
}
|
||||
|
||||
|
||||
#ifndef BINRELOC_RUNNING_DOXYGEN
|
||||
#undef NULL
|
||||
#define NULL ((void *) 0) /* typecasted as char* for C++ type safeness */
|
||||
#undef NULL
|
||||
#define NULL ((void *) 0) /* typecasted as char* for C++ type safeness */
|
||||
#endif
|
||||
|
||||
static char *exe = (char *) NULL;
|
||||
|
@ -301,10 +301,10 @@ static char *exe = (char *) NULL;
|
|||
* @returns 1 on success, 0 if BinReloc failed to initialize.
|
||||
*/
|
||||
int
|
||||
br_init (BrInitError *error)
|
||||
br_init(BrInitError *error)
|
||||
{
|
||||
exe = _br_find_exe (error);
|
||||
return exe != NULL;
|
||||
exe = _br_find_exe(error);
|
||||
return exe != NULL;
|
||||
}
|
||||
|
||||
|
||||
|
@ -323,10 +323,10 @@ br_init (BrInitError *error)
|
|||
* @returns 1 on success, 0 if a filename cannot be found.
|
||||
*/
|
||||
int
|
||||
br_init_lib (BrInitError *error)
|
||||
br_init_lib(BrInitError *error)
|
||||
{
|
||||
exe = _br_find_exe_for_symbol ((const void *) "", error);
|
||||
return exe != NULL;
|
||||
exe = _br_find_exe_for_symbol((const void *) "", error);
|
||||
return exe != NULL;
|
||||
}
|
||||
|
||||
|
||||
|
@ -340,16 +340,17 @@ br_init_lib (BrInitError *error)
|
|||
* NULL will be returned.
|
||||
*/
|
||||
char *
|
||||
br_find_exe (const char *default_exe)
|
||||
br_find_exe(const char *default_exe)
|
||||
{
|
||||
if (exe == (char *) NULL) {
|
||||
/* BinReloc is not initialized. */
|
||||
if (default_exe != (const char *) NULL)
|
||||
return strdup (default_exe);
|
||||
else
|
||||
return (char *) NULL;
|
||||
}
|
||||
return strdup (exe);
|
||||
if (exe == (char *) NULL)
|
||||
{
|
||||
/* BinReloc is not initialized. */
|
||||
if (default_exe != (const char *) NULL)
|
||||
return strdup(default_exe);
|
||||
else
|
||||
return (char *) NULL;
|
||||
}
|
||||
return strdup(exe);
|
||||
}
|
||||
|
||||
|
||||
|
@ -368,17 +369,18 @@ br_find_exe (const char *default_exe)
|
|||
* returned.
|
||||
*/
|
||||
char *
|
||||
br_find_exe_dir (const char *default_dir)
|
||||
br_find_exe_dir(const char *default_dir)
|
||||
{
|
||||
if (exe == NULL) {
|
||||
/* BinReloc not initialized. */
|
||||
if (default_dir != NULL)
|
||||
return strdup (default_dir);
|
||||
else
|
||||
return NULL;
|
||||
}
|
||||
if (exe == NULL)
|
||||
{
|
||||
/* BinReloc not initialized. */
|
||||
if (default_dir != NULL)
|
||||
return strdup(default_dir);
|
||||
else
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return br_dirname (exe);
|
||||
return br_dirname(exe);
|
||||
}
|
||||
|
||||
|
||||
|
@ -396,22 +398,23 @@ br_find_exe_dir (const char *default_dir)
|
|||
* will be returned. If default_prefix is NULL, then NULL will be returned.
|
||||
*/
|
||||
char *
|
||||
br_find_prefix (const char *default_prefix)
|
||||
br_find_prefix(const char *default_prefix)
|
||||
{
|
||||
char *dir1, *dir2;
|
||||
char *dir1, *dir2;
|
||||
|
||||
if (exe == (char *) NULL) {
|
||||
/* BinReloc not initialized. */
|
||||
if (default_prefix != (const char *) NULL)
|
||||
return strdup (default_prefix);
|
||||
else
|
||||
return (char *) NULL;
|
||||
}
|
||||
if (exe == (char *) NULL)
|
||||
{
|
||||
/* BinReloc not initialized. */
|
||||
if (default_prefix != (const char *) NULL)
|
||||
return strdup(default_prefix);
|
||||
else
|
||||
return (char *) NULL;
|
||||
}
|
||||
|
||||
dir1 = br_dirname (exe);
|
||||
dir2 = br_dirname (dir1);
|
||||
free (dir1);
|
||||
return dir2;
|
||||
dir1 = br_dirname(exe);
|
||||
dir2 = br_dirname(dir1);
|
||||
free(dir1);
|
||||
return dir2;
|
||||
}
|
||||
|
||||
|
||||
|
@ -429,22 +432,23 @@ br_find_prefix (const char *default_prefix)
|
|||
* be returned. If default_bin_dir is NULL, then NULL will be returned.
|
||||
*/
|
||||
char *
|
||||
br_find_bin_dir (const char *default_bin_dir)
|
||||
br_find_bin_dir(const char *default_bin_dir)
|
||||
{
|
||||
char *prefix, *dir;
|
||||
char *prefix, *dir;
|
||||
|
||||
prefix = br_find_prefix ((const char *) NULL);
|
||||
if (prefix == (char *) NULL) {
|
||||
/* BinReloc not initialized. */
|
||||
if (default_bin_dir != (const char *) NULL)
|
||||
return strdup (default_bin_dir);
|
||||
else
|
||||
return (char *) NULL;
|
||||
}
|
||||
prefix = br_find_prefix((const char *) NULL);
|
||||
if (prefix == (char *) NULL)
|
||||
{
|
||||
/* BinReloc not initialized. */
|
||||
if (default_bin_dir != (const char *) NULL)
|
||||
return strdup(default_bin_dir);
|
||||
else
|
||||
return (char *) NULL;
|
||||
}
|
||||
|
||||
dir = br_build_path (prefix, "bin");
|
||||
free (prefix);
|
||||
return dir;
|
||||
dir = br_build_path(prefix, "bin");
|
||||
free(prefix);
|
||||
return dir;
|
||||
}
|
||||
|
||||
|
||||
|
@ -462,22 +466,23 @@ br_find_bin_dir (const char *default_bin_dir)
|
|||
* be returned. If default_bin_dir is NULL, then NULL will be returned.
|
||||
*/
|
||||
char *
|
||||
br_find_sbin_dir (const char *default_sbin_dir)
|
||||
br_find_sbin_dir(const char *default_sbin_dir)
|
||||
{
|
||||
char *prefix, *dir;
|
||||
char *prefix, *dir;
|
||||
|
||||
prefix = br_find_prefix ((const char *) NULL);
|
||||
if (prefix == (char *) NULL) {
|
||||
/* BinReloc not initialized. */
|
||||
if (default_sbin_dir != (const char *) NULL)
|
||||
return strdup (default_sbin_dir);
|
||||
else
|
||||
return (char *) NULL;
|
||||
}
|
||||
prefix = br_find_prefix((const char *) NULL);
|
||||
if (prefix == (char *) NULL)
|
||||
{
|
||||
/* BinReloc not initialized. */
|
||||
if (default_sbin_dir != (const char *) NULL)
|
||||
return strdup(default_sbin_dir);
|
||||
else
|
||||
return (char *) NULL;
|
||||
}
|
||||
|
||||
dir = br_build_path (prefix, "sbin");
|
||||
free (prefix);
|
||||
return dir;
|
||||
dir = br_build_path(prefix, "sbin");
|
||||
free(prefix);
|
||||
return dir;
|
||||
}
|
||||
|
||||
|
||||
|
@ -496,22 +501,23 @@ br_find_sbin_dir (const char *default_sbin_dir)
|
|||
* returned.
|
||||
*/
|
||||
char *
|
||||
br_find_data_dir (const char *default_data_dir)
|
||||
br_find_data_dir(const char *default_data_dir)
|
||||
{
|
||||
char *prefix, *dir;
|
||||
char *prefix, *dir;
|
||||
|
||||
prefix = br_find_prefix ((const char *) NULL);
|
||||
if (prefix == (char *) NULL) {
|
||||
/* BinReloc not initialized. */
|
||||
if (default_data_dir != (const char *) NULL)
|
||||
return strdup (default_data_dir);
|
||||
else
|
||||
return (char *) NULL;
|
||||
}
|
||||
prefix = br_find_prefix((const char *) NULL);
|
||||
if (prefix == (char *) NULL)
|
||||
{
|
||||
/* BinReloc not initialized. */
|
||||
if (default_data_dir != (const char *) NULL)
|
||||
return strdup(default_data_dir);
|
||||
else
|
||||
return (char *) NULL;
|
||||
}
|
||||
|
||||
dir = br_build_path (prefix, "share");
|
||||
free (prefix);
|
||||
return dir;
|
||||
dir = br_build_path(prefix, "share");
|
||||
free(prefix);
|
||||
return dir;
|
||||
}
|
||||
|
||||
|
||||
|
@ -529,22 +535,23 @@ br_find_data_dir (const char *default_data_dir)
|
|||
* If default_locale_dir is NULL, then NULL will be returned.
|
||||
*/
|
||||
char *
|
||||
br_find_locale_dir (const char *default_locale_dir)
|
||||
br_find_locale_dir(const char *default_locale_dir)
|
||||
{
|
||||
char *data_dir, *dir;
|
||||
char *data_dir, *dir;
|
||||
|
||||
data_dir = br_find_data_dir ((const char *) NULL);
|
||||
if (data_dir == (char *) NULL) {
|
||||
/* BinReloc not initialized. */
|
||||
if (default_locale_dir != (const char *) NULL)
|
||||
return strdup (default_locale_dir);
|
||||
else
|
||||
return (char *) NULL;
|
||||
}
|
||||
data_dir = br_find_data_dir((const char *) NULL);
|
||||
if (data_dir == (char *) NULL)
|
||||
{
|
||||
/* BinReloc not initialized. */
|
||||
if (default_locale_dir != (const char *) NULL)
|
||||
return strdup(default_locale_dir);
|
||||
else
|
||||
return (char *) NULL;
|
||||
}
|
||||
|
||||
dir = br_build_path (data_dir, "locale");
|
||||
free (data_dir);
|
||||
return dir;
|
||||
dir = br_build_path(data_dir, "locale");
|
||||
free(data_dir);
|
||||
return dir;
|
||||
}
|
||||
|
||||
|
||||
|
@ -562,22 +569,23 @@ br_find_locale_dir (const char *default_locale_dir)
|
|||
* If default_lib_dir is NULL, then NULL will be returned.
|
||||
*/
|
||||
char *
|
||||
br_find_lib_dir (const char *default_lib_dir)
|
||||
br_find_lib_dir(const char *default_lib_dir)
|
||||
{
|
||||
char *prefix, *dir;
|
||||
char *prefix, *dir;
|
||||
|
||||
prefix = br_find_prefix ((const char *) NULL);
|
||||
if (prefix == (char *) NULL) {
|
||||
/* BinReloc not initialized. */
|
||||
if (default_lib_dir != (const char *) NULL)
|
||||
return strdup (default_lib_dir);
|
||||
else
|
||||
return (char *) NULL;
|
||||
}
|
||||
prefix = br_find_prefix((const char *) NULL);
|
||||
if (prefix == (char *) NULL)
|
||||
{
|
||||
/* BinReloc not initialized. */
|
||||
if (default_lib_dir != (const char *) NULL)
|
||||
return strdup(default_lib_dir);
|
||||
else
|
||||
return (char *) NULL;
|
||||
}
|
||||
|
||||
dir = br_build_path (prefix, "lib");
|
||||
free (prefix);
|
||||
return dir;
|
||||
dir = br_build_path(prefix, "lib");
|
||||
free(prefix);
|
||||
return dir;
|
||||
}
|
||||
|
||||
|
||||
|
@ -595,22 +603,23 @@ br_find_lib_dir (const char *default_lib_dir)
|
|||
* If default_libexec_dir is NULL, then NULL will be returned.
|
||||
*/
|
||||
char *
|
||||
br_find_libexec_dir (const char *default_libexec_dir)
|
||||
br_find_libexec_dir(const char *default_libexec_dir)
|
||||
{
|
||||
char *prefix, *dir;
|
||||
char *prefix, *dir;
|
||||
|
||||
prefix = br_find_prefix ((const char *) NULL);
|
||||
if (prefix == (char *) NULL) {
|
||||
/* BinReloc not initialized. */
|
||||
if (default_libexec_dir != (const char *) NULL)
|
||||
return strdup (default_libexec_dir);
|
||||
else
|
||||
return (char *) NULL;
|
||||
}
|
||||
prefix = br_find_prefix((const char *) NULL);
|
||||
if (prefix == (char *) NULL)
|
||||
{
|
||||
/* BinReloc not initialized. */
|
||||
if (default_libexec_dir != (const char *) NULL)
|
||||
return strdup(default_libexec_dir);
|
||||
else
|
||||
return (char *) NULL;
|
||||
}
|
||||
|
||||
dir = br_build_path (prefix, "libexec");
|
||||
free (prefix);
|
||||
return dir;
|
||||
dir = br_build_path(prefix, "libexec");
|
||||
free(prefix);
|
||||
return dir;
|
||||
}
|
||||
|
||||
|
||||
|
@ -628,22 +637,23 @@ br_find_libexec_dir (const char *default_libexec_dir)
|
|||
* If default_etc_dir is NULL, then NULL will be returned.
|
||||
*/
|
||||
char *
|
||||
br_find_etc_dir (const char *default_etc_dir)
|
||||
br_find_etc_dir(const char *default_etc_dir)
|
||||
{
|
||||
char *prefix, *dir;
|
||||
char *prefix, *dir;
|
||||
|
||||
prefix = br_find_prefix ((const char *) NULL);
|
||||
if (prefix == (char *) NULL) {
|
||||
/* BinReloc not initialized. */
|
||||
if (default_etc_dir != (const char *) NULL)
|
||||
return strdup (default_etc_dir);
|
||||
else
|
||||
return (char *) NULL;
|
||||
}
|
||||
prefix = br_find_prefix((const char *) NULL);
|
||||
if (prefix == (char *) NULL)
|
||||
{
|
||||
/* BinReloc not initialized. */
|
||||
if (default_etc_dir != (const char *) NULL)
|
||||
return strdup(default_etc_dir);
|
||||
else
|
||||
return (char *) NULL;
|
||||
}
|
||||
|
||||
dir = br_build_path (prefix, "etc");
|
||||
free (prefix);
|
||||
return dir;
|
||||
dir = br_build_path(prefix, "etc");
|
||||
free(prefix);
|
||||
return dir;
|
||||
}
|
||||
|
||||
|
||||
|
@ -658,69 +668,70 @@ br_find_etc_dir (const char *default_etc_dir)
|
|||
* @returns A newly-allocated string. This string should be freed when no longer needed.
|
||||
*/
|
||||
char *
|
||||
br_strcat (const char *str1, const char *str2)
|
||||
br_strcat(const char *str1, const char *str2)
|
||||
{
|
||||
char *result;
|
||||
size_t len1, len2;
|
||||
char *result;
|
||||
size_t len1, len2;
|
||||
|
||||
if (str1 == NULL)
|
||||
str1 = "";
|
||||
if (str2 == NULL)
|
||||
str2 = "";
|
||||
if (str1 == NULL)
|
||||
str1 = "";
|
||||
if (str2 == NULL)
|
||||
str2 = "";
|
||||
|
||||
len1 = strlen (str1);
|
||||
len2 = strlen (str2);
|
||||
len1 = strlen(str1);
|
||||
len2 = strlen(str2);
|
||||
|
||||
result = (char *) malloc (len1 + len2 + 1);
|
||||
memcpy (result, str1, len1);
|
||||
memcpy (result + len1, str2, len2);
|
||||
result[len1 + len2] = '\0';
|
||||
result = (char *) malloc(len1 + len2 + 1);
|
||||
memcpy(result, str1, len1);
|
||||
memcpy(result + len1, str2, len2);
|
||||
result[len1 + len2] = '\0';
|
||||
|
||||
return result;
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
char *
|
||||
br_build_path (const char *dir, const char *file)
|
||||
br_build_path(const char *dir, const char *file)
|
||||
{
|
||||
char *dir2, *result;
|
||||
size_t len;
|
||||
int must_free = 0;
|
||||
char *dir2, *result;
|
||||
size_t len;
|
||||
int must_free = 0;
|
||||
|
||||
len = strlen (dir);
|
||||
if (len > 0 && dir[len - 1] != '/') {
|
||||
dir2 = br_strcat (dir, "/");
|
||||
must_free = 1;
|
||||
} else
|
||||
dir2 = (char *) dir;
|
||||
len = strlen(dir);
|
||||
if (len > 0 && dir[len - 1] != '/')
|
||||
{
|
||||
dir2 = br_strcat(dir, "/");
|
||||
must_free = 1;
|
||||
} else
|
||||
dir2 = (char *) dir;
|
||||
|
||||
result = br_strcat (dir2, file);
|
||||
if (must_free)
|
||||
free (dir2);
|
||||
return result;
|
||||
result = br_strcat(dir2, file);
|
||||
if (must_free)
|
||||
free(dir2);
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
/* Emulates glibc's strndup() */
|
||||
static char *
|
||||
br_strndup (const char *str, size_t size)
|
||||
br_strndup(const char *str, size_t size)
|
||||
{
|
||||
char *result = (char *) NULL;
|
||||
size_t len;
|
||||
char *result = (char *) NULL;
|
||||
size_t len;
|
||||
|
||||
if (str == (const char *) NULL)
|
||||
return (char *) NULL;
|
||||
if (str == (const char *) NULL)
|
||||
return (char *) NULL;
|
||||
|
||||
len = strlen (str);
|
||||
if (len == 0)
|
||||
return strdup ("");
|
||||
if (size > len)
|
||||
size = len;
|
||||
len = strlen(str);
|
||||
if (len == 0)
|
||||
return strdup("");
|
||||
if (size > len)
|
||||
size = len;
|
||||
|
||||
result = (char *) malloc (len + 1);
|
||||
memcpy (result, str, size);
|
||||
result[size] = '\0';
|
||||
return result;
|
||||
result = (char *) malloc(len + 1);
|
||||
memcpy(result, str, size);
|
||||
result[size] = '\0';
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
|
@ -737,25 +748,26 @@ br_strndup (const char *str, size_t size)
|
|||
* @returns A directory name. This string should be freed when no longer needed.
|
||||
*/
|
||||
char *
|
||||
br_dirname (const char *path)
|
||||
br_dirname(const char *path)
|
||||
{
|
||||
char *end, *result;
|
||||
char *end, *result;
|
||||
|
||||
if (path == (const char *) NULL)
|
||||
return (char *) NULL;
|
||||
if (path == (const char *) NULL)
|
||||
return (char *) NULL;
|
||||
|
||||
end = strrchr (path, '/');
|
||||
if (end == (const char *) NULL)
|
||||
return strdup (".");
|
||||
end = strrchr(path, '/');
|
||||
if (end == (const char *) NULL)
|
||||
return strdup(".");
|
||||
|
||||
while (end > path && *end == '/')
|
||||
end--;
|
||||
result = br_strndup (path, end - path + 1);
|
||||
if (result[0] == 0) {
|
||||
free (result);
|
||||
return strdup ("/");
|
||||
} else
|
||||
return result;
|
||||
while (end > path && *end == '/')
|
||||
end--;
|
||||
result = br_strndup(path, end - path + 1);
|
||||
if (result[0] == 0)
|
||||
{
|
||||
free(result);
|
||||
return strdup("/");
|
||||
} else
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -20,36 +20,36 @@ extern "C" {
|
|||
|
||||
/** These error codes can be returned by br_init(), br_init_lib(), gbr_init() or gbr_init_lib(). */
|
||||
typedef enum {
|
||||
/** Cannot allocate memory. */
|
||||
BR_INIT_ERROR_NOMEM,
|
||||
/** Unable to open /proc/self/maps; see errno for details. */
|
||||
BR_INIT_ERROR_OPEN_MAPS,
|
||||
/** Unable to read from /proc/self/maps; see errno for details. */
|
||||
BR_INIT_ERROR_READ_MAPS,
|
||||
/** The file format of /proc/self/maps is invalid; kernel bug? */
|
||||
BR_INIT_ERROR_INVALID_MAPS,
|
||||
/** BinReloc is disabled (the ENABLE_BINRELOC macro is not defined). */
|
||||
BR_INIT_ERROR_DISABLED
|
||||
/** Cannot allocate memory. */
|
||||
BR_INIT_ERROR_NOMEM,
|
||||
/** Unable to open /proc/self/maps; see errno for details. */
|
||||
BR_INIT_ERROR_OPEN_MAPS,
|
||||
/** Unable to read from /proc/self/maps; see errno for details. */
|
||||
BR_INIT_ERROR_READ_MAPS,
|
||||
/** The file format of /proc/self/maps is invalid; kernel bug? */
|
||||
BR_INIT_ERROR_INVALID_MAPS,
|
||||
/** BinReloc is disabled (the ENABLE_BINRELOC macro is not defined). */
|
||||
BR_INIT_ERROR_DISABLED
|
||||
} BrInitError;
|
||||
|
||||
|
||||
#ifndef BINRELOC_RUNNING_DOXYGEN
|
||||
/* Mangle symbol names to avoid symbol collisions with other ELF objects. */
|
||||
#define br_init SbCJ22537442193159_br_init
|
||||
#define br_init_lib SbCJ22537442193159_br_init_lib
|
||||
#define br_find_exe SbCJ22537442193159_br_find_exe
|
||||
#define br_find_exe_dir SbCJ22537442193159_br_find_exe_dir
|
||||
#define br_find_prefix SbCJ22537442193159_br_find_prefix
|
||||
#define br_find_bin_dir SbCJ22537442193159_br_find_bin_dir
|
||||
#define br_find_sbin_dir SbCJ22537442193159_br_find_sbin_dir
|
||||
#define br_find_data_dir SbCJ22537442193159_br_find_data_dir
|
||||
#define br_find_locale_dir SbCJ22537442193159_br_find_locale_dir
|
||||
#define br_find_lib_dir SbCJ22537442193159_br_find_lib_dir
|
||||
#define br_find_libexec_dir SbCJ22537442193159_br_find_libexec_dir
|
||||
#define br_find_etc_dir SbCJ22537442193159_br_find_etc_dir
|
||||
#define br_strcat SbCJ22537442193159_br_strcat
|
||||
#define br_build_path SbCJ22537442193159_br_build_path
|
||||
#define br_dirname SbCJ22537442193159_br_dirname
|
||||
#define br_init SbCJ22537442193159_br_init
|
||||
#define br_init_lib SbCJ22537442193159_br_init_lib
|
||||
#define br_find_exe SbCJ22537442193159_br_find_exe
|
||||
#define br_find_exe_dir SbCJ22537442193159_br_find_exe_dir
|
||||
#define br_find_prefix SbCJ22537442193159_br_find_prefix
|
||||
#define br_find_bin_dir SbCJ22537442193159_br_find_bin_dir
|
||||
#define br_find_sbin_dir SbCJ22537442193159_br_find_sbin_dir
|
||||
#define br_find_data_dir SbCJ22537442193159_br_find_data_dir
|
||||
#define br_find_locale_dir SbCJ22537442193159_br_find_locale_dir
|
||||
#define br_find_lib_dir SbCJ22537442193159_br_find_lib_dir
|
||||
#define br_find_libexec_dir SbCJ22537442193159_br_find_libexec_dir
|
||||
#define br_find_etc_dir SbCJ22537442193159_br_find_etc_dir
|
||||
#define br_strcat SbCJ22537442193159_br_strcat
|
||||
#define br_build_path SbCJ22537442193159_br_build_path
|
||||
#define br_dirname SbCJ22537442193159_br_dirname
|
||||
|
||||
|
||||
#endif
|
||||
|
|
|
@ -18,14 +18,14 @@
|
|||
#include "getch.h"
|
||||
#endif
|
||||
|
||||
#define stricmp(a,b) strcasecmp(a,b)
|
||||
#define strnicmp(a,b,c) strncasecmp(a,b,c)
|
||||
#define stricmp(a,b) strcasecmp(a,b)
|
||||
#define strnicmp(a,b,c) strncasecmp(a,b,c)
|
||||
|
||||
/*
|
||||
* WinWorld wants '\'. Unices do not.
|
||||
*/
|
||||
#define DIRECTORY_SEP_CHAR '/'
|
||||
#define DIRECTORY_SEP_STR "/"
|
||||
#define DIRECTORY_SEP_CHAR '/'
|
||||
#define DIRECTORY_SEP_STR "/"
|
||||
|
||||
/*
|
||||
* SC assumes that a computer is Little Endian unless told otherwise. It uses
|
||||
|
@ -43,7 +43,7 @@
|
|||
#endif
|
||||
|
||||
#if !defined __BYTE_ORDER
|
||||
# error "Can't figure computer byte order (__BYTE_ORDER macro not found)"
|
||||
# error "Can't figure computer byte order (__BYTE_ORDER macro not found)"
|
||||
#endif
|
||||
|
||||
#endif /* SCLINUX_H */
|
||||
|
|
|
@ -68,7 +68,7 @@
|
|||
#elif defined FREEBSD && !defined __FreeBSD__
|
||||
#define __FreeBSD__
|
||||
#elif defined(_MSC_VER)
|
||||
#pragma warning(disable: 4996) /* for Microsoft Visual C/C++ */
|
||||
#pragma warning(disable: 4996) /* for Microsoft Visual C/C++ */
|
||||
#endif
|
||||
#if !defined strnicmp && !defined PORTABLE_STRNICMP
|
||||
#if defined __LINUX__ || defined __FreeBSD__ || defined __OpenBSD__ || defined __APPLE__
|
||||
|
|
|
@ -68,7 +68,7 @@ int ini_browse(INI_CALLBACK Callback, const void *UserData, const mTCHAR *Filen
|
|||
#if defined __cplusplus
|
||||
|
||||
#if defined __WXWINDOWS__
|
||||
#include "wxMinIni.h"
|
||||
#include "wxMinIni.h"
|
||||
#else
|
||||
#include <string>
|
||||
|
||||
|
|
Loading…
Reference in a new issue