aboutsummaryrefslogtreecommitdiff
path: root/backends/platform/PalmOS/Src/missing
diff options
context:
space:
mode:
authorMax Horn2006-07-06 21:44:48 +0000
committerMax Horn2006-07-06 21:44:48 +0000
commit1d8d9f5510dc5f574e926bd6fadb9d20337daede (patch)
tree5cdcf6c8a233159776be9d90f3f39885222f65eb /backends/platform/PalmOS/Src/missing
parent9269ebe9f5a281f452594f1e8108e31c88a398fb (diff)
downloadscummvm-rg350-1d8d9f5510dc5f574e926bd6fadb9d20337daede.tar.gz
scummvm-rg350-1d8d9f5510dc5f574e926bd6fadb9d20337daede.tar.bz2
scummvm-rg350-1d8d9f5510dc5f574e926bd6fadb9d20337daede.zip
Moving remaining platform/backends code, as previously threatened
svn-id: r23380
Diffstat (limited to 'backends/platform/PalmOS/Src/missing')
-rw-r--r--backends/platform/PalmOS/Src/missing/assert.h34
-rw-r--r--backends/platform/PalmOS/Src/missing/ext_stdio.c650
-rw-r--r--backends/platform/PalmOS/Src/missing/ext_stdlib.c117
-rw-r--r--backends/platform/PalmOS/Src/missing/ext_string.c45
-rw-r--r--backends/platform/PalmOS/Src/missing/ext_time.c85
-rw-r--r--backends/platform/PalmOS/Src/missing/ext_unistd.c41
-rw-r--r--backends/platform/PalmOS/Src/missing/fcntl.h42
-rw-r--r--backends/platform/PalmOS/Src/missing/math.h38
-rw-r--r--backends/platform/PalmOS/Src/missing/memory.h25
-rw-r--r--backends/platform/PalmOS/Src/missing/stdio.h103
-rw-r--r--backends/platform/PalmOS/Src/missing/stdlib.h88
-rw-r--r--backends/platform/PalmOS/Src/missing/string.h66
-rw-r--r--backends/platform/PalmOS/Src/missing/sys/stat.h1
-rw-r--r--backends/platform/PalmOS/Src/missing/time.h55
-rw-r--r--backends/platform/PalmOS/Src/missing/unistd.h42
15 files changed, 1432 insertions, 0 deletions
diff --git a/backends/platform/PalmOS/Src/missing/assert.h b/backends/platform/PalmOS/Src/missing/assert.h
new file mode 100644
index 0000000000..7bc571ec15
--- /dev/null
+++ b/backends/platform/PalmOS/Src/missing/assert.h
@@ -0,0 +1,34 @@
+/* ScummVM - Scumm Interpreter
+ * Copyright (C) 2001 Ludvig Strigeus
+ * Copyright (C) 2001-2006 The ScummVM project
+ * Copyright (C) 2002-2006 Chris Apers - PalmOS Backend
+ *
+ * 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * $URL$
+ * $Id$
+ *
+ */
+
+#ifndef __ASSERT_H__
+#define __ASSERT_H__
+
+#ifdef _DEBUG
+#define assert(a) ErrFatalDisplayIf(!(a), "Assertion failed: " #a)
+#else
+#define assert(a) (void)0
+#endif
+
+#endif
diff --git a/backends/platform/PalmOS/Src/missing/ext_stdio.c b/backends/platform/PalmOS/Src/missing/ext_stdio.c
new file mode 100644
index 0000000000..f7d37a9140
--- /dev/null
+++ b/backends/platform/PalmOS/Src/missing/ext_stdio.c
@@ -0,0 +1,650 @@
+/* ScummVM - Scumm Interpreter
+ * Copyright (C) 2001 Ludvig Strigeus
+ * Copyright (C) 2001-2006 The ScummVM project
+ * Copyright (C) 2002-2006 Chris Apers - PalmOS Backend
+ *
+ * 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * $URL$
+ * $Id$
+ *
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <PmPalmOSNVFS.h>
+
+#define CACHE_SIZE 1024
+enum {
+ MODE_BUFREAD = 1,
+ MODE_BUFWRITE,
+ MODE_BUFNONE
+};
+
+FILE gStdioOutput = {0,0,0,0,0,0};
+static void dummy(Boolean) {};
+
+static LedProc gStdioLedProc = dummy;
+static UInt16 gStdioVolRefNum = vfsInvalidVolRef;
+static UInt32 gCacheSize = CACHE_SIZE;
+
+// TODO : implement "errno"
+
+void StdioInit(UInt16 volRefNum, const Char *output) { // DONE
+ gStdioVolRefNum = volRefNum;
+ gStdioOutput.mode = MODE_BUFWRITE;
+
+ VFSFileDelete(gStdioVolRefNum, output);
+ VFSFileCreate(gStdioVolRefNum, output);
+ VFSFileOpen (gStdioVolRefNum, output,vfsModeWrite, &gStdioOutput.fileRef);
+}
+
+void StdioSetLedProc(LedProc ledProc) { // DONE
+ if (ledProc)
+ gStdioLedProc = ledProc;
+ else
+ gStdioLedProc = dummy;
+}
+
+void StdioSetCacheSize(UInt32 s) { // DONE
+ gCacheSize = s;
+}
+
+void StdioRelease() { // DONE
+ // there is no cache on stdout/stderr
+ VFSFileClose(gStdioOutput.fileRef);
+}
+
+UInt16 fclose(FILE *stream) { // DONE
+ UInt32 numBytesWritten;
+ Err e;
+
+ if (stream->cacheSize) {
+ if (stream->bufSize > 0 && stream->mode == MODE_BUFWRITE)
+ VFSFileWrite(stream->fileRef, stream->bufSize, stream->cache, &numBytesWritten);
+
+ MemPtrFree(stream->cache);
+ }
+
+ e = VFSFileClose(stream->fileRef);
+ e = MemPtrFree(stream);
+
+ return e;
+}
+
+UInt16 feof(FILE *stream) { // DONE
+ Err e;
+
+ if (stream->cacheSize) {
+ switch (stream->mode) {
+ case MODE_BUFWRITE:
+ return 0; // never set in this mode
+ case MODE_BUFREAD:
+ if (stream->bufSize > 0)
+ return 0;
+ break;
+ }
+ }
+
+ e = VFSFileEOF(stream->fileRef);
+ return e;
+}
+
+UInt16 ferror(FILE *stream) {
+ return (stream->err);
+}
+
+Int16 fgetc(FILE *stream) {
+ UInt32 numBytesRead;
+ Char c;
+
+ numBytesRead = fread(&c, 1, 1, stream);
+ return (int)(numBytesRead == 1 ? c : EOF);
+}
+
+Char *fgets(Char *s, UInt32 n, FILE *stream) {
+ UInt32 numBytesRead;
+
+ numBytesRead = fread(s, n, 1, stream);
+ if (numBytesRead) {
+ UInt32 reset = 0;
+ Char *endLine = StrChr(s, '\n');
+
+ if (endLine >= s) {
+ reset = (endLine - s);
+ s[reset] = 0;
+ reset = numBytesRead - (reset + 1);
+ fseek(stream, -reset, SEEK_CUR);
+ }
+
+ return s;
+ }
+
+ return NULL;
+}
+
+FILE *fopen(const Char *filename, const Char *type) { // DONE
+ Err err;
+ UInt16 openMode;
+ Boolean cache = true;
+ FILE *fileP = (FILE *)MemPtrNew(sizeof(FILE));
+
+ if (!fileP)
+ return NULL;
+
+ MemSet(fileP, sizeof(FILE), 0);
+
+ if (StrCompare(type,"r")==0 || StrCompare(type,"rb")==0) {
+ fileP->mode = MODE_BUFREAD;
+ openMode = vfsModeRead;
+
+ } else if (StrCompare(type,"w")==0 || StrCompare(type,"wb")==0) {
+ fileP->mode = MODE_BUFWRITE;
+ openMode = vfsModeCreate|vfsModeWrite;
+
+ } else {
+ cache = false;
+ fileP->mode = MODE_BUFNONE;
+ openMode = vfsModeReadWrite;
+ }
+
+ if (cache) {
+ fileP->cacheSize = gCacheSize;
+ if (gCacheSize) fileP->cache = (UInt8 *)malloc(gCacheSize); // was MemGluePtrNew
+ if (!fileP->cache) fileP->cacheSize = 0;
+ }
+
+ if (openMode & vfsModeRead) {
+ // if read file :
+ // first try to load from the specfied card
+ err = VFSFileOpen (gStdioVolRefNum, filename, openMode, &fileP->fileRef);
+ //if err (not found ?) parse each avalaible card for the specified file
+ if (err) {
+ UInt16 volRefNum;
+ UInt32 volIterator = vfsIteratorStart|vfsIncludePrivateVolumes;
+ while (volIterator != vfsIteratorStop) {
+ err = VFSVolumeEnumerate(&volRefNum, &volIterator);
+
+ if (!err) {
+ err = VFSFileOpen (volRefNum, filename, openMode, &fileP->fileRef);
+ if (!err)
+ return fileP;
+ }
+ }
+ } else {
+ return fileP;
+ }
+ } else {
+ // if write file :
+ // use only the specified card
+ err = VFSFileDelete(gStdioVolRefNum, filename); // delete it if exists
+ err = VFSFileCreate(gStdioVolRefNum, filename);
+ openMode = vfsModeWrite;
+ if (!err) {
+ err = VFSFileOpen (gStdioVolRefNum, filename, openMode, &fileP->fileRef);
+ if (!err)
+ return fileP;
+ }
+ }
+
+ if (fileP->cacheSize)
+ MemPtrFree(fileP->cache);
+
+ MemPtrFree(fileP); // prevent memory leak
+ return NULL;
+}
+
+UInt32 fread(void *ptr, UInt32 size, UInt32 nitems, FILE *stream) { // DONE
+ Err e = errNone;
+ UInt32 numBytesRead, rsize = (size * nitems);
+
+ // try to read on a write only stream ?
+ if (stream->mode == MODE_BUFWRITE || !rsize)
+ return 0;
+
+ // cached ?
+ if (stream->cacheSize) {
+ // empty buffer ? fill it if required
+ if (stream->bufSize == 0 && rsize < stream->cacheSize) {
+ gStdioLedProc(true);
+ e = VFSFileRead(stream->fileRef, stream->cacheSize, stream->cache, &numBytesRead);
+ gStdioLedProc(false);
+ stream->bufSize = numBytesRead;
+ stream->bufPos = 0;
+ }
+
+ // we have the data in the cache
+ if (stream->bufSize >= rsize) {
+ MemMove(ptr, (stream->cache + stream->bufPos), rsize);
+ stream->bufPos += rsize;
+ stream->bufSize -= rsize;
+ numBytesRead = rsize;
+
+ // not enough but something ?
+ } else if (stream->bufSize > 0) {
+ UInt8 *next = (UInt8 *)ptr;
+ MemMove(ptr, (stream->cache + stream->bufPos), stream->bufSize);
+ rsize -= stream->bufSize;
+ gStdioLedProc(true);
+ e = VFSFileRead(stream->fileRef, rsize, (next + stream->bufSize), &numBytesRead);
+ gStdioLedProc(false);
+ numBytesRead += stream->bufSize;
+ stream->bufSize = 0;
+ stream->bufPos = 0;
+
+ // nothing in the cache ?
+ } else {
+ gStdioLedProc(true);
+ e = VFSFileRead(stream->fileRef, rsize, ptr, &numBytesRead);
+ gStdioLedProc(false);
+ }
+
+ // no ? direct read
+ } else {
+ gStdioLedProc(true);
+ e = VFSFileRead(stream->fileRef, rsize, ptr, &numBytesRead);
+ gStdioLedProc(false);
+ }
+
+ if (e == errNone || e == vfsErrFileEOF)
+ return (UInt32)(numBytesRead / size);
+
+ return 0;
+}
+
+UInt32 fwrite(const void *ptr, UInt32 size, UInt32 nitems, FILE *stream) { // DONE
+ Err e = errNone;
+ UInt32 numBytesWritten = (size * nitems);
+
+ // try to write on a read only stream ?
+ if (stream->mode == MODE_BUFREAD || !numBytesWritten)
+ return 0;
+
+ // cached ?
+ if (stream->cacheSize) {
+ // can cache it ?
+ if ((stream->bufSize + numBytesWritten) <= stream->cacheSize) {
+ MemMove((stream->cache + stream->bufSize), ptr, numBytesWritten);
+ stream->bufSize += numBytesWritten;
+
+ // not enough room ? write cached data and new data
+ } else {
+ gStdioLedProc(true);
+ e = VFSFileWrite(stream->fileRef, stream->bufSize, stream->cache, &numBytesWritten);
+ e = VFSFileWrite(stream->fileRef, (size * nitems), ptr, &numBytesWritten);
+ gStdioLedProc(false);
+ stream->bufSize = 0;
+ }
+
+ // no ? direct write
+ } else {
+ gStdioLedProc(true);
+ e = VFSFileWrite(stream->fileRef, (size * nitems), ptr, &numBytesWritten);
+ gStdioLedProc(false);
+ }
+
+ if ((e == errNone || e == vfsErrFileEOF)) {
+ return (UInt32)(numBytesWritten / size);
+ }
+
+ return 0;
+}
+
+Int16 fseek(FILE *stream, Int32 offset, Int32 whence) { // DONE
+ UInt32 numBytesWritten;
+ Err e;
+
+ if (stream->cacheSize) {
+ switch (stream->mode) {
+ case MODE_BUFWRITE:
+ e = VFSFileWrite(stream->fileRef, stream->bufSize, stream->cache, &numBytesWritten);
+ stream->bufSize = 0;
+ break;
+
+ case MODE_BUFREAD:
+ // reposition file postion if needed
+ if (whence == SEEK_CUR)
+ e = VFSFileSeek(stream->fileRef, vfsOriginCurrent, -stream->bufSize);
+ stream->bufSize = 0;
+ stream->bufPos = 0;
+ break;
+ }
+ }
+
+ e = VFSFileSeek(stream->fileRef, whence, offset);
+ return (e ? -1 : 0);
+}
+
+Int32 ftell(FILE *stream) { // DONE
+ Err e;
+ UInt32 filePos;
+
+ e = VFSFileTell(stream->fileRef ,&filePos);
+
+ if (stream->cacheSize) {
+ switch (stream->mode) {
+ case MODE_BUFWRITE:
+ filePos += stream->bufSize;
+ break;
+
+ case MODE_BUFREAD:
+ filePos -= stream->bufSize;
+ break;
+ }
+ }
+
+ if (e) return -1; // errno = ?
+ return filePos;
+}
+
+Int32 fprintf(FILE *stream, const Char *formatStr, ...) { // DONE
+ UInt32 numBytesWritten;
+ Char buf[256];
+ va_list va;
+
+ if (!stream->fileRef)
+ return 0;
+
+ va_start(va, formatStr);
+ vsprintf(buf, formatStr, va);
+ va_end(va);
+
+ numBytesWritten = fwrite(buf, StrLen(buf), 1, stream);
+ return numBytesWritten;
+}
+
+Int32 printf(const Char *format, ...) { // DONE
+ UInt32 numBytesWritten;
+ Char buf[256];
+ va_list va;
+
+ if (!stdout->fileRef)
+ return 0;
+
+ va_start(va, format);
+ vsprintf(buf, format, va);
+ va_end(va);
+
+ numBytesWritten = fwrite(buf, StrLen(buf), 1, stdout);
+ return numBytesWritten;
+}
+
+/* needed with 68k mode only, already defined in ARM MSL */
+#ifdef PALMOS_68K
+
+Int32 sprintf(Char* s, const Char* formatStr, ...) {
+ Int16 count;
+ va_list va;
+
+ va_start(va, formatStr);
+ count = vsprintf(s, formatStr, va);
+ va_end(va);
+
+ return count;
+}
+
+Int32 snprintf(Char* s, UInt32 len, const Char* formatStr, ...) {
+ // len is ignored
+ Int16 count;
+ va_list va;
+
+ va_start(va, formatStr);
+ count = vsprintf(s, formatStr, va);
+ va_end(va);
+
+ return count;
+}
+
+
+/* WARNING : vsprintf
+ * -------
+ * This function can handle only %[+- ][.0][field length][sxXdoiucp] format strings
+ * compiler option : 4byte int mode only !
+ *
+ * TODO : check http://www.ijs.si/software/snprintf/ for a portable implementation of vsnprintf
+ * This one make use of sprintf so need to check if it works with PalmOS.
+ */
+
+static Char *StrIToBase(Char *s, Int32 i, UInt8 b) {
+ const Char *conv = "0123456789ABCDEF";
+ Char o;
+ Int16 c, n = 0;
+ Int32 div, mod;
+
+ do {
+ div = i / b;
+ mod = i % b;
+
+ s[n++] = *(conv + mod);
+ i = div;
+
+ } while (i >= b);
+
+ if (i > 0) {
+ s[n + 0] = *(conv + i);
+ s[n + 1] = 0;
+ } else {
+ s[n + 0] = 0;
+ n--;
+ }
+
+ for (c=0; c <= (n >> 1); c++) {
+ o = s[c];
+ s[c] = s[n - c];
+ s[n - c]= o;
+ }
+
+ return s;
+}
+
+static void StrProcC_(Char *ioStr, UInt16 maxLen) {
+ Char *found;
+ Int16 length;
+
+ while (found = StrStr(ioStr, "`c`")) {
+ if (found[3] == 0) { // if next char is NULL
+ length = maxLen - (found - ioStr + 2);
+ MemMove(found, found + 4, length);
+ maxLen -= 2;
+ }
+ }
+}
+
+static void StrProcXO(Char *ioStr, UInt16 maxLen, Char *tmp) {
+ Char *found, *last, mod, fill;
+ Int16 len, count, next;
+ Int32 val;
+
+ while (found = StrChr(ioStr, '`')) {
+ last = StrChr(found + 1, '`');
+
+ if (!last)
+ return;
+
+ *last = 0;
+ next = 0;
+ fill = *(found + 1);
+ mod = *(found + 2);
+ count = StrAToI(found + 3);
+
+ len = maxLen - (last - ioStr);
+ MemMove(found, (last + 1), len);
+
+ // x and X always 8char on palmos ... o set to 8char (not supported on palmos)
+ while ((found[next] == '0' || found[next] == ' ') && next < 8) // WARNING : reduce size only (TODO ?)
+ next++;
+
+ // convert to base 8
+ if (mod == 'o') {
+ StrNCopy(tmp, found + next, 8 - next);
+ tmp[8 - next] = 0;
+ val = StrAToI(tmp);
+ StrIToBase(tmp, val, 8); // now we have the same but in octal
+ next = 8 - StrLen(tmp);
+ MemMove(found + next, tmp, StrLen(tmp));
+ } else {
+ // if val is 0, keep last 0
+ if (next == 8)
+ next = 7;
+ }
+
+ if ((8 - next) > count)
+ count = 8 - next;
+
+ if (count == 0)
+ count = 1;
+
+ len = maxLen - (found - ioStr) - (8 - count);
+ MemSet(found, next, fill);
+ MemMove(found, found + (8 - count), len);
+
+ // ... and upper case
+ if (mod == 'x') {
+ while (count--) {
+ if (*found >='A' && *found <='F')
+ *found = (*found + 32);
+ found++;
+ }
+ }
+ }
+}
+
+Int32 vsprintf(Char* s, const Char* formatStr, _Palm_va_list argParam) {
+ Char format[256], result[256], tmp[32];
+
+ Char *found, *mod, *num;
+ UInt32 next;
+ Boolean zero;
+ Int16 count, len;
+
+ MemSet(format, sizeof(format), 'x');
+ MemSet(result, sizeof(result), 'y');
+ MemSet(tmp, sizeof(tmp), 'z');
+
+ StrCopy(format,formatStr); // copy actual formatStr to temp buffer
+ next = 0; // start of the string
+
+ while (found = StrChr(format + next, '%')) {
+ mod = found + 1;
+
+ if (*mod == '%') { // just a % ?
+ mod++;
+
+ } else {
+ if (*mod == '+' ||
+ *mod == '-' ||
+ *mod == ' ' ) // skip
+ mod++;
+
+ if (*mod == '0' ||
+ *mod == '.' ) {
+ *mod++ = '0';
+ zero = true;
+ } else {
+ zero = false;
+ }
+
+ num = mod;
+ while ( *mod >= '0' &&
+ *mod <= '9' ) // search format char
+ mod++;
+
+ // get the numeric value
+ if (num < mod) {
+ StrNCopy(tmp, num, mod - num);
+ tmp[mod - num] = 0;
+ count = StrAToI(tmp);
+ } else {
+ count = 0;
+ }
+
+ if (*mod == 'l') // already set to %...l(x) ?
+ mod++;
+
+ // prepare new format
+//#if !defined(PALMOS_ARM)
+ if (*mod == 'c') {
+ StrCopy(tmp, "`c`%c%c");
+
+ } else
+//#endif
+ if (*mod == 'p') {
+ StrCopy(tmp, "%08lX"); // %x = %08X in palmos
+
+ } else {
+ len = 0;
+
+ switch (*mod) {
+ case 'x':
+ case 'X':
+ case 'o':
+ tmp[0] = '`';
+ tmp[1] = (zero) ? '0' : ' ';
+ tmp[2] = *mod;
+ StrIToA(tmp + 3, count);
+ len += StrLen(tmp);
+ tmp[len++] = '`';
+ tmp[len] = 0;
+
+ if (*mod == 'o') { // set as base 10 num and convert later
+ *mod = 'd';
+ count = 8; // force 8char
+ }
+
+ break;
+ }
+
+ StrNCopy(tmp + len, found, (num - found));
+ len += (num - found);
+
+ if (count) {
+ StrIToA(tmp + len, count);
+ len += StrLen(tmp + len);
+ }
+
+ if (*mod == 'd' ||
+ *mod == 'i' ||
+ *mod == 'x' ||
+ *mod == 'X' ||
+ *mod == 'u'
+ ) {
+ tmp[len++] = 'l';
+ }
+
+ tmp[len + 0] = *mod;
+ tmp[len + 1] = 0;
+ }
+
+ mod++;
+ MemMove(found + StrLen(tmp), mod, StrLen(mod) + 1);
+ StrNCopy(found, tmp, StrLen(tmp));
+ mod = found + StrLen(tmp);
+ }
+
+ next = (mod - format);
+ }
+
+ // Copy result in a temp buffer to process last formats
+ StrVPrintF(result, format, argParam);
+//#if !defined(PALMOS_ARM)
+ StrProcC_(result, 256);
+//#endif
+ StrProcXO(result, 256, tmp);
+ StrCopy(s, result);
+
+ return StrLen(s);
+}
+
+#endif
diff --git a/backends/platform/PalmOS/Src/missing/ext_stdlib.c b/backends/platform/PalmOS/Src/missing/ext_stdlib.c
new file mode 100644
index 0000000000..8c8fbd50bd
--- /dev/null
+++ b/backends/platform/PalmOS/Src/missing/ext_stdlib.c
@@ -0,0 +1,117 @@
+/* ScummVM - Scumm Interpreter
+ * Copyright (C) 2001 Ludvig Strigeus
+ * Copyright (C) 2001-2006 The ScummVM project
+ * Copyright (C) 2002-2006 Chris Apers - PalmOS Backend
+ *
+ * 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * $URL$
+ * $Id$
+ *
+ */
+
+#include <stdlib.h>
+
+#define memNewChunkFlagAllowLarge 0x1000
+SysAppInfoPtr SysGetAppInfo(SysAppInfoPtr *uiAppPP, SysAppInfoPtr *actionCodeAppPP) SYS_TRAP(sysTrapSysGetAppInfo);
+
+#ifdef PALMOS68K
+long strtol(const char *s, char **endptr, int base) {
+ // WARNING : only base = 10 supported
+ long val = StrAToI(s);
+
+ if (endptr) {
+ Char str[maxStrIToALen];
+ StrIToA(str, val);
+
+ if (StrNCompare(s, str, StrLen(str)) == 0)
+ *endptr = (char *)s + StrLen(str);
+ }
+
+ return val;
+}
+#endif
+
+MemPtr __malloc(UInt32 size) {
+ MemPtr newP = NULL;
+
+ if (size <= 65000) {
+ newP = MemPtrNew(size);
+ } else {
+ SysAppInfoPtr appInfoP;
+ UInt16 ownerID;
+ UInt16 attr;
+
+ ownerID = ((SysAppInfoPtr)SysGetAppInfo(&appInfoP, &appInfoP))->memOwnerID;
+ attr = ownerID|memNewChunkFlagAllowLarge|memNewChunkFlagNonMovable;
+
+ newP = MemChunkNew(0, size, attr);
+ }
+
+ return newP;
+}
+
+MemPtr calloc(UInt32 nelem, UInt32 elsize) {
+ MemPtr newP;
+ UInt32 size = (nelem * elsize);
+
+ newP = malloc(size); // was MemGluePtrNew
+
+ if (newP)
+ MemSet(newP,size,0);
+
+ return newP;
+}
+
+Err free(MemPtr memP) {
+ if (memP)
+ return MemPtrFree(memP);
+ return memErrInvalidParam;
+}
+
+MemPtr realloc(MemPtr oldP, UInt32 size) {
+ MemPtr newP;
+
+ if (oldP != NULL)
+ if (MemPtrResize(oldP, size) == 0)
+ return oldP;
+
+ newP = malloc(size); // was MemPtrNew
+
+ if (oldP!=NULL) {
+ MemMove(newP,oldP,MemPtrSize(oldP));
+ MemPtrFree(oldP);
+ }
+
+ return newP;
+}
+
+ErrJumpBuf stdlib_errJumpBuf;
+#define ERR_MAGIC 0xDADA
+
+void exit(Int16 status) {
+ EventType event;
+ event.eType = keyDownEvent;
+
+ event.data.keyDown.chr = vchrLaunch;
+ event.data.keyDown.modifiers = commandKeyMask;
+#ifdef PALMOS_ARM
+ SysEventAddUniqueToQueue(&event, 0, true);
+#else
+ EvtAddUniqueEventToQueue(&event, 0, true);
+#endif
+
+ ErrLongJump(stdlib_errJumpBuf, status == 0 ? 0xDADA : status);
+}
diff --git a/backends/platform/PalmOS/Src/missing/ext_string.c b/backends/platform/PalmOS/Src/missing/ext_string.c
new file mode 100644
index 0000000000..319017f790
--- /dev/null
+++ b/backends/platform/PalmOS/Src/missing/ext_string.c
@@ -0,0 +1,45 @@
+/* ScummVM - Scumm Interpreter
+ * Copyright (C) 2001 Ludvig Strigeus
+ * Copyright (C) 2001-2006 The ScummVM project
+ * Copyright (C) 2002-2006 Chris Apers - PalmOS Backend
+ *
+ * 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * $URL$
+ * $Id$
+ *
+ */
+
+#include <string.h>
+
+#ifdef PALMOS_68K
+void *memchr(const void *s, int c, UInt32 n) {
+ UInt32 chr;
+ for(chr = 0; chr < n;chr++,((UInt8 *)s)++)
+ if ( *((UInt8 *)s) == c)
+ return (void *)s;
+
+ return NULL;
+}
+
+Char *strdup(const Char *s1) {
+ Char* buf = (Char *)MemPtrNew(StrLen(s1)+1);
+
+ if(buf)
+ StrCopy(buf, s1);
+
+ return buf;
+}
+#endif
diff --git a/backends/platform/PalmOS/Src/missing/ext_time.c b/backends/platform/PalmOS/Src/missing/ext_time.c
new file mode 100644
index 0000000000..5de64062b0
--- /dev/null
+++ b/backends/platform/PalmOS/Src/missing/ext_time.c
@@ -0,0 +1,85 @@
+/* ScummVM - Scumm Interpreter
+ * Copyright (C) 2001 Ludvig Strigeus
+ * Copyright (C) 2001-2006 The ScummVM project
+ * Copyright (C) 2002-2006 Chris Apers - PalmOS Backend
+ *
+ * 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * $URL$
+ * $Id$
+ *
+ */
+
+#include <time.h>
+
+time_t time(time_t *tloc) {
+ // get ROM version
+ UInt32 romVersion;
+ Err e = FtrGet(sysFtrCreator, sysFtrNumROMVersion, &romVersion);
+
+ // since 1/1/1904 12AM.
+ UInt32 secs = TimGetSeconds();
+
+ // form 1/1/1904 12AM to 1/1/1970 12AM
+ DateTimeType Epoch = {0, 0, 0, 1, 1, 1970, 0};
+
+ secs -= TimDateTimeToSeconds(&Epoch);
+
+ // DST really supported from OS v4.0
+ if (romVersion >= sysMakeROMVersion(4,0,0,sysROMStageRelease,0))
+ secs -= (PrefGetPreference(prefTimeZone) + PrefGetPreference(prefDaylightSavingAdjustment)) * 60;
+ else
+ secs -= (PrefGetPreference(prefMinutesWestOfGMT) - 720) * 60;
+
+ if (tloc)
+ *tloc = secs;
+
+ return (secs);
+}
+
+
+struct tm *localtime(const time_t *timer) {
+ static struct tm tmDate;
+ DateTimeType dt;
+ UInt32 secs = *timer;
+
+ // get ROM version
+ UInt32 romVersion;
+ Err e = FtrGet(sysFtrCreator, sysFtrNumROMVersion, &romVersion);
+
+ // form 1/1/1904 12AM to 1/1/1970 12AM
+ DateTimeType Epoch = {0, 0, 0, 1, 1, 1970, 0};
+
+ // timer supposed to be based on Epoch
+ secs += TimDateTimeToSeconds(&Epoch);
+
+ // DST really supported from OS v4.0
+ if (romVersion >= sysMakeROMVersion(4,0,0,sysROMStageRelease,0))
+ secs += (PrefGetPreference(prefTimeZone) + PrefGetPreference(prefDaylightSavingAdjustment)) * 60;
+ else
+ secs += (PrefGetPreference(prefMinutesWestOfGMT) - 720) * 60; // no sure about this one
+
+ TimSecondsToDateTime (secs, &dt);
+
+ tmDate.tm_sec = dt.second;
+ tmDate.tm_min = dt.minute;
+ tmDate.tm_hour = dt.hour;
+ tmDate.tm_mday = dt.day;
+ tmDate.tm_mon = dt.month - 1;
+ tmDate.tm_year = dt.year - 1900;
+ tmDate.tm_wday = dt.weekDay;
+
+ return &tmDate;
+}
diff --git a/backends/platform/PalmOS/Src/missing/ext_unistd.c b/backends/platform/PalmOS/Src/missing/ext_unistd.c
new file mode 100644
index 0000000000..91f2e8e3e5
--- /dev/null
+++ b/backends/platform/PalmOS/Src/missing/ext_unistd.c
@@ -0,0 +1,41 @@
+/* ScummVM - Scumm Interpreter
+ * Copyright (C) 2001 Ludvig Strigeus
+ * Copyright (C) 2001-2006 The ScummVM project
+ * Copyright (C) 2002-2006 Chris Apers - PalmOS Backend
+ *
+ * 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * $URL$
+ * $Id$
+ *
+ */
+
+#include <unistd.h>
+
+const Char *gUnistdCWD = NULL;
+
+// currently used only to retreive savepath
+Char *getcwd(Char *buf, UInt32 size) {
+ Char *copy = buf;
+
+ if (gUnistdCWD) {
+ if (!copy)
+ copy = (Char *)MemPtrNew(StrLen(gUnistdCWD)); // this may never occured
+
+ StrCopy(copy, gUnistdCWD);
+ }
+
+ return copy;
+} \ No newline at end of file
diff --git a/backends/platform/PalmOS/Src/missing/fcntl.h b/backends/platform/PalmOS/Src/missing/fcntl.h
new file mode 100644
index 0000000000..59daa2ae05
--- /dev/null
+++ b/backends/platform/PalmOS/Src/missing/fcntl.h
@@ -0,0 +1,42 @@
+/* ScummVM - Scumm Interpreter
+ * Copyright (C) 2001 Ludvig Strigeus
+ * Copyright (C) 2001-2006 The ScummVM project
+ * Copyright (C) 2002-2006 Chris Apers - PalmOS Backend
+ *
+ * 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * $URL$
+ * $Id$
+ *
+ */
+
+#ifndef FCNTL_H
+#define FCNTL_H
+
+#define O_TEXT 0x0 /* 960827: Added this for Visual C++ compatibility. */
+#define O_RDWR 0x1 /* open the file in read/write mode */ /*- mm 980420 -*/
+#define O_RDONLY 0x2 /* open the file in read only mode */ /*- mm 980420 -*/
+#define O_WRONLY 0x4 /* open the file in write only mode */ /*- mm 980420 -*/
+#define O_APPEND 0x0100 /* open the file in append mode */
+#define O_CREAT 0x0200 /* create the file if it doesn't exist */
+#define O_EXCL 0x0400 /* if the file already exists don't create it again */
+#define O_TRUNC 0x0800 /* truncate the file after opening it */
+#define O_NRESOLVE 0x1000 /* Don't resolve any aliases */
+#define O_ALIAS 0x2000 /* Open alias file (if the file is an alias) */
+#define O_RSRC 0x4000 /* Open the resource fork */
+#define O_BINARY 0x8000 /* open the file in binary mode (default is text mode) */
+#define F_DUPFD 0x0 /* return a duplicate file descriptor */
+
+#endif
diff --git a/backends/platform/PalmOS/Src/missing/math.h b/backends/platform/PalmOS/Src/missing/math.h
new file mode 100644
index 0000000000..eca2d9de08
--- /dev/null
+++ b/backends/platform/PalmOS/Src/missing/math.h
@@ -0,0 +1,38 @@
+/* ScummVM - Scumm Interpreter
+ * Copyright (C) 2001 Ludvig Strigeus
+ * Copyright (C) 2001-2006 The ScummVM project
+ * Copyright (C) 2002-2006 Chris Apers - PalmOS Backend
+ *
+ * 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * $URL$
+ * $Id$
+ *
+ */
+
+#ifndef __MATH_H__
+#define __MATH_H__
+
+#ifndef PALMOS_ARM
+# include "mathlib.h"
+#else
+# include "matharm.h"
+#endif
+
+#ifndef M_PI
+# define M_PI 3.14159265358979323846
+#endif
+
+#endif
diff --git a/backends/platform/PalmOS/Src/missing/memory.h b/backends/platform/PalmOS/Src/missing/memory.h
new file mode 100644
index 0000000000..f57990b19d
--- /dev/null
+++ b/backends/platform/PalmOS/Src/missing/memory.h
@@ -0,0 +1,25 @@
+/* ScummVM - Scumm Interpreter
+ * Copyright (C) 2001 Ludvig Strigeus
+ * Copyright (C) 2001-2006 The ScummVM project
+ * Copyright (C) 2002-2006 Chris Apers - PalmOS Backend
+ *
+ * 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * $URL$
+ * $Id$
+ *
+ */
+
+ #include "string.h" \ No newline at end of file
diff --git a/backends/platform/PalmOS/Src/missing/stdio.h b/backends/platform/PalmOS/Src/missing/stdio.h
new file mode 100644
index 0000000000..490da720a5
--- /dev/null
+++ b/backends/platform/PalmOS/Src/missing/stdio.h
@@ -0,0 +1,103 @@
+/* ScummVM - Scumm Interpreter
+ * Copyright (C) 2001 Ludvig Strigeus
+ * Copyright (C) 2001-2006 The ScummVM project
+ * Copyright (C) 2002-2006 Chris Apers - PalmOS Backend
+ *
+ * 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * $URL$
+ * $Id$
+ *
+ */
+
+#ifndef __STDIO_H__
+#define __STDIO_H__
+
+#include "palmversion.h"
+#include <stdarg.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+typedef void (*LedProc)(Boolean show);
+typedef UInt32 size_t;
+
+typedef struct {
+ FileRef fileRef;
+ UInt32 cacheSize, bufSize, bufPos;
+ UInt8 *cache;
+ UInt16 mode, err;
+} FILE;
+
+#undef stdin
+#undef stdout
+#undef stderr
+
+#define stdin 0
+#define stdout (&gStdioOutput)
+#define stderr (&gStdioOutput)
+
+#undef SEEK_SET
+#undef SEEK_CUR
+#undef SEEK_END
+
+#define SEEK_SET vfsOriginBeginning
+#define SEEK_CUR vfsOriginCurrent
+#define SEEK_END vfsOriginEnd
+
+extern FILE gStdioOutput;
+
+void StdioInit (UInt16 volRefNum, const Char *output);
+void StdioSetLedProc (LedProc ledProc);
+void StdioSetCacheSize (UInt32 s);
+void StdioRelease ();
+
+/* missing functions in 68k MSL (some are defined in ARM) */
+#define clearerr(a)
+#define fflush(a)
+#define getc(a) fgetc(a)
+#define vsnprintf(a,b,c,d) vsprintf(a,c,d)
+
+UInt16 fclose (FILE *stream);
+UInt16 feof (FILE *stream);
+UInt16 ferror (FILE *stream);
+Char *fgets (Char *s, UInt32 n, FILE *stream);
+Int16 fgetc (FILE *stream);
+FILE *fopen (const Char *filename, const Char *type);
+UInt32 fread (void *ptr, UInt32 size, UInt32 nitems, FILE *stream);
+UInt32 fwrite (const void *ptr, UInt32 size, UInt32 nitems, FILE *stream);
+Int16 fseek (FILE *stream, Int32 offset, Int32 whence);
+Int32 ftell (FILE *stream);
+
+Int32 fprintf (FILE *stream, const Char *formatStr, ...);
+Int32 printf (const Char* formatStr, ...);
+Int32 sprintf (Char* s, const Char* formatStr, ...);
+Int32 snprintf (Char* s, UInt32 len, const Char* formatStr, ...);
+Int32 vsprintf (Char* s, const Char* formatStr, _Palm_va_list argParam);
+
+/* ARM MSL only */
+#ifdef PALMOS_ARM
+#undef vsnprintf
+
+int vsnprintf (char *str, size_t size, const char *format, va_list ap);
+int sscanf ( char * buffer, const char * format, ...);
+#endif
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
diff --git a/backends/platform/PalmOS/Src/missing/stdlib.h b/backends/platform/PalmOS/Src/missing/stdlib.h
new file mode 100644
index 0000000000..8b1c959c01
--- /dev/null
+++ b/backends/platform/PalmOS/Src/missing/stdlib.h
@@ -0,0 +1,88 @@
+/* ScummVM - Scumm Interpreter
+ * Copyright (C) 2001 Ludvig Strigeus
+ * Copyright (C) 2001-2006 The ScummVM project
+ * Copyright (C) 2002-2006 Chris Apers - PalmOS Backend
+ *
+ * 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * $URL$
+ * $Id$
+ *
+ */
+
+#ifndef STDLIB_H
+#define STDLIB_H
+
+#include "palmversion.h"
+
+#ifdef PALMOS_68K
+#include "MemGlue.h"
+#endif
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/* malloc stuff */
+#if defined(COMPILE_ZODIAC)
+# define malloc MemPtrNew
+#elif defined(COMPILE_OS5) && defined(PALMOS_ARM)
+# define malloc __malloc
+#else
+# define malloc MemGluePtrNew
+#endif
+
+/* custom exit (true exit !) */
+extern ErrJumpBuf stdlib_errJumpBuf;
+#define DO_EXIT( code ) \
+ if (ErrSetJump(stdlib_errJumpBuf) == 0) { code }
+
+/* mapped to system functions */
+#define atoi StrAToI
+#define atol StrAToI
+#define abs(a) ((a) < 0 ? -(a) : (a))
+#define qsort(a,b,c,d) SysQSort((a), (b), (c), (CmpFuncPtr)(&d), 0);
+#define rand() SysRandom(0)
+#define abort()
+#define strtoul(a,b,c) ((unsigned long)strtol(a,b,c))
+
+MemPtr __malloc (UInt32);
+MemPtr calloc (UInt32 nelem, UInt32 elsize);
+void exit (Int16 status);
+Err free (MemPtr memP);
+MemPtr realloc (MemPtr oldP, UInt32 size);
+long strtol (const char *s, char **endptr, int base);
+
+/* already defined in MSL */
+void *bsearch (const void *key, const void *base, UInt32 nmemb, UInt32 size, int (*compar)(const void *, const void *));
+
+/* ARM MSL only */
+#ifdef PALMOS_ARM
+#undef qsort
+#undef strtol
+#undef strtoul
+
+typedef int (*_compare_function)(const void*, const void*);
+
+void qsort (void * table_base, UInt32 num_members, UInt32 member_size, _compare_function compare_members);
+long int strtol (const char *nptr, char **endptr, int base);
+unsigned long int strtoul (const char *nptr, char **endptr,int base);
+#endif
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
diff --git a/backends/platform/PalmOS/Src/missing/string.h b/backends/platform/PalmOS/Src/missing/string.h
new file mode 100644
index 0000000000..bb250dfe9b
--- /dev/null
+++ b/backends/platform/PalmOS/Src/missing/string.h
@@ -0,0 +1,66 @@
+/* ScummVM - Scumm Interpreter
+ * Copyright (C) 2001 Ludvig Strigeus
+ * Copyright (C) 2001-2006 The ScummVM project
+ * Copyright (C) 2002-2006 Chris Apers - PalmOS Backend
+ *
+ * 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * $URL$
+ * $Id$
+ *
+ */
+
+#ifndef PALM_STRING_H
+#define PALM_STRING_H
+
+#include "palmversion.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/* mapped to system functions */
+#define memcmp MemCmp
+#define memcpy MemMove
+#define memmove MemMove
+#define memset(a,b,c) MemSet(a,c,b)
+#define strcat StrCat
+#define strncat StrNCat
+#define strchr StrChr
+#define strcmp StrCompare
+#define strcpy StrCopy
+#define strncpy StrNCopy
+#define stricmp StrCaselessCompare
+#define strnicmp StrNCaselessCompare
+#define strlen StrLen
+#define strncmp StrNCompare
+#define strstr StrStr
+
+/* missing functions in 68k MSL */
+void *memchr (const void *s, int c, UInt32 n);
+Char *strdup (const Char *strSource);
+
+/* already defined in MSL */
+Char *strtok (Char *str, const Char *sep);
+Char *strrchr (const Char *s, int c);
+Char *strpbrk (const Char *s1, const Char *s2);
+UInt32 strspn (const Char *s1, const Char *s2);
+UInt32 strcspn (const Char *s1, const Char *s2);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
diff --git a/backends/platform/PalmOS/Src/missing/sys/stat.h b/backends/platform/PalmOS/Src/missing/sys/stat.h
new file mode 100644
index 0000000000..da84fa5f6b
--- /dev/null
+++ b/backends/platform/PalmOS/Src/missing/sys/stat.h
@@ -0,0 +1 @@
+/* nothing */
diff --git a/backends/platform/PalmOS/Src/missing/time.h b/backends/platform/PalmOS/Src/missing/time.h
new file mode 100644
index 0000000000..3de16f4517
--- /dev/null
+++ b/backends/platform/PalmOS/Src/missing/time.h
@@ -0,0 +1,55 @@
+/* ScummVM - Scumm Interpreter
+ * Copyright (C) 2001 Ludvig Strigeus
+ * Copyright (C) 2001-2006 The ScummVM project
+ * Copyright (C) 2002-2006 Chris Apers - PalmOS Backend
+ *
+ * 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * $URL$
+ * $Id$
+ *
+ */
+
+#ifndef __TIME_H__
+#define __TIME_H__
+
+#include "palmversion.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+typedef UInt32 time_t;
+
+struct tm {
+ Int16 tm_sec; // seconds [0,61]
+ Int16 tm_min; // minutes [0,59]
+ Int16 tm_hour; // hour [0,23]
+ Int16 tm_mday; // day of month [1,31]
+ Int16 tm_mon; // month of year [0,11]
+ Int16 tm_year; // years since 1900
+ Int16 tm_wday; // day of week [0,6] (Sunday = 0)
+ Int16 tm_yday; // day of year [0,365]
+ Int16 tm_isdst; // daylight savings flag
+};
+
+time_t time(time_t *tloc);
+struct tm *localtime(const time_t *timer);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
diff --git a/backends/platform/PalmOS/Src/missing/unistd.h b/backends/platform/PalmOS/Src/missing/unistd.h
new file mode 100644
index 0000000000..400b0e2c39
--- /dev/null
+++ b/backends/platform/PalmOS/Src/missing/unistd.h
@@ -0,0 +1,42 @@
+/* ScummVM - Scumm Interpreter
+ * Copyright (C) 2001 Ludvig Strigeus
+ * Copyright (C) 2001-2006 The ScummVM project
+ * Copyright (C) 2002-2006 Chris Apers - PalmOS Backend
+ *
+ * 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * $URL$
+ * $Id$
+ *
+ */
+
+#ifndef __UNISTD_H__
+#define __UNISTD_H__
+
+#include "palmversion.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+extern const Char *gUnistdCWD;
+
+Char *getcwd(Char *buf, UInt32 size);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif