2012-04-24 01:22:36 +00:00
|
|
|
/*
|
2015-07-15 21:23:19 +00:00
|
|
|
Copyright 2015 Wolfgang Thaller.
|
2012-04-24 01:22:36 +00:00
|
|
|
|
2014-09-14 22:43:30 +00:00
|
|
|
This file is part of Retro68.
|
2012-04-24 01:22:36 +00:00
|
|
|
|
2014-09-14 22:43:30 +00:00
|
|
|
Retro68 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 3 of the License, or
|
|
|
|
(at your option) any later version.
|
2012-04-24 01:22:36 +00:00
|
|
|
|
2014-09-14 22:43:30 +00:00
|
|
|
Retro68 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.
|
2012-04-24 01:22:36 +00:00
|
|
|
|
2015-07-15 21:23:19 +00:00
|
|
|
Under Section 7 of GPL version 3, you are granted additional
|
|
|
|
permissions described in the GCC Runtime Library Exception, version
|
|
|
|
3.1, as published by the Free Software Foundation.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License and
|
|
|
|
a copy of the GCC Runtime Library Exception along with this program;
|
|
|
|
see the files COPYING and COPYING.RUNTIME respectively. If not, see
|
|
|
|
<http://www.gnu.org/licenses/>.
|
2012-04-24 01:22:36 +00:00
|
|
|
*/
|
|
|
|
|
2012-03-29 08:29:41 +00:00
|
|
|
#include <sys/types.h>
|
|
|
|
#include <sys/stat.h>
|
|
|
|
#include <unistd.h>
|
2015-09-15 22:39:03 +00:00
|
|
|
#include <sys/time.h>
|
|
|
|
|
2012-03-29 08:29:41 +00:00
|
|
|
#include <MacMemory.h>
|
|
|
|
#include <Processes.h>
|
|
|
|
|
|
|
|
int isatty(int fd) { return fd >= 0 && fd <= 2; }
|
|
|
|
void *sbrk(long increment)
|
|
|
|
{
|
2014-09-14 22:43:30 +00:00
|
|
|
Debugger();
|
|
|
|
return NewPtrClear(increment);
|
2012-03-29 08:29:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void _exit(int status)
|
|
|
|
{
|
2014-09-30 09:00:33 +00:00
|
|
|
//if(status != 0)
|
|
|
|
// Debugger();
|
2014-09-14 22:43:30 +00:00
|
|
|
ExitToShell();
|
|
|
|
for(;;)
|
|
|
|
;
|
2012-03-29 08:29:41 +00:00
|
|
|
}
|
|
|
|
|
2014-09-30 09:00:33 +00:00
|
|
|
ssize_t _consolewrite(int fd, const void *buf, size_t count);
|
|
|
|
ssize_t _consoleread(int fd, void *buf, size_t count);
|
2014-09-17 01:35:18 +00:00
|
|
|
|
2012-03-29 08:29:41 +00:00
|
|
|
ssize_t write(int fd, const void *buf, size_t count)
|
|
|
|
{
|
2014-09-30 09:00:33 +00:00
|
|
|
return _consolewrite(fd,buf,count);
|
2012-03-29 08:29:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
ssize_t read(int fd, void *buf, size_t count)
|
|
|
|
{
|
2014-09-30 09:00:33 +00:00
|
|
|
return _consoleread(fd,buf,count);
|
2012-03-29 08:29:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int open(const char* name, int flags, mode_t mode)
|
|
|
|
{
|
2014-09-14 22:43:30 +00:00
|
|
|
return -1;
|
2012-03-29 08:29:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int close(int fd)
|
|
|
|
{
|
2014-09-14 22:43:30 +00:00
|
|
|
return -1;
|
2012-03-29 08:29:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int fstat(int fd, struct stat *buf)
|
|
|
|
{
|
2014-09-14 22:43:30 +00:00
|
|
|
return -1;
|
2012-03-29 08:29:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
off_t lseek(int fd, off_t offset, int whence)
|
|
|
|
{
|
2014-09-14 22:43:30 +00:00
|
|
|
return (off_t) -1;
|
2012-03-29 08:29:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int kill(pid_t pid, int sig)
|
|
|
|
{
|
2014-09-14 22:43:30 +00:00
|
|
|
if(pid == 42)
|
|
|
|
_exit(42);
|
|
|
|
else
|
|
|
|
return -1;
|
2012-03-29 08:29:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
pid_t getpid(void)
|
|
|
|
{
|
2014-09-14 22:43:30 +00:00
|
|
|
return 42;
|
2012-03-29 08:29:41 +00:00
|
|
|
}
|
2015-09-15 22:39:03 +00:00
|
|
|
|
|
|
|
int gettimeofday(struct timeval *tp, void *__tz)
|
|
|
|
{
|
|
|
|
/* Classic MacOS's GetDateTime function returns an integer.
|
|
|
|
* TickCount() has a slightly higher resolution, but is independend of the real-time clock.
|
|
|
|
*/
|
|
|
|
unsigned long secs;
|
|
|
|
GetDateTime(&secs);
|
|
|
|
unsigned long ticks = TickCount();
|
|
|
|
|
|
|
|
static unsigned long savedTicks = 0, savedSecs = 0;
|
|
|
|
|
|
|
|
if(!savedSecs)
|
|
|
|
{
|
|
|
|
savedTicks = ticks;
|
|
|
|
savedSecs = secs;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
unsigned long elapsedTicks = ticks - savedTicks;
|
|
|
|
unsigned long elapsedSecs = secs - savedSecs;
|
|
|
|
unsigned long expectedTicks = elapsedSecs * 60 + elapsedSecs * 3 / 20;
|
|
|
|
|
|
|
|
if(expectedTicks > elapsedTicks)
|
|
|
|
savedTicks = ticks;
|
|
|
|
else
|
|
|
|
savedTicks += expectedTicks;
|
|
|
|
savedSecs = secs;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(tp)
|
|
|
|
{
|
|
|
|
tp->tv_sec = secs - 86400 * (365 * 66 + 66/4);
|
|
|
|
tp->tv_usec = (ticks - savedTicks) * 20000000 / 2003;
|
|
|
|
}
|
|
|
|
}
|