diff options
| author | Mathias Agopian <mathias@google.com> | 2009-05-31 23:27:21 -0700 |
|---|---|---|
| committer | Mathias Agopian <mathias@google.com> | 2009-05-31 23:38:37 -0700 |
| commit | f940dc66398f8d1721edd50ab42245a67df685ff (patch) | |
| tree | b74e161031b79c351197fa2951ae5d3e30ce412b /simulator | |
| parent | 9503c3867a6218a33ab76ecca13b6bf9da7da49c (diff) | |
| download | android_development-f940dc66398f8d1721edd50ab42245a67df685ff.tar.gz android_development-f940dc66398f8d1721edd50ab42245a67df685ff.tar.bz2 android_development-f940dc66398f8d1721edd50ab42245a67df685ff.zip | |
get rid of ported.h, move implementation in here (only place it's possibly used -- I'm being conservative).
Diffstat (limited to 'simulator')
| -rw-r--r-- | simulator/app/Android.mk | 3 | ||||
| -rw-r--r-- | simulator/app/ported.cpp | 106 | ||||
| -rw-r--r-- | simulator/app/ported.h | 50 |
3 files changed, 158 insertions, 1 deletions
diff --git a/simulator/app/Android.mk b/simulator/app/Android.mk index 605cd3dad..3ce7cd5db 100644 --- a/simulator/app/Android.mk +++ b/simulator/app/Android.mk @@ -31,7 +31,8 @@ LOCAL_SRC_FILES := \ Semaphore.cpp \ Shmem.cpp \ UserEvent.cpp \ - executablepath_linux.cpp + executablepath_linux.cpp \ + ported.cpp LOCAL_STATIC_LIBRARIES := \ libtinyxml diff --git a/simulator/app/ported.cpp b/simulator/app/ported.cpp new file mode 100644 index 000000000..232b30258 --- /dev/null +++ b/simulator/app/ported.cpp @@ -0,0 +1,106 @@ +/* + * Copyright (C) 2005 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +// +// Ports of standard functions that don't exist on a specific platform. +// +// Note these are NOT in the "android" namespace. +// +#include "ported.h" + +#if defined(NEED_GETTIMEOFDAY) || defined(NEED_USLEEP) +# include <sys/time.h> +# include <windows.h> +#endif + + +#if defined(NEED_GETTIMEOFDAY) +/* + * Replacement gettimeofday() for Windows environments (primarily MinGW). + * + * Ignores "tz". + */ +int gettimeofday(struct timeval* ptv, struct timezone* tz) +{ + long long nsTime; // time in 100ns units since Jan 1 1601 + FILETIME ft; + + if (tz != NULL) { + // oh well + } + + ::GetSystemTimeAsFileTime(&ft); + nsTime = (long long) ft.dwHighDateTime << 32 | + (long long) ft.dwLowDateTime; + // convert to time in usec since Jan 1 1970 + ptv->tv_usec = (long) ((nsTime / 10LL) % 1000000LL); + ptv->tv_sec = (long) ((nsTime - 116444736000000000LL) / 10000000LL); + + return 0; +} +#endif + +#if defined(NEED_USLEEP) +// +// Replacement usleep for Windows environments (primarily MinGW). +// +void usleep(unsigned long usec) +{ + // Win32 API function Sleep() takes milliseconds + ::Sleep((usec + 500) / 1000); +} +#endif + +#if 0 //defined(NEED_PIPE) +// +// Replacement pipe() command for MinGW +// +// The _O_NOINHERIT flag sets bInheritHandle to FALSE in the +// SecurityAttributes argument to CreatePipe(). This means the handles +// aren't inherited when a new process is created. The examples I've seen +// use it, possibly because there's a lot of junk going on behind the +// scenes. (I'm assuming "process" and "thread" are different here, so +// we should be okay spinning up a thread.) The recommended practice is +// to dup() the descriptor you want the child to have. +// +// It appears that unnamed pipes can't do non-blocking ("overlapped") I/O. +// You can't use select() either, since that only works on sockets. The +// Windows API calls that are useful here all operate on a HANDLE, not +// an integer file descriptor, and I don't think you can get there from +// here. The "named pipe" stuff is insane. +// +int pipe(int filedes[2]) +{ + return _pipe(filedes, 0, _O_BINARY | _O_NOINHERIT); +} +#endif + +#if defined(NEED_SETENV) +/* + * MinGW lacks these. For now, just stub them out so the code compiles. + */ +int setenv(const char* name, const char* value, int overwrite) +{ + return 0; +} +void unsetenv(const char* name) +{ +} +char* getenv(const char* name) +{ + return NULL; +} +#endif diff --git a/simulator/app/ported.h b/simulator/app/ported.h new file mode 100644 index 000000000..eb3be01e9 --- /dev/null +++ b/simulator/app/ported.h @@ -0,0 +1,50 @@ +/* + * Copyright (C) 2005 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +// +// Standard functions ported to the current platform. Note these are NOT +// in the "android" namespace. +// +#ifndef _LIBS_UTILS_PORTED_H +#define _LIBS_UTILS_PORTED_H + +#include <sys/time.h> // for timeval + +#ifdef __cplusplus +extern "C" { +#endif + +/* library replacement functions */ +#if defined(NEED_GETTIMEOFDAY) +int gettimeofday(struct timeval* tv, struct timezone* tz); +#endif +#if defined(NEED_USLEEP) +void usleep(unsigned long usec); +#endif +#if defined(NEED_PIPE) +int pipe(int filedes[2]); +#endif +#if defined(NEED_SETENV) +int setenv(const char* name, const char* value, int overwrite); +void unsetenv(const char* name); +char* getenv(const char* name); +#endif + +#ifdef __cplusplus +} +#endif + +#endif // _LIBS_UTILS_PORTED_H |
