diff options
author | Toby Gray <toby.gray@realvnc.com> | 2013-01-16 02:07:29 +0000 |
---|---|---|
committer | Toby Gray <toby.gray@realvnc.com> | 2013-01-23 00:40:18 +0000 |
commit | 244271931a782028fd9bc1cdcdb12200f65cf8d9 (patch) | |
tree | eea17ea7e2e4c8638b26aa5a8984ef1b272a1566 /msvc | |
parent | 790ffc78b008a03c95d10899f53997b504f55c72 (diff) | |
download | android_external_libusbx-244271931a782028fd9bc1cdcdb12200f65cf8d9.tar.gz android_external_libusbx-244271931a782028fd9bc1cdcdb12200f65cf8d9.tar.bz2 android_external_libusbx-244271931a782028fd9bc1cdcdb12200f65cf8d9.zip |
WinCE: Add support for WinCE (sources)
Diffstat (limited to 'msvc')
-rw-r--r-- | msvc/config.h | 10 | ||||
-rw-r--r-- | msvc/errno.h | 100 | ||||
-rw-r--r-- | msvc/missing.c | 80 | ||||
-rw-r--r-- | msvc/missing.h | 29 |
4 files changed, 218 insertions, 1 deletions
diff --git a/msvc/config.h b/msvc/config.h index 730d091..eb05d3d 100644 --- a/msvc/config.h +++ b/msvc/config.h @@ -23,14 +23,22 @@ /* Message logging */ #define ENABLE_LOGGING 1 -/* Windows backend */ +/* Windows/WinCE backend */ +#if defined(_WIN32_WCE) +#define OS_WINCE 1 +#else #define OS_WINDOWS 1 +#endif /* type of second poll() argument */ #define POLL_NFDS_TYPE unsigned int +#if !defined(_WIN32_WCE) + /* Define to 1 if you have the <signal.h> header file. */ #define HAVE_SIGNAL_H 1 /* Define to 1 if you have the <sys/types.h> header file. */ #define HAVE_SYS_TYPES_H 1 + +#endif
\ No newline at end of file diff --git a/msvc/errno.h b/msvc/errno.h new file mode 100644 index 0000000..a1d4f64 --- /dev/null +++ b/msvc/errno.h @@ -0,0 +1,100 @@ +/* + * errno.h + * This file has no copyright assigned and is placed in the Public Domain. + * This file is a part of the mingw-runtime package. + * No warranty is given; refer to the file DISCLAIMER within the package. + * + * Error numbers and access to error reporting. + * + */ + +#ifndef _ERRNO_H_ +#define _ERRNO_H_ + +#include <crtdefs.h> + +/* + * Error numbers. + * TODO: Can't be sure of some of these assignments, I guessed from the + * names given by strerror and the defines in the Cygnus errno.h. A lot + * of the names from the Cygnus errno.h are not represented, and a few + * of the descriptions returned by strerror do not obviously match + * their error naming. + */ +#define EPERM 1 /* Operation not permitted */ +#define ENOFILE 2 /* No such file or directory */ +#define ENOENT 2 +#define ESRCH 3 /* No such process */ +#define EINTR 4 /* Interrupted function call */ +#define EIO 5 /* Input/output error */ +#define ENXIO 6 /* No such device or address */ +#define E2BIG 7 /* Arg list too long */ +#define ENOEXEC 8 /* Exec format error */ +#define EBADF 9 /* Bad file descriptor */ +#define ECHILD 10 /* No child processes */ +#define EAGAIN 11 /* Resource temporarily unavailable */ +#define ENOMEM 12 /* Not enough space */ +#define EACCES 13 /* Permission denied */ +#define EFAULT 14 /* Bad address */ +/* 15 - Unknown Error */ +#define EBUSY 16 /* strerror reports "Resource device" */ +#define EEXIST 17 /* File exists */ +#define EXDEV 18 /* Improper link (cross-device link?) */ +#define ENODEV 19 /* No such device */ +#define ENOTDIR 20 /* Not a directory */ +#define EISDIR 21 /* Is a directory */ +#define EINVAL 22 /* Invalid argument */ +#define ENFILE 23 /* Too many open files in system */ +#define EMFILE 24 /* Too many open files */ +#define ENOTTY 25 /* Inappropriate I/O control operation */ +/* 26 - Unknown Error */ +#define EFBIG 27 /* File too large */ +#define ENOSPC 28 /* No space left on device */ +#define ESPIPE 29 /* Invalid seek (seek on a pipe?) */ +#define EROFS 30 /* Read-only file system */ +#define EMLINK 31 /* Too many links */ +#define EPIPE 32 /* Broken pipe */ +#define EDOM 33 /* Domain error (math functions) */ +#define ERANGE 34 /* Result too large (possibly too small) */ +/* 35 - Unknown Error */ +#define EDEADLOCK 36 /* Resource deadlock avoided (non-Cyg) */ +#define EDEADLK 36 +/* 37 - Unknown Error */ +#define ENAMETOOLONG 38 /* Filename too long (91 in Cyg?) */ +#define ENOLCK 39 /* No locks available (46 in Cyg?) */ +#define ENOSYS 40 /* Function not implemented (88 in Cyg?) */ +#define ENOTEMPTY 41 /* Directory not empty (90 in Cyg?) */ +#define EILSEQ 42 /* Illegal byte sequence */ + +/* + * NOTE: ENAMETOOLONG and ENOTEMPTY conflict with definitions in the + * sockets.h header provided with windows32api-0.1.2. + * You should go and put an #if 0 ... #endif around the whole block + * of errors (look at the comment above them). + */ + +#ifndef RC_INVOKED + +#ifdef __cplusplus +extern "C" { +#endif + +/* + * Definitions of errno. For _doserrno, sys_nerr and * sys_errlist, see + * stdlib.h. + */ +#if defined(_UWIN) || defined(_WIN32_WCE) +#undef errno +extern int errno; +#else +_CRTIMP int* __cdecl _errno(void); +#define errno (*_errno()) +#endif + +#ifdef __cplusplus +} +#endif + +#endif /* Not RC_INVOKED */ + +#endif /* Not _ERRNO_H_ */
\ No newline at end of file diff --git a/msvc/missing.c b/msvc/missing.c new file mode 100644 index 0000000..85d9d6f --- /dev/null +++ b/msvc/missing.c @@ -0,0 +1,80 @@ +/* + * Source file for missing WinCE functionality + * Copyright © 2012 RealVNC Ltd. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library 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 + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#include "missing.h" + +#include <config.h> +#include <libusbi.h> + +#include <windows.h> + +// The registry path to store environment variables +#define ENVIRONMENT_REG_PATH _T("Software\\libusb\\environment") + +/* Workaround getenv not being available on WinCE. + * Instead look in HKLM\Software\libusb\environment */ +char *getenv(const char *name) +{ + static char value[MAX_PATH]; + TCHAR wValue[MAX_PATH]; + WCHAR wName[MAX_PATH]; + DWORD dwType, dwData; + HKEY hkey; + LONG rc; + + if (!name) + return NULL; + + if (MultiByteToWideChar(CP_UTF8, 0, name, -1, wName, MAX_PATH) <= 0) { + usbi_dbg("Failed to convert environment variable name to wide string"); + return NULL; + } + wName[MAX_PATH - 1] = 0; // Be sure it's NUL terminated + + rc = RegOpenKeyEx(HKEY_LOCAL_MACHINE, ENVIRONMENT_REG_PATH, 0, KEY_QUERY_VALUE, &hkey); + if (rc != ERROR_SUCCESS) { + usbi_dbg("Failed to open registry key for getenv with error %d", rc); + return NULL; + } + + // Attempt to read the key + dwData = sizeof(wValue); + rc = RegQueryValueEx(hkey, wName, NULL, &dwType, + (LPBYTE)&wValue, &dwData); + RegCloseKey(hkey); + if (rc != ERROR_SUCCESS) { + usbi_dbg("Failed to read registry key value for getenv with error %d", rc); + return NULL; + } + if (dwType != REG_SZ) { + usbi_dbg("Registry value was of type %d instead of REG_SZ", dwType); + return NULL; + } + + // Success in reading the key, convert from WCHAR to char + if (WideCharToMultiByte(CP_UTF8, 0, + wValue, dwData / sizeof(*wValue), + value, MAX_PATH, + NULL, NULL) <= 0) { + usbi_dbg("Failed to convert environment variable value to narrow string"); + return NULL; + } + value[MAX_PATH - 1] = 0; // Be sure it's NUL terminated + return value; +} diff --git a/msvc/missing.h b/msvc/missing.h new file mode 100644 index 0000000..7846976 --- /dev/null +++ b/msvc/missing.h @@ -0,0 +1,29 @@ +/* + * Header file for missing WinCE functionality + * Copyright © 2012 RealVNC Ltd. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library 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 + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#ifndef MISSING_H +#define MISSING_H + +/* Windows CE doesn't have any APIs to query environment variables. + * + * This contains a registry based implementation of getenv. + */ +char *getenv(const char *name); + +#endif |