]> git.ipfire.org Git - thirdparty/curl.git/commitdiff
build: add Windows CE / CeGCC support, with CI jobs
authorViktor Szakats <commit@vsz.me>
Fri, 10 Jan 2025 10:04:02 +0000 (11:04 +0100)
committerViktor Szakats <commit@vsz.me>
Fri, 21 Feb 2025 12:56:34 +0000 (13:56 +0100)
Make it possible to build curl for Windows CE using the CeGCC toolchain.
With both CMake and autotools, including tests and examples, also in CI.
The build configuration is the default one with Schannel enabled. No
3rd-party dependencies have been tested.

Also revive old code to make Schannel build with Windows CE, including
certificate verification.

Builds have been throughougly tested. But, I've made no functional tests
for this PR. Some parts (esp. file operations, like truncate and seek)
are stubbed out and likely broken as a result. Test servers build, but
they do not work on Windows CE. This patch substitutes `fstat()` calls
with `stat()`, which operate on filenames, not file handles. This may or
may not work and/or may not be secure.

About CeGCC: I used the latest available macOS binary build v0.59.1
r1397 from 2009, in native `mingw32ce` build mode. CeGCC is in effect
MinGW + GCC 4.4.0 + old/classic-mingw Windows headers. It targets
Windows CE v3.0 according to its `_WIN32_WCE` value. It means this PR
restores portions of old/classic-mingw support. It makes the Windows CE
codepath compatible with GCC 4.4.0. It also adds workaround for CMake,
which cannot identify and configure this toolchain out of the box.

Notes:
- CMake doesn't recognize CeGCC/mingw32ce, necessitating tricks as seen
  with Amiga and MS-DOS.
- CMake doesn't set `MINGW` for mingw32ce. Set it and `MINGW32CE`
  manually as a helper variable, in addition to `WINCE` which CMake sets
  based on `CMAKE_SYSTEM_NAME`.
- CMake fails to create an implib for `libcurl.dll`, due to not
  recognizing the platform as a Windowsy one. This patch adds the
  necessary workaround to make it work.
- headers shipping with CeGCC miss some things curl needs for Schannel
  support. Fixed by restoring and renovating code previously deleted
  old-mingw code.
- it's sometime non-trivial to figure out if a fallout is WinCE,
  mingw32ce, old-mingw, or GCC version-specific.
- WinCE is always Unicode. With exceptions: no `wmain`,
  `GetProcAddress()`.
- `_fileno()` is said to convert from `FILE *` to `void *` which is
  a Win32 file `HANDLE`. (This patch doesn't use this, but with further
  effort it probably could be.)
  https://stackoverflow.com/questions/3989545/how-do-i-get-the-file-handle-from-the-fopen-file-structure
- WinCE has no signals, current directory, stdio/CRT file handles, no
  `_get_osfhandle()`, no `errno`, no `errno.h`. Some of this stuff is
  standard C89, yet missing from this platform. Microsoft expects
  Windows CE apps to use Win32 file API and `FILE *` exclusively.
- revived CeGCC here (not tested for this PR):
  https://building.enlyze.com/posts/a-new-windows-ce-x86-compiler-in-2024/

On `UNDER_CE` vs. `_WIN32_WCE`: (This patch settled on `UNDER_CE`)

- A custom VS2008 WinCE toolchain does not set any of these.
  The compiler binaries don't contain these strings, and has no compiler
  option for targeting WinCE, hinting that a vanilla toolchain isn't
  setting any of them either.
- `UNDER_CE` is automatically defined by the CeGCC compiler.
  https://cegcc.sourceforge.net/docs/details.html
- `UNDER_CE` is similar to `_WIN32`, except it's not set automatically
  by all compilers. It's not supposed to have any value, like a version.
  (Though e.g. OpenSSL sets it to a version)
- `_WIN32_WCE` is the CE counterpart of the non-CE `_WIN32_WINNT` macro.
  That does return the targeted Windows CE version.
- `_WIN32_WCE` is not defined by compilers, and relies on a header
  setting it to a default, or the build to set it to the desired target
  version. This is also how `_WIN32_WINNT` works.
- `_WIN32_WCE` default is set by `windef.h` in CeGCC.
- `_WIN32_WCE` isn't set to a default by MSVC Windows CE headers (the
  ones I checked at least).
- CMake sets `_WIN32_WCE=<ver>`, `UNDER_CE`, `WINCE` for MSVC WinCE.
- `_WIN32_WCE` seems more popular in other projects, including CeGCC
  itself. `zlib` is a notable exception amongst curl dependencies,
  which uses `UNDER_CE`.
- Since `_WIN32_WCE` needs "certain" headers to have it defined, it's
  undefined depending on headers included beforehand.
- `curl/curl.h` re-uses `_WIN32_WCE`'s as a self-guard, relying on
  its not-(necessarily)-defined-by-default property:
  https://github.com/curl/curl/blob/25b445e4796bcbf9f842de686a8c384b30f6c2a2/include/curl/curl.h#L77

Toolchain downloads:
- Windows:
  https://downloads.sourceforge.net/cegcc/cegcc/0.59.1/cegcc_mingw32ce_cygwin1.7_r1399.tar.bz2
- macOS Intel:
  https://downloads.sourceforge.net/cegcc/cegcc/0.59.1/cegcc_mingw32ce_snowleopard_r1397.tar.bz2

Closes #15975

89 files changed:
.github/workflows/windows.yml
CMake/CurlSymbolHiding.cmake
CMake/win32-cache.cmake
CMakeLists.txt
acinclude.m4
configure.ac
docs/examples/anyauthput.c
docs/examples/block_ip.c
docs/examples/externalsocket.c
docs/examples/fileupload.c
docs/examples/ftpupload.c
docs/examples/ftpuploadresume.c
docs/examples/http2-download.c
docs/examples/http2-upload.c
docs/examples/sftpuploadresume.c
include/curl/curl.h
include/curl/system.h
lib/asyn-thread.c
lib/cf-socket.c
lib/config-win32.h
lib/connect.c
lib/curl_multibyte.c
lib/curl_setup.h
lib/curl_setup_once.h
lib/curl_sspi.c
lib/curl_sspi.h
lib/curl_threads.c
lib/curl_threads.h
lib/easy.c
lib/file.c
lib/fopen.c
lib/ftp.c
lib/getenv.c
lib/hostip.c
lib/inet_ntop.c
lib/inet_pton.c
lib/memdebug.c
lib/mprintf.c
lib/rename.c
lib/socketpair.c
lib/strerror.c
lib/strerror.h
lib/system_win32.c
lib/transfer.c
lib/urlapi.c
lib/vtls/rustls.c
lib/vtls/schannel.c
lib/vtls/schannel_verify.c
lib/vtls/vtls_scache.c
src/CMakeLists.txt
src/terminal.c
src/tool_cb_hdr.c
src/tool_cb_rea.c
src/tool_cb_see.c
src/tool_cb_wrt.c
src/tool_dirhie.c
src/tool_doswin.c
src/tool_doswin.h
src/tool_formparse.c
src/tool_getparam.c
src/tool_getpass.c
src/tool_main.c
src/tool_operate.c
src/tool_paramhlp.c
src/tool_parsecfg.c
src/tool_setup.h
src/tool_urlglob.c
src/tool_util.c
src/tool_util.h
tests/http/clients/h2-upgrade-extreme.c
tests/http/clients/tls-session-reuse.c
tests/libtest/lib3026.c
tests/libtest/lib3207.c
tests/libtest/lib505.c
tests/libtest/lib525.c
tests/libtest/lib541.c
tests/libtest/lib556.c
tests/libtest/lib582.c
tests/libtest/testutil.c
tests/server/Makefile.inc
tests/server/mqttd.c
tests/server/resolve.c
tests/server/rtspd.c
tests/server/sockfilt.c
tests/server/socksd.c
tests/server/sws.c
tests/server/tftpd.c
tests/server/util.c
tests/unit/unit2600.c

index cbd9026f0b11b5d10cfc9886eff7c4884e1fa715..9b4abe7c3adb52babe1bc0daf6103f8dd9d4aa09 100644 (file)
@@ -590,6 +590,111 @@ jobs:
             make -C bld -j5 examples
           fi
 
+  wince:
+    name: "mingw32ce, ${{ matrix.build == 'cmake' && 'CM' || 'AM' }} 4.4.0-arm schannel"
+    runs-on: 'macos-latest'
+    timeout-minutes: 10
+    env:
+      toolchain-version: '0.59.1'
+    strategy:
+      matrix:
+        build: [autotools, cmake]
+      fail-fast: false
+    steps:
+      - name: 'install packages'
+        if: ${{ matrix.build == 'autotools' }}
+        run: |
+          echo automake libtool | xargs -Ix -n1 echo brew '"x"' > /tmp/Brewfile
+          while [[ $? == 0 ]]; do for i in 1 2 3; do brew update && brew bundle install --no-lock --file /tmp/Brewfile && break 2 || { echo Error: wait to try again; sleep 10; } done; false Too many retries; done
+
+      - name: 'cache compiler (mingw32ce)'
+        uses: actions/cache@1bd1e32a3bdc45362d1e726936510720a7c30a57 # v4
+        id: cache-compiler
+        with:
+          path: ~/opt/mingw32ce
+          key: ${{ runner.os }}-mingw32ce-${{ env.toolchain-version }}-amd64
+
+      - name: 'install compiler (mingw32ce)'
+        if: ${{ steps.cache-compiler.outputs.cache-hit != 'true' }}
+        run: |
+          cd "${HOME}" || exit 1
+          curl --disable --fail --silent --show-error --connect-timeout 15 --max-time 120 --retry 3 --retry-connrefused --proto-redir =https \
+            --location 'https://downloads.sourceforge.net/cegcc/cegcc/${{ env.toolchain-version }}/cegcc_mingw32ce_snowleopard_r1397.tar.bz2' | tar -x
+          ls -l
+
+      - uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4
+
+      - name: 'configure'
+        run: |
+          MINGW32CE_ROOT="${HOME}/opt/mingw32ce"
+          if [ '${{ matrix.build }}' = 'cmake' ]; then
+            cmake -B bld \
+              -DCMAKE_SYSTEM_NAME=WindowsCE \
+              -DCMAKE_SYSTEM_VERSION=8.0 \
+              -DCMAKE_SYSTEM_PROCESSOR=arm \
+              -DCMAKE_C_COMPILER_TARGET=arm-wince-mingw32ce \
+              -DCMAKE_C_COMPILER="${MINGW32CE_ROOT}/bin/arm-mingw32ce-gcc" \
+              -DCMAKE_RC_COMPILER="${MINGW32CE_ROOT}/bin/arm-mingw32ce-windres" \
+              -DMINGW32CE_LIBRARY_DIR="${MINGW32CE_ROOT}/arm-mingw32ce/lib" \
+              -DCMAKE_IGNORE_PREFIX_PATH="$(brew --prefix)" \
+              -DCMAKE_UNITY_BUILD=ON -DCURL_TEST_BUNDLES=ON \
+              -DBUILD_SHARED_LIBS=ON -DBUILD_STATIC_LIBS=ON -DBUILD_STATIC_CURL=OFF \
+              -DCURL_WERROR=ON \
+              -DCURL_USE_SCHANNEL=ON \
+              -DCURL_USE_LIBPSL=OFF
+          else
+            autoreconf -fi
+            mkdir bld && cd bld && ../configure --disable-dependency-tracking --enable-unity --enable-test-bundles --enable-warnings --enable-werror \
+              ac_cv_prog_cc_c99=no \
+              CC="${MINGW32CE_ROOT}/bin/arm-mingw32ce-gcc" \
+              AR="${MINGW32CE_ROOT}/bin/arm-mingw32ce-ar" \
+              RANLIB="${MINGW32CE_ROOT}/bin/arm-mingw32ce-ranlib" \
+              RC="${MINGW32CE_ROOT}/bin/arm-mingw32ce-windres" \
+              --host=arm-wince-mingw32ce \
+              --with-schannel \
+              --without-libpsl \
+              --disable-shared
+          fi
+
+      - name: 'configure log'
+        if: ${{ !cancelled() }}
+        run: cat bld/config.log bld/CMakeFiles/CMake*.yaml 2>/dev/null || true
+
+      - name: 'curl_config.h'
+        run: |
+          echo '::group::raw'; cat bld/lib/curl_config.h || true; echo '::endgroup::'
+          grep -F '#define' bld/lib/curl_config.h | sort || true
+
+      - name: 'build'
+        run: |
+          if [ '${{ matrix.build }}' = 'cmake' ]; then
+            cmake --build bld
+          else
+            make -j5 -C bld
+          fi
+
+      - name: 'curl info'
+        run: |
+          find . \( -name '*.exe' -o -name '*.dll' -o -name '*.a' \) -exec file '{}' \;
+
+      - name: 'build tests'
+        if: ${{ matrix.build == 'cmake' }}  # skip for autotools to save time
+        run: |
+          if [ '${{ matrix.build }}' = 'cmake' ]; then
+            cmake --build bld --target testdeps
+          else
+            make -j5 -C bld -C tests
+          fi
+
+      - name: 'build examples'
+        if: ${{ matrix.build == 'cmake' }}  # skip for autotools to save time
+        run: |
+          if [ '${{ matrix.build }}' = 'cmake' ]; then
+            cmake --build bld --target curl-examples
+          else
+            make -j5 -C bld examples
+          fi
+
   msvc:
     name: 'msvc, CM ${{ matrix.arch }}-${{ matrix.plat }} ${{ matrix.name }}'
     runs-on: windows-latest
index 31a97cb107085c7fb3ed07455a6d4db6bdaf050e..b962cf0e6ca1568a0b35914ea7b0e21e44784e99 100644 (file)
@@ -29,7 +29,7 @@ if(WIN32 AND (ENABLE_DEBUG OR ENABLE_CURLDEBUG))
   # e.g. curl_easy_perform_ev() or curl_dbg_*(),
   # so disable symbol hiding for debug builds and for memory tracking.
   set(CURL_HIDDEN_SYMBOLS OFF)
-elseif(DOS OR AMIGA)
+elseif(DOS OR AMIGA OR MINGW32CE)
   set(CURL_HIDDEN_SYMBOLS OFF)
 endif()
 
index 5f292a2d70d9060c8456887e87526716f470a0f8..05a209971d14da6385cd2a330e5c3d6c81b0f3fc 100644 (file)
@@ -44,6 +44,10 @@ if(MINGW)
   set(HAVE_UTIME_H 1)  # wrapper to sys/utime.h
   set(HAVE_DIRENT_H 1)
   set(HAVE_OPENDIR 1)
+  if(MINGW32CE)
+    set(HAVE_STRTOK_R 0)
+    set(HAVE_FILE_OFFSET_BITS 0)
+  endif()
 else()
   set(HAVE_LIBGEN_H 0)
   set(HAVE_FTRUNCATE 0)
@@ -191,3 +195,16 @@ set(STDC_HEADERS 1)
 
 set(HAVE_SIZEOF_SUSECONDS_T 0)
 set(HAVE_SIZEOF_SA_FAMILY_T 0)
+
+if(WINCE)  # Windows CE exceptions
+  set(HAVE_LOCALE_H 0)
+  set(HAVE_GETADDRINFO 0)
+  set(HAVE_FREEADDRINFO 0)
+  set(HAVE_SETLOCALE 0)
+  set(HAVE_SOCKADDR_IN6_SIN6_SCOPE_ID 0)
+  set(HAVE_SIGNAL 0)
+  set(HAVE_SETMODE 0)
+  if(MINGW32CE)
+    set(HAVE__SETMODE 0)
+  endif()
+endif()
index 764b6fcc0b6c355284dc809b2f85ecb59895eb1f..3e8d112b39de2e8b85557d6ebbc7b94b78360c15 100644 (file)
@@ -91,6 +91,33 @@ if(WINDOWS_STORE AND MINGW)  # mingw UWP build
   # CMake (as of v3.31.2) gets confused and applies the MSVC rc.exe command-line
   # template to windres. Reset it to the windres template via 'Modules/Platform/Windows-windres.cmake':
   set(CMAKE_RC_COMPILE_OBJECT "<CMAKE_RC_COMPILER> -O coff <DEFINES> <INCLUDES> <FLAGS> <SOURCE> <OBJECT>")
+elseif(WIN32 AND WINCE AND CMAKE_COMPILER_IS_GNUCC)  # mingw32ce build
+  if(NOT MINGW32CE_LIBRARY_DIR)
+    message(FATAL_ERROR "Set MINGW32CE_LIBRARY_DIR variable to the mingw32ce platform library directory.")
+  endif()
+
+  set(MINGW 1)
+  set(MINGW32CE 1)
+
+  # Build implib with libcurl DLL. Copied from CMake's 'Modules/Platform/Windows-GNU.cmake'.
+  set(CMAKE_C_CREATE_SHARED_LIBRARY "<CMAKE_C_COMPILER> <CMAKE_SHARED_LIBRARY_C_FLAGS> <LANGUAGE_COMPILE_FLAGS> <LINK_FLAGS>")
+  string(APPEND CMAKE_C_CREATE_SHARED_LIBRARY " <CMAKE_SHARED_LIBRARY_CREATE_C_FLAGS> -o <TARGET> -Wl,--out-implib,<TARGET_IMPLIB>")
+  string(APPEND CMAKE_C_CREATE_SHARED_LIBRARY " ${CMAKE_GNULD_IMAGE_VERSION} <OBJECTS> <LINK_LIBRARIES>")
+
+  # Build resources. Copied from CMake's 'Modules/Platform/Windows-windres.cmake'.
+  set(CMAKE_RC_COMPILE_OBJECT "<CMAKE_RC_COMPILER> -O coff <DEFINES> <INCLUDES> <FLAGS> <SOURCE> <OBJECT>")
+  enable_language(RC)
+
+  set(CMAKE_C_COMPILE_OPTIONS_PIC "")  # CMake sets it to '-fPIC', confusing the toolchain and breaking builds. Zap it.
+
+  set(CMAKE_STATIC_LIBRARY_PREFIX "lib")
+  set(CMAKE_STATIC_LIBRARY_SUFFIX ".a")
+  set(CMAKE_SHARED_LIBRARY_PREFIX "lib")
+  set(CMAKE_SHARED_LIBRARY_SUFFIX ".dll")
+  set(CMAKE_IMPORT_LIBRARY_PREFIX "lib")
+  set(CMAKE_IMPORT_LIBRARY_SUFFIX ".dll.a")
+  set(CMAKE_FIND_LIBRARY_PREFIXES "lib" "")
+  set(CMAKE_FIND_LIBRARY_SUFFIXES ".dll.a" ".a" ".lib")
 elseif(DOS AND CMAKE_COMPILER_IS_GNUCC)  # DJGPP
   set(CMAKE_STATIC_LIBRARY_PREFIX "lib")
   set(CMAKE_STATIC_LIBRARY_SUFFIX ".a")
@@ -119,6 +146,9 @@ endif()
 if(WIN32)
   string(APPEND _target_flags " WIN32")
 endif()
+if(WINCE)
+  string(APPEND _target_flags " WINCE")
+endif()
 if(WINDOWS_STORE)
   string(APPEND _target_flags " UWP")
 endif()
@@ -195,12 +225,12 @@ if(WIN32)
   endif()
 
   option(ENABLE_UNICODE "Use the Unicode version of the Windows API functions" OFF)
-  if(WINDOWS_STORE)
+  if(WINDOWS_STORE OR WINCE)
     set(ENABLE_UNICODE ON)
   endif()
   if(ENABLE_UNICODE)
     set_property(DIRECTORY APPEND PROPERTY COMPILE_DEFINITIONS "UNICODE" "_UNICODE")
-    if(MINGW)
+    if(MINGW AND NOT MINGW32CE)
       set_property(DIRECTORY APPEND PROPERTY COMPILE_OPTIONS "-municode")
     endif()
   endif()
@@ -476,7 +506,7 @@ if(HTTP_ONLY)
   set(CURL_DISABLE_TFTP ON)
 endif()
 
-if(WINDOWS_STORE)
+if(WINDOWS_STORE OR WINCE)
   set(CURL_DISABLE_TELNET ON)  # telnet code needs fixing to compile for UWP.
 endif()
 
@@ -567,7 +597,19 @@ if(ENABLE_THREADED_RESOLVER)
 endif()
 
 # Check for all needed libraries
-if(DOS)
+if(WIN32)
+  if(WINCE)
+    set(_win32_winsock "ws2")
+  else()
+    set(_win32_winsock "ws2_32")
+  endif()
+  set(_win32_crypt32 "crypt32")
+
+  if(MINGW32CE)  # FIXME upstream: must specify the full path to avoid CMake converting "ws2" to "ws2.lib"
+    set(_win32_winsock "${MINGW32CE_LIBRARY_DIR}/lib${_win32_winsock}.a")
+    set(_win32_crypt32 "${MINGW32CE_LIBRARY_DIR}/lib${_win32_crypt32}.a")
+  endif()
+elseif(DOS)
   if(WATT_ROOT)
     set(USE_WATT32 ON)
     # FIXME upstream: must specify the full path to avoid CMake converting "watt" to "watt.lib"
@@ -588,7 +630,7 @@ elseif(AMIGA)
     set(CURL_USE_OPENSSL ON)
     set(CURL_CA_FALLBACK ON CACHE BOOL "")
   endif()
-elseif(NOT WIN32 AND NOT APPLE)
+elseif(NOT APPLE)
   check_library_exists("socket" "connect" "" HAVE_LIBSOCKET)
   if(HAVE_LIBSOCKET)
     set(CURL_LIBS "socket" ${CURL_LIBS})
@@ -623,7 +665,7 @@ if(ENABLE_IPV6)
     endif()
   endif()
 endif()
-if(ENABLE_IPV6)
+if(ENABLE_IPV6 AND NOT WINCE)
   set(USE_IPV6 ON)
 endif()
 
@@ -954,8 +996,8 @@ macro(curl_openssl_check_exists)
     if(HAVE_LIBZ)
       list(APPEND CMAKE_REQUIRED_LIBRARIES ZLIB::ZLIB)
     endif()
-    if(WIN32)
-      list(APPEND CMAKE_REQUIRED_LIBRARIES "ws2_32")
+    if(WIN32 AND NOT WINCE)
+      list(APPEND CMAKE_REQUIRED_LIBRARIES "${_win32_winsock}")
       list(APPEND CMAKE_REQUIRED_LIBRARIES "bcrypt")  # for OpenSSL/LibreSSL
     endif()
   endif()
@@ -967,7 +1009,7 @@ macro(curl_openssl_check_exists)
       list(APPEND CMAKE_REQUIRED_LIBRARIES ZLIB::ZLIB)  # Public wolfSSL headers also require zlib headers
     endif()
     if(WIN32)
-      list(APPEND CMAKE_REQUIRED_LIBRARIES "ws2_32" "crypt32")
+      list(APPEND CMAKE_REQUIRED_LIBRARIES "${_win32_winsock}" "${_win32_crypt32}")
     endif()
     list(APPEND CMAKE_REQUIRED_DEFINITIONS "-DHAVE_UINTPTR_T")  # to pull in stdint.h (as of wolfSSL v5.5.4)
   endif()
@@ -1174,7 +1216,7 @@ if(NOT CURL_DISABLE_SRP AND (HAVE_GNUTLS_SRP OR HAVE_OPENSSL_SRP))
 endif()
 
 if(NOT CURL_DISABLE_LDAP)
-  if(WIN32 AND NOT WINDOWS_STORE)
+  if(WIN32 AND NOT WINDOWS_STORE AND NOT WINCE)
     option(USE_WIN32_LDAP "Use Windows LDAP implementation" ON)
     if(USE_WIN32_LDAP)
       list(APPEND CURL_LIBS "wldap32")
@@ -1460,7 +1502,7 @@ if(USE_LIBRTMP)
 endif()
 
 option(ENABLE_UNIX_SOCKETS "Enable Unix domain sockets support" ON)
-if(ENABLE_UNIX_SOCKETS)
+if(ENABLE_UNIX_SOCKETS AND NOT WINCE)
   if(WIN32 OR DOS)
     set(USE_UNIX_SOCKETS ON)
   else()
@@ -1571,13 +1613,13 @@ if(WIN32)
   list(APPEND CURL_INCLUDES "ws2tcpip.h")
 
   if(HAVE_WIN32_WINNT)
-    if(HAVE_WIN32_WINNT LESS 0x0501)
+    if(HAVE_WIN32_WINNT LESS 0x0501 AND NOT WINCE)
       # Windows XP is required for freeaddrinfo, getaddrinfo
       message(FATAL_ERROR "Building for Windows XP or newer is required.")
     endif()
 
     # Pre-fill detection results based on target OS version
-    if(MINGW OR MSVC)
+    if(MINGW OR MSVC OR WINCE)
       if(HAVE_WIN32_WINNT LESS 0x0600)
         set(HAVE_INET_NTOP 0)
         set(HAVE_INET_PTON 0)
@@ -1685,7 +1727,7 @@ endif()
 
 # Apply to all feature checks
 if(WIN32)
-  list(APPEND CMAKE_REQUIRED_LIBRARIES "ws2_32")
+  list(APPEND CMAKE_REQUIRED_LIBRARIES "${_win32_winsock}")
 elseif(HAVE_LIBSOCKET)
   list(APPEND CMAKE_REQUIRED_LIBRARIES "socket")
 elseif(DOS)
@@ -1737,7 +1779,6 @@ check_symbol_exists("getpeername"     "${CURL_INCLUDES}" HAVE_GETPEERNAME)  # wi
 check_symbol_exists("getsockname"     "${CURL_INCLUDES}" HAVE_GETSOCKNAME)  # winsock2.h unistd.h proto/bsdsocket.h
 check_function_exists("getrlimit"       HAVE_GETRLIMIT)
 check_function_exists("setlocale"       HAVE_SETLOCALE)
-check_function_exists("setmode"         HAVE_SETMODE)
 check_function_exists("setrlimit"       HAVE_SETRLIMIT)
 
 if(NOT WIN32)
@@ -1749,8 +1790,11 @@ if(NOT WIN32)
   check_symbol_exists("strcmpi"         "string.h" HAVE_STRCMPI)
 endif()
 
-if(WIN32 OR CYGWIN)
-  check_function_exists("_setmode" HAVE__SETMODE)
+if(NOT MINGW32CE)  # Avoid false detections
+  check_function_exists("setmode" HAVE_SETMODE)
+  if(WIN32 OR CYGWIN)
+    check_function_exists("_setmode" HAVE__SETMODE)
+  endif()
 endif()
 
 if(AMIGA)
@@ -1930,9 +1974,14 @@ include(CMake/OtherTests.cmake)
 set_property(DIRECTORY APPEND PROPERTY COMPILE_DEFINITIONS "HAVE_CONFIG_H")
 
 if(WIN32)
-  list(APPEND CURL_LIBS "ws2_32" "bcrypt")
+  list(APPEND CURL_LIBS "${_win32_winsock}")
+  if(NOT WINCE)
+    list(APPEND CURL_LIBS "bcrypt")
+  endif()
 
-  set(USE_WIN32_LARGE_FILES ON)
+  if(NOT WINCE)
+    set(USE_WIN32_LARGE_FILES ON)
+  endif()
 
   # Use the manifest embedded in the Windows Resource
   string(APPEND CMAKE_RC_FLAGS " -DCURL_EMBED_MANIFEST")
@@ -1944,7 +1993,10 @@ if(WIN32)
 
   # Link required libraries for USE_WIN32_CRYPTO or USE_SCHANNEL
   if(USE_WIN32_CRYPTO OR USE_SCHANNEL)
-    list(APPEND CURL_LIBS "advapi32" "crypt32")
+    if(NOT WINCE)
+      list(APPEND CURL_LIBS "advapi32")
+    endif()
+    list(APPEND CURL_LIBS "${_win32_crypt32}")
   endif()
 endif()
 
index ab267a7a0c6a13f2cc3ca5a00a9ff3136729de29..1ecda765615535c4bdcc3c70bf189bcc310e136e 100644 (file)
@@ -1310,16 +1310,13 @@ AC_DEFUN([CURL_CHECK_WIN32_LARGEFILE], [
   AC_REQUIRE([CURL_CHECK_NATIVE_WINDOWS])dnl
   if test "$curl_cv_native_windows" = 'yes'; then
     AC_MSG_CHECKING([whether build target supports Win32 large files])
-    case $host_os in
-      mingw32ce*|cegcc*)
-        dnl Windows CE does not support large files
-        curl_win32_has_largefile='no'
-        ;;
-      *)
-        dnl All mingw-w64 versions support large files
-        curl_win32_has_largefile='yes'
-        ;;
-    esac
+    if test "$curl_cv_wince" = 'yes'; then
+      dnl Windows CE does not support large files
+      curl_win32_has_largefile='no'
+    else
+      dnl All mingw-w64 versions support large files
+      curl_win32_has_largefile='yes'
+    fi
     case "$curl_win32_has_largefile" in
       yes)
         if test x"$enable_largefile" = 'xno'; then
@@ -1476,9 +1473,20 @@ AC_DEFUN([CURL_PREPARE_BUILDINFO], [
   if test "$curl_cv_native_windows" = 'yes'; then
     curl_pflags="${curl_pflags} WIN32"
   fi
+  if test "$curl_cv_wince" = 'yes'; then
+    curl_pflags="${curl_pflags} WINCE"
+  fi
   if test "$curl_cv_winuwp" = 'yes'; then
     curl_pflags="${curl_pflags} UWP"
   fi
+  case $host in
+    *-*-*bsd*|*-*-aix*|*-*-hpux*|*-*-interix*|*-*-irix*|*-*-linux*|*-*-solaris*|*-*-sunos*|*-apple-*|*-*-cygwin*|*-*-msys*)
+      curl_pflags="${curl_pflags} UNIX";;
+  esac
+  case $host in
+    *-*-*bsd*)
+      curl_pflags="${curl_pflags} BSD";;
+  esac
   if test "$curl_cv_cygwin" = 'yes'; then
     curl_pflags="${curl_pflags} CYGWIN"
   fi
index 5f177cab8e70b386400ab51c1e1eb6c7af043ba9..98bacbf31fec3a4420357e1d873d21cf85340c59 100644 (file)
@@ -493,8 +493,12 @@ dnl **********************************************************************
 CURL_CHECK_COMPILER
 CURL_CHECK_NATIVE_WINDOWS
 
+curl_cv_wince='no'
 curl_cv_winuwp='no'
 if test "$curl_cv_native_windows" = "yes"; then
+  case $host_os in
+    mingw32ce*) curl_cv_wince='yes';;
+  esac
   case "$CPPFLAGS" in
     *-DWINSTORECOMPAT*) curl_cv_winuwp='yes';;
   esac
@@ -883,7 +887,7 @@ AS_HELP_STRING([--disable-telnet],[Disable TELNET support]),
     AC_MSG_RESULT(yes)
 )
 
-if test "$curl_cv_winuwp" = 'yes'; then
+if test "$curl_cv_winuwp" = 'yes' -o "$curl_cv_wince" = 'yes'; then
   AC_DEFINE(CURL_DISABLE_TELNET, 1, [to disable TELNET])
   CURL_DISABLE_TELNET=1
 fi
@@ -1161,11 +1165,42 @@ if test "$HAVE_GETHOSTBYNAME" != "1"; then
   ])
 fi
 
+if test "$HAVE_GETHOSTBYNAME" != "1"; then
+  if test "$curl_cv_wince" = 'yes'; then
+    dnl This is for Windows CE systems
+    winsock_LIB="-lws2"
+    if test ! -z "$winsock_LIB"; then
+      my_ac_save_LIBS=$LIBS
+      LIBS="$winsock_LIB $LIBS"
+      AC_MSG_CHECKING([for gethostbyname in $winsock_LIB])
+      AC_LINK_IFELSE([
+        AC_LANG_PROGRAM([[
+          #ifdef _WIN32
+          #ifndef WIN32_LEAN_AND_MEAN
+          #define WIN32_LEAN_AND_MEAN
+          #endif
+          #include <winsock2.h>
+          #endif
+        ]],[[
+          gethostbyname("localhost");
+        ]])
+      ],[
+        AC_MSG_RESULT([yes])
+        HAVE_GETHOSTBYNAME="1"
+      ],[
+        AC_MSG_RESULT([no])
+        winsock_LIB=""
+        LIBS=$my_ac_save_LIBS
+      ])
+    fi
+  fi
+fi
+
 # In UWP mode gethostbyname gets detected via the core libs, but some
 # code (in6addr_any) still need ws2_32, so let us detect and add it.
 if test "$HAVE_GETHOSTBYNAME" != "1" -o "$curl_cv_winuwp" = "yes"; then
-  dnl This is for Winsock systems
   if test "$curl_cv_native_windows" = "yes"; then
+    dnl This is for Winsock systems
     winsock_LIB="-lws2_32"
     if test ! -z "$winsock_LIB"; then
       my_ac_save_LIBS=$LIBS
@@ -1733,6 +1768,10 @@ AS_HELP_STRING([--disable-ipv6],[Disable IPv6 support]),
   )
 )
 
+if test "$curl_cv_wince" = 'yes'; then
+  ipv6=no
+fi
+
 if test "$ipv6" = yes; then
   curl_ipv6_msg="enabled"
   AC_DEFINE(USE_IPV6, 1, [Define if you want to enable IPv6 support])
@@ -2062,11 +2101,14 @@ CURL_WITH_RUSTLS
 
 dnl link required libraries for USE_WIN32_CRYPTO or SCHANNEL_ENABLED
 if test "x$USE_WIN32_CRYPTO" = "x1" -o "x$SCHANNEL_ENABLED" = "x1"; then
-  LIBS="-ladvapi32 -lcrypt32 $LIBS"
+  LIBS="-lcrypt32 $LIBS"
+  if test "$curl_cv_wince" = 'no'; then
+    LIBS="-ladvapi32 $LIBS"
+  fi
 fi
 
 dnl link bcrypt for BCryptGenRandom() (used when building for Vista or newer)
-if test "x$curl_cv_native_windows" = "xyes"; then
+if test "x$curl_cv_native_windows" = "xyes" -a "$curl_cv_wince" = 'no'; then
   LIBS="-lbcrypt $LIBS"
 fi
 
@@ -2611,7 +2653,11 @@ dnl ----------------------------
 dnl check Windows Unicode option
 dnl ----------------------------
 
-want_winuni="no"
+if test "$curl_cv_wince" = 'yes'; then
+  want_winuni="yes"
+else
+  want_winuni="no"
+fi
 if test "$curl_cv_native_windows" = "yes"; then
   if test "$curl_cv_winuwp" = 'yes'; then
     want_winuni="yes"
@@ -4068,7 +4114,6 @@ AC_CHECK_FUNCS([\
   sendmsg \
   sendmmsg \
   setlocale \
-  setmode \
   setrlimit \
   snprintf \
   utime \
@@ -4086,8 +4131,11 @@ if test "$curl_cv_native_windows" != 'yes'; then
   CURL_CHECK_FUNC_STRICMP
 fi
 
-if test "$curl_cv_native_windows" = 'yes' -o "$curl_cv_cygwin" = 'yes'; then
-  AC_CHECK_FUNCS([_setmode])
+if test "$curl_cv_wince" = 'no'; then
+  AC_CHECK_FUNCS([setmode])
+  if test "$curl_cv_native_windows" = 'yes' -o "$curl_cv_cygwin" = 'yes'; then
+    AC_CHECK_FUNCS([_setmode])
+  fi
 fi
 
 if test -z "$ssl_backends"; then
@@ -4467,7 +4515,7 @@ AS_HELP_STRING([--disable-unix-sockets],[Disable Unix domain sockets]),
     want_unix_sockets=auto
     ]
 )
-if test "x$want_unix_sockets" != "xno"; then
+if test "x$want_unix_sockets" != "xno" -a "$curl_cv_wince" = 'no'; then
   if test "x$curl_cv_native_windows" = "xyes"; then
     USE_UNIX_SOCKETS=1
     AC_DEFINE(USE_UNIX_SOCKETS, 1, [Use Unix domain sockets])
index be6dad69c07cc6d430e664f0f4e211b1db006fed..550c827693ffb9b559073f2027bdf9112826da7b 100644 (file)
@@ -103,7 +103,11 @@ int main(int argc, char **argv)
   if(!fp)
     return 2;
 
+#ifdef UNDER_CE
+  stat(file, &file_info);
+#else
   fstat(fileno(fp), &file_info);
+#endif
 
   /* In Windows, this inits the Winsock stuff */
   curl_global_init(CURL_GLOBAL_ALL);
index aac60df74c3973375559af4fe061471380feddaa..b185177ab68c3c0935b507595128a810b2f8e1a4 100644 (file)
@@ -29,9 +29,9 @@
  * filter IP addresses.
  */
 
-#ifdef __AMIGA__
+#if defined(__AMIGA__) || defined(UNDER_CE)
 #include <stdio.h>
-int main(void) { printf("AmigaOS is not supported.\n"); return 1; }
+int main(void) { printf("Platform not supported.\n"); return 1; }
 #else
 
 #ifdef _WIN32
index d33823f9337e9b9aa8d7bf75cdabb6e8e69a0747..142b5af91d0cf59de381f4f4b309acb92d36082d 100644 (file)
 #include <unistd.h>           /*  misc. Unix functions      */
 #endif
 
+#ifdef UNDER_CE
+#define strerror(e) "?"
+#else
 #include <errno.h>
+#endif
 
 /* The IP address and port number to connect to */
 #define IPADDR "127.0.0.1"
index ae23a310ec18fd266ef2ac4874383a7582657a3a..0860c9457bea9d604e7318c6de881aecc6bd1049 100644 (file)
@@ -51,7 +51,11 @@ int main(void)
     return 1; /* cannot continue */
 
   /* to get the file size */
+#ifdef UNDER_CE
+  if(stat("debugit", &file_info) != 0) {
+#else
   if(fstat(fileno(fd), &file_info) != 0) {
+#endif
     fclose(fd);
     return 1; /* cannot continue */
   }
index eb6770120ca07589970a09ffa273d4198fbcc874..6e7bece70dee28b28e68c00d283522b5eccd06e8 100644 (file)
 #include <sys/types.h>
 #include <sys/stat.h>
 #include <fcntl.h>
+#ifdef UNDER_CE
+#define strerror(e) "?"
+#else
 #include <errno.h>
+#endif
 #ifdef _WIN32
 #include <io.h>
 #undef stat
index d4063925dd4175f59a43076d944d7b4147cb1ff4..b02ad928a6dc05e85ba5ac23743c77745e243a24 100644 (file)
@@ -77,7 +77,9 @@ static int upload(CURL *curlhandle, const char *remotepath,
 
   f = fopen(localpath, "rb");
   if(!f) {
+#ifndef UNDER_CE
     perror(NULL);
+#endif
     return 0;
   }
 
index ff74efb8ce867eb704e1e290a787fa8a167998ed..693f393ada034c4b39a35c331548781377f064f8 100644 (file)
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
+#ifdef UNDER_CE
+#define strerror(e) "?"
+#else
 #include <errno.h>
+#endif
 
 /* curl stuff */
 #include <curl/curl.h>
index 292897c1b9b4f9824bd31da513c778fffdf85463..88a1bdbabdcd968fa199f0892ae949bc0e72745a 100644 (file)
 #include <string.h>
 #include <fcntl.h>
 #include <sys/stat.h>
+#ifdef UNDER_CE
+#define strerror(e) "?"
+#else
 #include <errno.h>
+#endif
 
 /* somewhat Unix-specific */
 #ifndef _MSC_VER
index aabe5c39535b372f11a968ba41f2b25d14dbdce8..d0d40a0bc83fc242e35b1842be8675459b9d6b7c 100644 (file)
@@ -90,7 +90,9 @@ static int sftpResumeUpload(CURL *curlhandle, const char *remotepath,
 
   f = fopen(localpath, "rb");
   if(!f) {
+#ifndef UNDER_CE
     perror(NULL);
+#endif
     return 0;
   }
 
@@ -99,7 +101,7 @@ static int sftpResumeUpload(CURL *curlhandle, const char *remotepath,
   curl_easy_setopt(curlhandle, CURLOPT_READFUNCTION, readfunc);
   curl_easy_setopt(curlhandle, CURLOPT_READDATA, f);
 
-#ifdef _WIN32
+#if defined(_WIN32) && !defined(UNDER_CE)
   _fseeki64(f, remoteFileSizeByte, SEEK_SET);
 #else
   fseek(f, (long)remoteFileSizeByte, SEEK_SET);
index 84cf5f2f525abe3cdfb728631ab94e178cfd734a..b72d0317005c1dac9467a7a007d6e7b57759d2e3 100644 (file)
 #include <sys/select.h>
 #endif
 
-#if !defined(_WIN32) && !defined(_WIN32_WCE)
-#include <sys/socket.h>
-#endif
-
 #if !defined(_WIN32)
+#include <sys/socket.h>
 #include <sys/time.h>
 #endif
 
index 820fe96b39bb69367fd5789e8c74d8500e6da19b..f647f85870a7e3c77b844b35a74fed125dfc6008 100644 (file)
 #    define CURL_TYPEOF_CURL_SOCKLEN_T unsigned int
 #  endif
 
-#elif defined(_WIN32_WCE)
-#  define CURL_TYPEOF_CURL_OFF_T     __int64
-#  define CURL_FORMAT_CURL_OFF_T     "I64d"
-#  define CURL_FORMAT_CURL_OFF_TU    "I64u"
-#  define CURL_SUFFIX_CURL_OFF_T     i64
-#  define CURL_SUFFIX_CURL_OFF_TU    ui64
-#  define CURL_TYPEOF_CURL_SOCKLEN_T int
+#elif defined(UNDER_CE)
+#  if defined(__MINGW32CE__)
+#    define CURL_TYPEOF_CURL_OFF_T     long long
+#    define CURL_FORMAT_CURL_OFF_T     "lld"
+#    define CURL_FORMAT_CURL_OFF_TU    "llu"
+#    define CURL_SUFFIX_CURL_OFF_T     LL
+#    define CURL_SUFFIX_CURL_OFF_TU    ULL
+#    define CURL_TYPEOF_CURL_SOCKLEN_T int
+#  else
+#    define CURL_TYPEOF_CURL_OFF_T     __int64
+#    define CURL_FORMAT_CURL_OFF_T     "I64d"
+#    define CURL_FORMAT_CURL_OFF_TU    "I64u"
+#    define CURL_SUFFIX_CURL_OFF_T     i64
+#    define CURL_SUFFIX_CURL_OFF_TU    ui64
+#    define CURL_TYPEOF_CURL_SOCKLEN_T int
+#  endif
 
 #elif defined(__MINGW32__)
 #  include <inttypes.h>
index a0ca8b3e9d37c17ffc6f1a8a3f3dd989d05185c4..2ca28041d0f0660de72e0d557abbc4e9adef3a16 100644 (file)
@@ -259,7 +259,7 @@ static CURLcode getaddrinfo_complete(struct Curl_easy *data)
  * and wait on it.
  */
 static
-#if defined(_WIN32_WCE) || defined(CURL_WINDOWS_UWP)
+#if defined(CURL_WINDOWS_UWP) || defined(UNDER_CE)
 DWORD
 #else
 unsigned int
@@ -318,7 +318,7 @@ CURL_STDCALL getaddrinfo_thread(void *arg)
  * gethostbyname_thread() resolves a name and then exits.
  */
 static
-#if defined(_WIN32_WCE) || defined(CURL_WINDOWS_UWP)
+#if defined(CURL_WINDOWS_UWP) || defined(UNDER_CE)
 DWORD
 #else
 unsigned int
@@ -477,7 +477,7 @@ err_exit:
   destroy_async_data(data);
 
 errno_exit:
-  errno = err;
+  CURL_SETERRNO(err);
   return FALSE;
 }
 
index ce3a771fc0a10a194977967ec542f1d25834d90a..b7b218f896afffe1b1030f04f38caecbd62eef90 100644 (file)
@@ -843,7 +843,7 @@ static bool verifyconnect(curl_socket_t sockfd, int *error)
    *    Someone got to verify this on Win-NT 4.0, 2000."
    */
 
-#ifdef _WIN32_WCE
+#ifdef UNDER_CE
   Sleep(0);
 #else
   SleepEx(0, FALSE);
@@ -853,7 +853,7 @@ static bool verifyconnect(curl_socket_t sockfd, int *error)
 
   if(0 != getsockopt(sockfd, SOL_SOCKET, SO_ERROR, (void *)&err, &errSize))
     err = SOCKERRNO;
-#ifdef _WIN32_WCE
+#ifdef UNDER_CE
   /* Old Windows CE versions do not support SO_ERROR */
   if(WSAENOPROTOOPT == err) {
     SET_SOCKERRNO(0);
index 1b1ead6c9a24cbb194f09da840cf49499b06c897..4ef2bd3b1950d756d07781f4a31dc3a8e4ba88cf 100644 (file)
 /* Define if you have the <arpa/inet.h> header file. */
 /* #define HAVE_ARPA_INET_H 1 */
 
+#ifndef UNDER_CE
+
 /* Define if you have the <fcntl.h> header file. */
-#define HAVE_FCNTL_H 1
+#define HAVE_FCNTL_H 1  /* exists on __MINGW32CE__ */
 
 /* Define if you have the <io.h> header file. */
-#define HAVE_IO_H 1
+#define HAVE_IO_H 1  /* exists on __MINGW32CE__ */
 
 /* Define if you have the <locale.h> header file. */
-#ifndef UNDER_CE
 #define HAVE_LOCALE_H 1
+
 #endif
 
 /* Define if you have the <netdb.h> header file. */
 /* #define HAVE_NETINET_IN_H 1 */
 
 /* Define to 1 if you have the <stdbool.h> header file. */
+#ifndef UNDER_CE
 #if (defined(_MSC_VER) && (_MSC_VER >= 1800)) || defined(__MINGW32__)
-#define HAVE_STDBOOL_H 1
+#define HAVE_STDBOOL_H 1  /* exists on __MINGW32CE__ */
+#endif
 #endif
 
 /* Define if you have the <sys/param.h> header file. */
 #define STDC_HEADERS 1
 
 /* Define to 1 if bool is an available type. */
+#ifndef UNDER_CE
 #if (defined(_MSC_VER) && (_MSC_VER >= 1800)) || defined(__MINGW32__)
-#define HAVE_BOOL_T 1
+#define HAVE_BOOL_T 1  /* exists on __MINGW32CE__ */
+#endif
 #endif
 
 /* ---------------------------------------------------------------- */
@@ -499,11 +505,9 @@ Vista
 #define CURL_DISABLE_TELNET 1
 #define CURL_DISABLE_LDAP 1
 
-#define ENOSPC 1
-#define ENOMEM 2
-#define EAGAIN 3
-
+#ifndef _MSC_VER
 extern int stat(const char *path, struct stat *buffer);
+#endif
 
 #endif /* UNDER_CE */
 
index 02abd158f3b6e2bc0f447c455c1982ea304cb58f..88ebf524312b0ea35057f80b4fb505c3ffabd4c4 100644 (file)
@@ -301,7 +301,7 @@ bool Curl_addr2string(struct sockaddr *sa, curl_socklen_t salen,
 
   addr[0] = '\0';
   *port = 0;
-  errno = EAFNOSUPPORT;
+  CURL_SETERRNO(EAFNOSUPPORT);
   return FALSE;
 }
 
index 220b2fa3f620f56d1e97c82d5250d6f4d5e9954e..9c9fae6653ff2ea52faee757a3dc0fb7d9217fa5 100644 (file)
@@ -84,6 +84,8 @@ char *curlx_convert_wchar_to_UTF8(const wchar_t *str_w)
   return str_utf8;
 }
 
+#ifndef UNDER_CE
+
 /* declare GetFullPathNameW for mingw-w64 UWP builds targeting old windows */
 #if defined(CURL_WINDOWS_UWP) && defined(__MINGW32__) && \
   (_WIN32_WINNT < _WIN32_WINNT_WIN10)
@@ -267,7 +269,7 @@ int curlx_win32_open(const char *filename, int oflag, ...)
     curlx_unicodefree(filename_w);
   }
   else
-    errno = EINVAL;
+    CURL_SETERRNO(EINVAL);
 #else
   if(fix_excessive_path(filename, &fixed))
     target = fixed;
@@ -297,7 +299,7 @@ FILE *curlx_win32_fopen(const char *filename, const char *mode)
     result = _wfopen(target, mode_w);
   }
   else
-    errno = EINVAL;
+    CURL_SETERRNO(EINVAL);
   curlx_unicodefree(filename_w);
   curlx_unicodefree(mode_w);
 #else
@@ -333,7 +335,7 @@ int curlx_win32_stat(const char *path, struct_stat *buffer)
     curlx_unicodefree(path_w);
   }
   else
-    errno = EINVAL;
+    CURL_SETERRNO(EINVAL);
 #else
   if(fix_excessive_path(path, &fixed))
     target = fixed;
@@ -350,4 +352,6 @@ int curlx_win32_stat(const char *path, struct_stat *buffer)
   return result;
 }
 
+#endif /* UNDER_CE */
+
 #endif /* _WIN32 */
index ad9b1a2d1d32dab2fd188a7bb3e9b0883f6e7482..92d911dfb991abc2e05309e1727b6f1e08528878 100644 (file)
  */
 
 #ifdef USE_WIN32_LARGE_FILES
+#  ifdef HAVE_IO_H
 #  include <io.h>
+#  endif
 #  include <sys/types.h>
 #  include <sys/stat.h>
 #  undef  lseek
  */
 
 #if defined(_WIN32) && !defined(USE_WIN32_LARGE_FILES)
+#  ifdef HAVE_IO_H
 #  include <io.h>
+#  endif
 #  include <sys/types.h>
 #  include <sys/stat.h>
-#  ifndef _WIN32_WCE
+#  ifndef UNDER_CE
 #    undef  lseek
 #    define lseek(fdes,offset,whence)  _lseek(fdes, (long)offset, whence)
 #    define fstat(fdes,stp)            _fstat(fdes, stp)
 #include "curl_setup_once.h"
 #endif
 
+#ifdef UNDER_CE
+#define getenv curl_getenv  /* Windows CE does not support getenv() */
+#define raise(s) ((void)(s))
+/* Terrible workarounds to make Windows CE compile */
+#define errno 0
+#define CURL_SETERRNO(x) ((void)(x))
+#define EAGAIN 11
+#define ENOMEM 12
+#define EACCES 13
+#define EEXIST 17
+#define EISDIR 21
+#define ENOSPC 28
+#define ERANGE 34
+#define strerror(x) "?"
+#else
+#define CURL_SETERRNO(x) (errno = (x))
+#endif
+
 /*
  * Definition of our NOP statement Object-like macro
  */
index 037bffb45cb3c5e0d6e064526b0c8a64fed83ed7..016355b1094540930717e4ad331105856f8ae16c 100644 (file)
@@ -33,7 +33,9 @@
 #include <string.h>
 #include <stdarg.h>
 #include <time.h>
+#ifndef UNDER_CE
 #include <errno.h>
+#endif
 
 #ifdef HAVE_SYS_TYPES_H
 #include <sys/types.h>
@@ -390,7 +392,7 @@ typedef unsigned int bit;
 
 #ifdef __VMS
 #define argv_item_t  __char_ptr32
-#elif defined(_UNICODE)
+#elif defined(_UNICODE) && !defined(UNDER_CE)
 #define argv_item_t  wchar_t *
 #else
 #define argv_item_t  char *
index 680bb661b285ed0710d1808da0daeb94e7586cd2..08d28b20feb56dee3e7a0b77a8b278e43e24ab51 100644 (file)
@@ -42,7 +42,7 @@ typedef PSecurityFunctionTable (APIENTRY *INITSECURITYINTERFACE_FN)(VOID);
 
 /* See definition of SECURITY_ENTRYPOINT in sspi.h */
 #ifdef UNICODE
-#  ifdef _WIN32_WCE
+#  ifdef UNDER_CE
 #    define SECURITYENTRYPOINT L"InitSecurityInterfaceW"
 #  else
 #    define SECURITYENTRYPOINT "InitSecurityInterfaceW"
index ac39afa253e81bd4ec21c6d9dd88e4751b4a87f0..cafdb8d3bc8acd0e029f3447573252c4b06a4f5f 100644 (file)
@@ -70,6 +70,225 @@ extern PSecurityFunctionTable Curl_pSecFn;
 #define ISC_REQ_USE_HTTP_STYLE                0x01000000
 #endif
 
+#ifdef __MINGW32CE__
+#ifndef ISC_RET_REPLAY_DETECT
+#define ISC_RET_REPLAY_DETECT                 0x00000004
+#endif
+#ifndef ISC_RET_SEQUENCE_DETECT
+#define ISC_RET_SEQUENCE_DETECT               0x00000008
+#endif
+#ifndef ISC_RET_CONFIDENTIALITY
+#define ISC_RET_CONFIDENTIALITY               0x00000010
+#endif
+#ifndef ISC_RET_ALLOCATED_MEMORY
+#define ISC_RET_ALLOCATED_MEMORY              0x00000100
+#endif
+#ifndef ISC_RET_STREAM
+#define ISC_RET_STREAM                        0x00008000
+#endif
+
+#ifndef SEC_E_INSUFFICIENT_MEMORY
+#define SEC_E_INSUFFICIENT_MEMORY             ((HRESULT)0x80090300L)
+#endif
+#ifndef SEC_E_INVALID_HANDLE
+#define SEC_E_INVALID_HANDLE                  ((HRESULT)0x80090301L)
+#endif
+#ifndef SEC_E_UNSUPPORTED_FUNCTION
+#define SEC_E_UNSUPPORTED_FUNCTION            ((HRESULT)0x80090302L)
+#endif
+#ifndef SEC_E_TARGET_UNKNOWN
+#define SEC_E_TARGET_UNKNOWN                  ((HRESULT)0x80090303L)
+#endif
+#ifndef SEC_E_INTERNAL_ERROR
+#define SEC_E_INTERNAL_ERROR                  ((HRESULT)0x80090304L)
+#endif
+#ifndef SEC_E_SECPKG_NOT_FOUND
+#define SEC_E_SECPKG_NOT_FOUND                ((HRESULT)0x80090305L)
+#endif
+#ifndef SEC_E_NOT_OWNER
+#define SEC_E_NOT_OWNER                       ((HRESULT)0x80090306L)
+#endif
+#ifndef SEC_E_CANNOT_INSTALL
+#define SEC_E_CANNOT_INSTALL                  ((HRESULT)0x80090307L)
+#endif
+#ifndef SEC_E_INVALID_TOKEN
+#define SEC_E_INVALID_TOKEN                   ((HRESULT)0x80090308L)
+#endif
+#ifndef SEC_E_CANNOT_PACK
+#define SEC_E_CANNOT_PACK                     ((HRESULT)0x80090309L)
+#endif
+#ifndef SEC_E_QOP_NOT_SUPPORTED
+#define SEC_E_QOP_NOT_SUPPORTED               ((HRESULT)0x8009030AL)
+#endif
+#ifndef SEC_E_NO_IMPERSONATION
+#define SEC_E_NO_IMPERSONATION                ((HRESULT)0x8009030BL)
+#endif
+#ifndef SEC_E_LOGON_DENIED
+#define SEC_E_LOGON_DENIED                    ((HRESULT)0x8009030CL)
+#endif
+#ifndef SEC_E_UNKNOWN_CREDENTIALS
+#define SEC_E_UNKNOWN_CREDENTIALS             ((HRESULT)0x8009030DL)
+#endif
+#ifndef SEC_E_NO_CREDENTIALS
+#define SEC_E_NO_CREDENTIALS                  ((HRESULT)0x8009030EL)
+#endif
+#ifndef SEC_E_MESSAGE_ALTERED
+#define SEC_E_MESSAGE_ALTERED                 ((HRESULT)0x8009030FL)
+#endif
+#ifndef SEC_E_OUT_OF_SEQUENCE
+#define SEC_E_OUT_OF_SEQUENCE                 ((HRESULT)0x80090310L)
+#endif
+#ifndef SEC_E_NO_AUTHENTICATING_AUTHORITY
+#define SEC_E_NO_AUTHENTICATING_AUTHORITY     ((HRESULT)0x80090311L)
+#endif
+#ifndef SEC_E_BAD_PKGID
+#define SEC_E_BAD_PKGID                       ((HRESULT)0x80090316L)
+#endif
+#ifndef SEC_E_CONTEXT_EXPIRED
+#define SEC_E_CONTEXT_EXPIRED                 ((HRESULT)0x80090317L)
+#endif
+#ifndef SEC_E_INCOMPLETE_MESSAGE
+#define SEC_E_INCOMPLETE_MESSAGE              ((HRESULT)0x80090318L)
+#endif
+#ifndef SEC_E_INCOMPLETE_CREDENTIALS
+#define SEC_E_INCOMPLETE_CREDENTIALS          ((HRESULT)0x80090320L)
+#endif
+#ifndef SEC_E_BUFFER_TOO_SMALL
+#define SEC_E_BUFFER_TOO_SMALL                ((HRESULT)0x80090321L)
+#endif
+#ifndef SEC_E_WRONG_PRINCIPAL
+#define SEC_E_WRONG_PRINCIPAL                 ((HRESULT)0x80090322L)
+#endif
+#ifndef SEC_E_TIME_SKEW
+#define SEC_E_TIME_SKEW                       ((HRESULT)0x80090324L)
+#endif
+#ifndef SEC_E_UNTRUSTED_ROOT
+#define SEC_E_UNTRUSTED_ROOT                  ((HRESULT)0x80090325L)
+#endif
+#ifndef SEC_E_ILLEGAL_MESSAGE
+#define SEC_E_ILLEGAL_MESSAGE                 ((HRESULT)0x80090326L)
+#endif
+#ifndef SEC_E_CERT_UNKNOWN
+#define SEC_E_CERT_UNKNOWN                    ((HRESULT)0x80090327L)
+#endif
+#ifndef SEC_E_CERT_EXPIRED
+#define SEC_E_CERT_EXPIRED                    ((HRESULT)0x80090328L)
+#endif
+#ifndef SEC_E_ENCRYPT_FAILURE
+#define SEC_E_ENCRYPT_FAILURE                 ((HRESULT)0x80090329L)
+#endif
+#ifndef SEC_E_DECRYPT_FAILURE
+#define SEC_E_DECRYPT_FAILURE                 ((HRESULT)0x80090330L)
+#endif
+#ifndef SEC_E_ALGORITHM_MISMATCH
+#define SEC_E_ALGORITHM_MISMATCH              ((HRESULT)0x80090331L)
+#endif
+#ifndef SEC_E_SECURITY_QOS_FAILED
+#define SEC_E_SECURITY_QOS_FAILED             ((HRESULT)0x80090332L)
+#endif
+#ifndef SEC_E_UNFINISHED_CONTEXT_DELETED
+#define SEC_E_UNFINISHED_CONTEXT_DELETED      ((HRESULT)0x80090333L)
+#endif
+#ifndef SEC_E_NO_TGT_REPLY
+#define SEC_E_NO_TGT_REPLY                    ((HRESULT)0x80090334L)
+#endif
+#ifndef SEC_E_NO_IP_ADDRESSES
+#define SEC_E_NO_IP_ADDRESSES                 ((HRESULT)0x80090335L)
+#endif
+#ifndef SEC_E_WRONG_CREDENTIAL_HANDLE
+#define SEC_E_WRONG_CREDENTIAL_HANDLE         ((HRESULT)0x80090336L)
+#endif
+#ifndef SEC_E_CRYPTO_SYSTEM_INVALID
+#define SEC_E_CRYPTO_SYSTEM_INVALID           ((HRESULT)0x80090337L)
+#endif
+#ifndef SEC_E_MAX_REFERRALS_EXCEEDED
+#define SEC_E_MAX_REFERRALS_EXCEEDED          ((HRESULT)0x80090338L)
+#endif
+#ifndef SEC_E_MUST_BE_KDC
+#define SEC_E_MUST_BE_KDC                     ((HRESULT)0x80090339L)
+#endif
+#ifndef SEC_E_STRONG_CRYPTO_NOT_SUPPORTED
+#define SEC_E_STRONG_CRYPTO_NOT_SUPPORTED     ((HRESULT)0x8009033AL)
+#endif
+#ifndef SEC_E_TOO_MANY_PRINCIPALS
+#define SEC_E_TOO_MANY_PRINCIPALS             ((HRESULT)0x8009033BL)
+#endif
+#ifndef SEC_E_NO_PA_DATA
+#define SEC_E_NO_PA_DATA                      ((HRESULT)0x8009033CL)
+#endif
+#ifndef SEC_E_PKINIT_NAME_MISMATCH
+#define SEC_E_PKINIT_NAME_MISMATCH            ((HRESULT)0x8009033DL)
+#endif
+#ifndef SEC_E_SMARTCARD_LOGON_REQUIRED
+#define SEC_E_SMARTCARD_LOGON_REQUIRED        ((HRESULT)0x8009033EL)
+#endif
+#ifndef SEC_E_SHUTDOWN_IN_PROGRESS
+#define SEC_E_SHUTDOWN_IN_PROGRESS            ((HRESULT)0x8009033FL)
+#endif
+#ifndef SEC_E_KDC_INVALID_REQUEST
+#define SEC_E_KDC_INVALID_REQUEST             ((HRESULT)0x80090340L)
+#endif
+#ifndef SEC_E_KDC_UNABLE_TO_REFER
+#define SEC_E_KDC_UNABLE_TO_REFER             ((HRESULT)0x80090341L)
+#endif
+#ifndef SEC_E_KDC_UNKNOWN_ETYPE
+#define SEC_E_KDC_UNKNOWN_ETYPE               ((HRESULT)0x80090342L)
+#endif
+#ifndef SEC_E_UNSUPPORTED_PREAUTH
+#define SEC_E_UNSUPPORTED_PREAUTH             ((HRESULT)0x80090343L)
+#endif
+#ifndef SEC_E_DELEGATION_REQUIRED
+#define SEC_E_DELEGATION_REQUIRED             ((HRESULT)0x80090345L)
+#endif
+#ifndef SEC_E_BAD_BINDINGS
+#define SEC_E_BAD_BINDINGS                    ((HRESULT)0x80090346L)
+#endif
+#ifndef SEC_E_MULTIPLE_ACCOUNTS
+#define SEC_E_MULTIPLE_ACCOUNTS               ((HRESULT)0x80090347L)
+#endif
+#ifndef SEC_E_NO_KERB_KEY
+#define SEC_E_NO_KERB_KEY                     ((HRESULT)0x80090348L)
+#endif
+#ifndef SEC_E_CERT_WRONG_USAGE
+#define SEC_E_CERT_WRONG_USAGE                ((HRESULT)0x80090349L)
+#endif
+#ifndef SEC_E_DOWNGRADE_DETECTED
+#define SEC_E_DOWNGRADE_DETECTED              ((HRESULT)0x80090350L)
+#endif
+#ifndef SEC_E_SMARTCARD_CERT_REVOKED
+#define SEC_E_SMARTCARD_CERT_REVOKED          ((HRESULT)0x80090351L)
+#endif
+#ifndef SEC_E_ISSUING_CA_UNTRUSTED
+#define SEC_E_ISSUING_CA_UNTRUSTED            ((HRESULT)0x80090352L)
+#endif
+#ifndef SEC_E_REVOCATION_OFFLINE_C
+#define SEC_E_REVOCATION_OFFLINE_C            ((HRESULT)0x80090353L)
+#endif
+#ifndef SEC_E_PKINIT_CLIENT_FAILURE
+#define SEC_E_PKINIT_CLIENT_FAILURE           ((HRESULT)0x80090354L)
+#endif
+#ifndef SEC_E_SMARTCARD_CERT_EXPIRED
+#define SEC_E_SMARTCARD_CERT_EXPIRED          ((HRESULT)0x80090355L)
+#endif
+#ifndef SEC_E_NO_S4U_PROT_SUPPORT
+#define SEC_E_NO_S4U_PROT_SUPPORT             ((HRESULT)0x80090356L)
+#endif
+#ifndef SEC_E_CROSSREALM_DELEGATION_FAILURE
+#define SEC_E_CROSSREALM_DELEGATION_FAILURE   ((HRESULT)0x80090357L)
+#endif
+#ifndef SEC_E_REVOCATION_OFFLINE_KDC
+#define SEC_E_REVOCATION_OFFLINE_KDC          ((HRESULT)0x80090358L)
+#endif
+#ifndef SEC_E_ISSUING_CA_UNTRUSTED_KDC
+#define SEC_E_ISSUING_CA_UNTRUSTED_KDC        ((HRESULT)0x80090359L)
+#endif
+#ifndef SEC_E_KDC_CERT_EXPIRED
+#define SEC_E_KDC_CERT_EXPIRED                ((HRESULT)0x8009035AL)
+#endif
+#ifndef SEC_E_KDC_CERT_REVOKED
+#define SEC_E_KDC_CERT_REVOKED                ((HRESULT)0x8009035BL)
+#endif
+#endif /* __MINGW32CE__ */
 #ifndef SEC_E_INVALID_PARAMETER
 # define SEC_E_INVALID_PARAMETER              ((HRESULT)0x8009035DL)
 #endif
@@ -80,6 +299,32 @@ extern PSecurityFunctionTable Curl_pSecFn;
 # define SEC_E_POLICY_NLTM_ONLY               ((HRESULT)0x8009035FL)
 #endif
 
+#ifdef __MINGW32CE__
+#ifndef SEC_I_CONTINUE_NEEDED
+#define SEC_I_CONTINUE_NEEDED                 ((HRESULT)0x00090312L)
+#endif
+#ifndef SEC_I_COMPLETE_NEEDED
+#define SEC_I_COMPLETE_NEEDED                 ((HRESULT)0x00090313L)
+#endif
+#ifndef SEC_I_COMPLETE_AND_CONTINUE
+#define SEC_I_COMPLETE_AND_CONTINUE           ((HRESULT)0x00090314L)
+#endif
+#ifndef SEC_I_LOCAL_LOGON
+#define SEC_I_LOCAL_LOGON                     ((HRESULT)0x00090315L)
+#endif
+#ifndef SEC_I_CONTEXT_EXPIRED
+#define SEC_I_CONTEXT_EXPIRED                 ((HRESULT)0x00090317L)
+#endif
+#ifndef SEC_I_INCOMPLETE_CREDENTIALS
+#define SEC_I_INCOMPLETE_CREDENTIALS          ((HRESULT)0x00090320L)
+#endif
+#ifndef SEC_I_RENEGOTIATE
+#define SEC_I_RENEGOTIATE                     ((HRESULT)0x00090321L)
+#endif
+#ifndef SEC_I_NO_LSA_CONTEXT
+#define SEC_I_NO_LSA_CONTEXT                  ((HRESULT)0x00090323L)
+#endif
+#endif /* __MINGW32CE__ */
 #ifndef SEC_I_SIGNATURE_NEEDED
 #define SEC_I_SIGNATURE_NEEDED                ((HRESULT)0x0009035CL)
 #endif
index fbbbf9b2d3214980deccff8e92eee8d2b171ec37..6f90bfed15a35059aaa1e8eed64571cf7d8abfcf 100644 (file)
@@ -103,7 +103,7 @@ int Curl_thread_join(curl_thread_t *hnd)
 #elif defined(USE_THREADS_WIN32)
 
 curl_thread_t Curl_thread_create(
-#if defined(_WIN32_WCE) || defined(CURL_WINDOWS_UWP)
+#if defined(CURL_WINDOWS_UWP) || defined(UNDER_CE)
                                  DWORD
 #else
                                  unsigned int
@@ -111,25 +111,26 @@ curl_thread_t Curl_thread_create(
                                  (CURL_STDCALL *func) (void *),
                                  void *arg)
 {
-#if defined(_WIN32_WCE) || defined(CURL_WINDOWS_UWP)
+#if defined(CURL_WINDOWS_UWP) || defined(UNDER_CE)
   typedef HANDLE curl_win_thread_handle_t;
 #else
   typedef uintptr_t curl_win_thread_handle_t;
 #endif
   curl_thread_t t;
   curl_win_thread_handle_t thread_handle;
-#if defined(_WIN32_WCE) || defined(CURL_WINDOWS_UWP)
+#if defined(CURL_WINDOWS_UWP) || defined(UNDER_CE)
   thread_handle = CreateThread(NULL, 0, func, arg, 0, NULL);
 #else
   thread_handle = _beginthreadex(NULL, 0, func, arg, 0, NULL);
 #endif
   t = (curl_thread_t)thread_handle;
   if((t == 0) || (t == LongToHandle(-1L))) {
-#ifdef _WIN32_WCE
+#ifdef UNDER_CE
     DWORD gle = GetLastError();
-    errno = ((gle == ERROR_ACCESS_DENIED ||
-              gle == ERROR_NOT_ENOUGH_MEMORY) ?
-             EACCES : EINVAL);
+    int err = (gle == ERROR_ACCESS_DENIED ||
+               gle == ERROR_NOT_ENOUGH_MEMORY) ?
+               EACCES : EINVAL;
+    CURL_SETERRNO(err);
 #endif
     return curl_thread_t_null;
   }
index c9f18a4e09e12ac534b5917299e98c27848def1e..0b334034cea1d03a6daa33d596c7ee58d1d584d2 100644 (file)
@@ -53,7 +53,7 @@
 #if defined(USE_THREADS_POSIX) || defined(USE_THREADS_WIN32)
 
 curl_thread_t Curl_thread_create(
-#if defined(_WIN32_WCE) || defined(CURL_WINDOWS_UWP)
+#if defined(CURL_WINDOWS_UWP) || defined(UNDER_CE)
                                  DWORD
 #else
                                  unsigned int
index 1573a9d9297b01be3d370171e318a39b5158243e..72caeff3f378116f06fe0ea1e47920125b2c1cb5 100644 (file)
@@ -105,7 +105,7 @@ static curl_simple_lock s_lock = CURL_SIMPLE_LOCK_INIT;
  * ways, but at this point it must be defined as the system-supplied strdup
  * so the callback pointer is initialized correctly.
  */
-#if defined(_WIN32_WCE)
+#if defined(UNDER_CE)
 #define system_strdup _strdup
 #elif !defined(HAVE_STRDUP)
 #define system_strdup Curl_strdup
index 40d950c0e07d903f6efccf390b4eedf31c695957..b493a13375bfa697b3f098c0cbeed723d2b9cb54 100644 (file)
@@ -547,7 +547,7 @@ static CURLcode file_do(struct Curl_easy *data, bool *done)
 
   if(data->state.resume_from) {
     if(!S_ISDIR(statbuf.st_mode)) {
-#ifdef __AMIGA__
+#if defined(__AMIGA__) || defined(__MINGW32CE__)
       if(data->state.resume_from !=
           lseek(fd, (off_t)data->state.resume_from, SEEK_SET))
 #else
index 90dc0ae4d7334b31ac87dacaa6d40aeb05bae431..43678e29f9f046edd421b5a22862d20e1ad0fdce 100644 (file)
@@ -105,7 +105,13 @@ CURLcode Curl_fopen(struct Curl_easy *data, const char *filename,
   *fh = fopen(filename, FOPEN_WRITETEXT);
   if(!*fh)
     goto fail;
-  if(fstat(fileno(*fh), &sb) == -1 || !S_ISREG(sb.st_mode)) {
+  if(
+#ifdef UNDER_CE
+     stat(filename, &sb) == -1
+#else
+     fstat(fileno(*fh), &sb) == -1
+#endif
+     || !S_ISREG(sb.st_mode)) {
     return CURLE_OK;
   }
   fclose(*fh);
index 4ce932efe533b29753113b01f1b400eb823fed09..c50f5f8de31ff2cc943939390d2bd581063d3951 100644 (file)
--- a/lib/ftp.c
+++ b/lib/ftp.c
@@ -3290,7 +3290,7 @@ static CURLcode ftp_done(struct Curl_easy *data, CURLcode status,
 
   /* shut down the socket to inform the server we are done */
 
-#ifdef _WIN32_WCE
+#ifdef UNDER_CE
   shutdown(conn->sock[SECONDARYSOCKET], 2);  /* SD_BOTH */
 #endif
 
index 63eaeda0f26ea9b3f276a4bca170298d4eacbdd6..3bfcf707a44b16694c82a16450b9275b6f8599b6 100644 (file)
@@ -31,7 +31,7 @@
 
 static char *GetEnv(const char *variable)
 {
-#if defined(_WIN32_WCE) || defined(CURL_WINDOWS_UWP) || \
+#if defined(CURL_WINDOWS_UWP) || defined(UNDER_CE) || \
   defined(__ORBIS__) || defined(__PROSPERO__) /* PlayStation 4 and 5 */
   (void)variable;
   return NULL;
index e0589adbfb1344751aa4ca3319d06d9d5ec443f8..0eefba628c8b30a028be627fab6fca46a315d284 100644 (file)
@@ -42,7 +42,9 @@
 #endif
 
 #include <setjmp.h>
+#ifndef UNDER_CE
 #include <signal.h>
+#endif
 
 #include "urldata.h"
 #include "sendf.h"
index a447f300de17e233461d8036f64b7865d5a8451e..f666f55c8893055689ffb3598e64a01f7ac7f34f 100644 (file)
@@ -74,7 +74,7 @@ static char *inet_ntop4(const unsigned char *src, char *dst, size_t size)
 
   len = strlen(tmp);
   if(len == 0 || len >= size) {
-    errno = ENOSPC;
+    CURL_SETERRNO(ENOSPC);
     return NULL;
   }
   strcpy(dst, tmp);
@@ -153,7 +153,7 @@ static char *inet_ntop6(const unsigned char *src, char *dst, size_t size)
     if(i == 6 && best.base == 0 &&
         (best.len == 6 || (best.len == 5 && words[5] == 0xffff))) {
       if(!inet_ntop4(src + 12, tp, sizeof(tmp) - (tp - tmp))) {
-        errno = ENOSPC;
+        CURL_SETERRNO(ENOSPC);
         return NULL;
       }
       tp += strlen(tp);
@@ -171,7 +171,7 @@ static char *inet_ntop6(const unsigned char *src, char *dst, size_t size)
   /* Check for overflow, copy, and we are done.
    */
   if((size_t)(tp - tmp) > size) {
-    errno = ENOSPC;
+    CURL_SETERRNO(ENOSPC);
     return NULL;
   }
   strcpy(dst, tmp);
@@ -197,7 +197,7 @@ char *Curl_inet_ntop(int af, const void *src, char *buf, size_t size)
   case AF_INET6:
     return inet_ntop6((const unsigned char *)src, buf, size);
   default:
-    errno = EAFNOSUPPORT;
+    CURL_SETERRNO(EAFNOSUPPORT);
     return NULL;
   }
 }
index d0c04db1dae6471b86b9bf129281009d9de24ccc..ad9fe4da0b121d2891668768b1bebbb18ab19168 100644 (file)
@@ -80,7 +80,7 @@ Curl_inet_pton(int af, const char *src, void *dst)
   case AF_INET6:
     return inet_pton6(src, (unsigned char *)dst);
   default:
-    errno = EAFNOSUPPORT;
+    CURL_SETERRNO(EAFNOSUPPORT);
     return -1;
   }
   /* NOTREACHED */
index 9c284ede518f09bae569eca01b630f1c15134295..726e862c13ab4a75f4850675bb015cedb555e3d4 100644 (file)
@@ -117,7 +117,7 @@ static bool countcheck(const char *func, int line, const char *source)
       fprintf(stderr, "LIMIT %s:%d %s reached memlimit\n",
               source, line, func);
       fflush(curl_dbg_logfile); /* because it might crash now */
-      errno = ENOMEM;
+      CURL_SETERRNO(ENOMEM);
       return TRUE; /* RETURN ERROR! */
     }
     else
index 8bc9054407c0406cda093816d77ae278bcc0f702..29464876cc927b8ec3cd95ba7a53b7209948471c 100644 (file)
@@ -337,7 +337,7 @@ static int parsefmt(const char *format,
         case 'h':
           flags |= FLAGS_SHORT;
           break;
-#if defined(_WIN32) || defined(_WIN32_WCE)
+#ifdef _WIN32
         case 'I':
           /* Non-ANSI integer extensions I32 I64 */
           if((fmt[0] == '3') && (fmt[1] == '2')) {
@@ -356,7 +356,7 @@ static int parsefmt(const char *format,
 #endif
           }
           break;
-#endif /* _WIN32 || _WIN32_WCE */
+#endif /* _WIN32 */
         case 'l':
           if(flags & FLAGS_LONG)
             flags |= FLAGS_LONGLONG;
index 8715a4306d988851bb3535117e82d5e8b6269839..3605c1001ce15d965ff59c078f61c61e3f4f83da 100644 (file)
@@ -40,7 +40,7 @@
 /* return 0 on success, 1 on error */
 int Curl_rename(const char *oldpath, const char *newpath)
 {
-#ifdef _WIN32
+#if defined(_WIN32) && !defined(UNDER_CE)
   /* rename() on Windows does not overwrite, so we cannot use it here.
      MoveFileEx() will overwrite and is usually atomic, however it fails
      when there are open handles to the file. */
index 6ae541b4550697cf8f94ff06dd0aba37cd66cba3..0bb70419dbe203f47f1e0aa9731a17281b8413e5 100644 (file)
@@ -103,7 +103,9 @@ int Curl_socketpair(int domain, int type, int protocol,
  * This is a socketpair() implementation for Windows.
  */
 #include <string.h>
+#ifdef HAVE_IO_H
 #include <io.h>
+#endif
 #else
 #ifdef HAVE_NETDB_H
 #include <netdb.h>
index f69c81663b69f27405596b75770ad0607ab52d48..6f0710187367a3b814e1e918fe906fd715d6e438 100644 (file)
@@ -48,7 +48,7 @@
 #include "curl_memory.h"
 #include "memdebug.h"
 
-#if defined(_WIN32) || defined(_WIN32_WCE)
+#ifdef _WIN32
 #define PRESERVE_WINDOWS_ERROR_CODE
 #endif
 
@@ -768,7 +768,7 @@ get_winsock_error(int err, char *buf, size_t len)
 }
 #endif   /* USE_WINSOCK */
 
-#if defined(_WIN32) || defined(_WIN32_WCE)
+#ifdef _WIN32
 /* This is a helper function for Curl_strerror that converts Windows API error
  * codes (GetLastError) to error messages.
  * Returns NULL if no error message was found for error code.
@@ -810,7 +810,7 @@ get_winapi_error(int err, char *buf, size_t buflen)
 
   return *buf ? buf : NULL;
 }
-#endif /* _WIN32 || _WIN32_WCE */
+#endif /* _WIN32 */
 
 /*
  * Our thread-safe and smart strerror() replacement.
@@ -848,8 +848,8 @@ const char *Curl_strerror(int err, char *buf, size_t buflen)
 
   *buf = '\0';
 
-#if defined(_WIN32) || defined(_WIN32_WCE)
-#if defined(_WIN32)
+#ifdef _WIN32
+#ifndef UNDER_CE
   /* 'sys_nerr' is the maximum errno number, it is not widely portable */
   if(err >= 0 && err < sys_nerr)
     msnprintf(buf, buflen, "%s", sys_errlist[err]);
@@ -911,7 +911,7 @@ const char *Curl_strerror(int err, char *buf, size_t buflen)
     *p = '\0';
 
   if(errno != old_errno)
-    errno = old_errno;
+    CURL_SETERRNO(old_errno);
 
 #ifdef PRESERVE_WINDOWS_ERROR_CODE
   if(old_win_err != GetLastError())
@@ -925,7 +925,7 @@ const char *Curl_strerror(int err, char *buf, size_t buflen)
  * Curl_winapi_strerror:
  * Variant of Curl_strerror if the error code is definitely Windows API.
  */
-#if defined(_WIN32) || defined(_WIN32_WCE)
+#ifdef _WIN32
 const char *Curl_winapi_strerror(DWORD err, char *buf, size_t buflen)
 {
 #ifdef PRESERVE_WINDOWS_ERROR_CODE
@@ -951,7 +951,7 @@ const char *Curl_winapi_strerror(DWORD err, char *buf, size_t buflen)
 #endif
 
   if(errno != old_errno)
-    errno = old_errno;
+    CURL_SETERRNO(old_errno);
 
 #ifdef PRESERVE_WINDOWS_ERROR_CODE
   if(old_win_err != GetLastError())
@@ -960,7 +960,7 @@ const char *Curl_winapi_strerror(DWORD err, char *buf, size_t buflen)
 
   return buf;
 }
-#endif /* _WIN32 || _WIN32_WCE */
+#endif /* _WIN32 */
 
 #ifdef USE_WINDOWS_SSPI
 /*
@@ -1100,7 +1100,7 @@ const char *Curl_sspi_strerror(int err, char *buf, size_t buflen)
 #endif
 
   if(errno != old_errno)
-    errno = old_errno;
+    CURL_SETERRNO(old_errno);
 
 #ifdef PRESERVE_WINDOWS_ERROR_CODE
   if(old_win_err != GetLastError())
index 6806867345315e4b19b8db6d065a24b0661f3dff..069acfc2abd4d5320bb7e693ca40d41f3828fabc 100644 (file)
@@ -29,7 +29,7 @@
 #define STRERROR_LEN 256 /* a suitable length */
 
 const char *Curl_strerror(int err, char *buf, size_t buflen);
-#if defined(_WIN32) || defined(_WIN32_WCE)
+#ifdef _WIN32
 const char *Curl_winapi_strerror(DWORD err, char *buf, size_t buflen);
 #endif
 #ifdef USE_WINDOWS_SSPI
index 5ab711871e5011f9d5b08b6a532b2cab699f26da..bfe1606776ddd003480ac4465d1e61f159cb33cc 100644 (file)
@@ -96,9 +96,15 @@ CURLcode Curl_win32_init(long flags)
   s_hIpHlpApiDll = Curl_load_library(TEXT("iphlpapi.dll"));
   if(s_hIpHlpApiDll) {
     /* Get the address of the if_nametoindex function */
+#ifdef UNDER_CE
+    #define CURL_TEXT(n) TEXT(n)
+#else
+    #define CURL_TEXT(n) (n)
+#endif
     IF_NAMETOINDEX_FN pIfNameToIndex =
       CURLX_FUNCTION_CAST(IF_NAMETOINDEX_FN,
-                          (GetProcAddress(s_hIpHlpApiDll, "if_nametoindex")));
+                          (GetProcAddress(s_hIpHlpApiDll,
+                                          CURL_TEXT("if_nametoindex"))));
 
     if(pIfNameToIndex)
       Curl_if_nametoindex = pIfNameToIndex;
@@ -150,7 +156,7 @@ typedef HMODULE (APIENTRY *LOADLIBRARYEX_FN)(LPCTSTR, HANDLE, DWORD);
 
 /* See function definitions in winbase.h */
 #ifdef UNICODE
-#  ifdef _WIN32_WCE
+#  ifdef UNDER_CE
 #    define LOADLIBARYEX  L"LoadLibraryExW"
 #  else
 #    define LOADLIBARYEX  "LoadLibraryExW"
@@ -175,7 +181,7 @@ typedef HMODULE (APIENTRY *LOADLIBRARYEX_FN)(LPCTSTR, HANDLE, DWORD);
  */
 HMODULE Curl_load_library(LPCTSTR filename)
 {
-#ifndef CURL_WINDOWS_UWP
+#if !defined(CURL_WINDOWS_UWP) && !defined(UNDER_CE)
   HMODULE hModule = NULL;
   LOADLIBRARYEX_FN pLoadLibraryEx = NULL;
 
index 56db9ae6b6fed2d4df3b02ad34bfad9acb22ba66..a6ee0a10fdcdbd903a84fdb3b7b6d92ef1580cdf 100644 (file)
@@ -39,7 +39,9 @@
 #ifdef HAVE_SYS_IOCTL_H
 #include <sys/ioctl.h>
 #endif
+#ifndef UNDER_CE
 #include <signal.h>
+#endif
 
 #ifdef HAVE_SYS_PARAM_H
 #include <sys/param.h>
index a3aac4f2fff771fc4391a3c283ccaef924acdd7d..04446dfd52ca0a4a4003b2900232ad97e48d0c72 100644 (file)
@@ -602,7 +602,6 @@ static int ipv4_normalize(struct dynbuf *host)
   if(*c == '[')
     return HOST_IPV6;
 
-  errno = 0; /* for strtoul */
   while(!done) {
     int rc;
     curl_off_t l;
index 2fecca097066b6e28717e43ceec26cc2535b2003..450a0bb9c6cbb91714d5cf85a68577839fab9ad9 100644 (file)
@@ -29,7 +29,6 @@
 
 #include "curl_printf.h"
 
-#include <errno.h>
 #include <rustls.h>
 
 #include "inet_pton.h"
index e57c5c47ec7250cc7cc1eb3cbf90bf2bc55cf8be..8c6fa06982bf6cd931e7fc354ea37f6974abdf55 100644 (file)
 #define CALG_SHA_256 0x0000800c
 #endif
 
+/* Work around typo in CeGCC (as of 0.59.1) w32api headers */
+#if defined(__MINGW32CE__) && \
+  !defined(ALG_CLASS_DHASH) && defined(ALG_CLASS_HASH)
+#define ALG_CLASS_DHASH ALG_CLASS_HASH
+#endif
+
 #ifndef PKCS12_NO_PERSIST_KEY
 #define PKCS12_NO_PERSIST_KEY 0x00008000
 #endif
      https://technet.microsoft.com/en-us/library/hh831771%28v=ws.11%29.aspx
    Or mingw-w64 9.0 or upper.
 */
-#if (defined(__MINGW32__) && __MINGW64_VERSION_MAJOR >= 9) || \
+#if (defined(__MINGW64_VERSION_MAJOR) && __MINGW64_VERSION_MAJOR >= 9) || \
   (defined(_MSC_VER) && (_MSC_VER >= 1800) && !defined(_USING_V110_SDK71_))
 #define HAS_ALPN_SCHANNEL
 static bool s_win_has_alpn;
@@ -880,7 +886,9 @@ schannel_connect_step1(struct Curl_cfilter *cf, struct Curl_easy *data)
   struct ssl_connect_data *connssl = cf->ctx;
   struct schannel_ssl_backend_data *backend =
     (struct schannel_ssl_backend_data *)connssl->backend;
+#ifndef UNDER_CE
   struct ssl_primary_config *conn_config = Curl_ssl_cf_get_primary_config(cf);
+#endif
   struct ssl_config_data *ssl_config = Curl_ssl_cf_get_config(cf, data);
   SecBuffer outbuf;
   SecBufferDesc outbuf_desc;
@@ -912,9 +920,9 @@ schannel_connect_step1(struct Curl_cfilter *cf, struct Curl_easy *data)
   backend->use_alpn = FALSE;
 #endif
 
-#ifdef _WIN32_WCE
+#ifdef UNDER_CE
 #ifdef HAS_MANUAL_VERIFY_API
-  /* certificate validation on CE does not seem to work right; we will
+  /* certificate validation on Windows CE does not seem to work right; we will
    * do it following a more manual process. */
   backend->use_manual_cred_validation = TRUE;
 #else
@@ -2373,7 +2381,7 @@ static void schannel_close(struct Curl_cfilter *cf, struct Curl_easy *data)
 
 static int schannel_init(void)
 {
-#ifdef HAS_ALPN_SCHANNEL
+#if defined(HAS_ALPN_SCHANNEL) && !defined(UNDER_CE)
   bool wine = FALSE;
   bool wine_has_alpn = FALSE;
 
@@ -2383,7 +2391,7 @@ static int schannel_init(void)
      Assume no WINE because WINE has no UWP support. */
   WINE_GET_VERSION_FN p_wine_get_version =
     CURLX_FUNCTION_CAST(WINE_GET_VERSION_FN,
-                        (GetProcAddress(GetModuleHandle(TEXT("ntdll")),
+                        (GetProcAddress(GetModuleHandleA("ntdll"),
                                         "wine_get_version")));
   wine = !!p_wine_get_version;
   if(wine) {
@@ -2399,7 +2407,7 @@ static int schannel_init(void)
     s_win_has_alpn = curlx_verify_windows_version(6, 3, 0, PLATFORM_WINNT,
                                                   VERSION_GREATER_THAN_EQUAL);
   }
-#endif /* HAS_ALPN_SCHANNEL */
+#endif /* HAS_ALPN_SCHANNEL && !UNDER_CE */
 
   return Curl_sspi_global_init() == CURLE_OK ? 1 : 0;
 }
@@ -2524,7 +2532,12 @@ static void schannel_checksum(const unsigned char *input,
     if(!CryptCreateHash(hProv, algId, 0, 0, &hHash))
       break; /* failed */
 
+#ifdef __MINGW32CE__
+    /* workaround for CeGCC, should be (const BYTE*) */
+    if(!CryptHashData(hHash, (BYTE*)input, (DWORD)inputlen, 0))
+#else
     if(!CryptHashData(hHash, input, (DWORD)inputlen, 0))
+#endif
       break; /* failed */
 
     /* get hash size */
index fede3908feba5920c7b4fc43454718c7ca2e0488..485b564ebe9a95c93b6409ccf6c4bd8aee086f3f 100644 (file)
 
 #ifdef HAS_MANUAL_VERIFY_API
 
+#ifdef __MINGW32CE__
+#define CERT_QUERY_OBJECT_BLOB 0x00000002
+#define CERT_QUERY_CONTENT_CERT 1
+#define CERT_QUERY_CONTENT_FLAG_CERT (1 << CERT_QUERY_CONTENT_CERT)
+#define CERT_QUERY_FORMAT_BINARY 1
+#define CERT_QUERY_FORMAT_BASE64_ENCODED 2
+#define CERT_QUERY_FORMAT_ASN_ASCII_HEX_ENCODED 3
+#define CERT_QUERY_FORMAT_FLAG_ALL               \
+  (1 << CERT_QUERY_FORMAT_BINARY) |              \
+  (1 << CERT_QUERY_FORMAT_BASE64_ENCODED) |      \
+  (1 << CERT_QUERY_FORMAT_ASN_ASCII_HEX_ENCODED)
+#define CERT_CHAIN_REVOCATION_CHECK_CHAIN 0x20000000
+#define CERT_NAME_DISABLE_IE4_UTF8_FLAG 0x00010000
+#define CERT_TRUST_IS_OFFLINE_REVOCATION 0x01000000
+#endif /* __MINGW32CE__ */
+
 #define MAX_CAFILE_SIZE 1048576 /* 1 MiB */
 #define BEGIN_CERT "-----BEGIN CERTIFICATE-----"
 #define END_CERT "\n-----END CERTIFICATE-----"
@@ -76,6 +92,7 @@ struct cert_chain_engine_config_win7 {
   HCERTSTORE hExclusiveTrustedPeople;
 };
 
+#ifndef UNDER_CE
 static int is_cr_or_lf(char c)
 {
   return c == '\r' || c == '\n';
@@ -330,9 +347,11 @@ cleanup:
 
   return result;
 }
+#endif
 
 #endif /* HAS_MANUAL_VERIFY_API */
 
+#ifndef UNDER_CE
 /*
  * Returns the number of characters necessary to populate all the host_names.
  * If host_names is not NULL, populate it with all the hostnames. Each string
@@ -511,15 +530,68 @@ static bool get_alt_name_info(struct Curl_easy *data,
 #endif
   return result;
 }
+#endif /* !UNDER_CE */
 
 /* Verify the server's hostname */
 CURLcode Curl_verify_host(struct Curl_cfilter *cf,
                           struct Curl_easy *data)
 {
-  struct ssl_connect_data *connssl = cf->ctx;
-  SECURITY_STATUS sspi_status;
   CURLcode result = CURLE_PEER_FAILED_VERIFICATION;
+  struct ssl_connect_data *connssl = cf->ctx;
   CERT_CONTEXT *pCertContextServer = NULL;
+#ifdef UNDER_CE
+  TCHAR cert_hostname_buff[256];
+  DWORD len;
+
+  /* This code does not support certificates with multiple alternative names.
+   * Right now we are only asking for the first preferred alternative name.
+   * Instead we would need to do all via CERT_NAME_SEARCH_ALL_NAMES_FLAG
+   * (If Windows CE supports that?) and run this section in a loop for each.
+   * https://msdn.microsoft.com/en-us/library/windows/desktop/aa376086.aspx
+   * curl: (51) schannel: CertGetNameString() certificate hostname
+   * (.google.com) did not match connection (google.com)
+   */
+  len = CertGetNameString(pCertContextServer,
+                          CERT_NAME_DNS_TYPE,
+                          CERT_NAME_DISABLE_IE4_UTF8_FLAG,
+                          NULL,
+                          cert_hostname_buff,
+                          256);
+  if(len > 0) {
+    /* Comparing the cert name and the connection hostname encoded as UTF-8
+     * is acceptable since both values are assumed to use ASCII
+     * (or some equivalent) encoding
+     */
+    char *cert_hostname = curlx_convert_tchar_to_UTF8(cert_hostname_buff);
+    if(!cert_hostname) {
+      result = CURLE_OUT_OF_MEMORY;
+    }
+    else{
+      const char *conn_hostname = connssl->peer.hostname;
+      if(Curl_cert_hostcheck(cert_hostname, strlen(cert_hostname),
+                             conn_hostname, strlen(conn_hostname))) {
+        infof(data,
+              "schannel: connection hostname (%s) validated "
+              "against certificate name (%s)\n",
+              conn_hostname, cert_hostname);
+        result = CURLE_OK;
+      }
+      else{
+        failf(data,
+              "schannel: connection hostname (%s) "
+              "does not match certificate name (%s)",
+              conn_hostname, cert_hostname);
+      }
+      Curl_safefree(cert_hostname);
+    }
+  }
+  else {
+    failf(data,
+          "schannel: CertGetNameString did not provide any "
+          "certificate name information");
+  }
+#else
+  SECURITY_STATUS sspi_status;
   TCHAR *cert_hostname_buff = NULL;
   size_t cert_hostname_buff_index = 0;
   const char *conn_hostname = connssl->peer.hostname;
@@ -664,6 +736,7 @@ cleanup:
 
   if(pCertContextServer)
     CertFreeCertificateContext(pCertContextServer);
+#endif /* !UNDER_CE */
 
   return result;
 }
@@ -681,15 +754,17 @@ CURLcode Curl_verify_certificate(struct Curl_cfilter *cf,
   CERT_CONTEXT *pCertContextServer = NULL;
   const CERT_CHAIN_CONTEXT *pChainContext = NULL;
   HCERTCHAINENGINE cert_chain_engine = NULL;
+#ifndef UNDER_CE
   HCERTSTORE trust_store = NULL;
   HCERTSTORE own_trust_store = NULL;
+#endif /* !UNDER_CE */
 
   DEBUGASSERT(BACKEND);
 
   sspi_status =
     Curl_pSecFn->QueryContextAttributes(&BACKEND->ctxt->ctxt_handle,
-                                     SECPKG_ATTR_REMOTE_CERT_CONTEXT,
-                                     &pCertContextServer);
+                                        SECPKG_ATTR_REMOTE_CERT_CONTEXT,
+                                        &pCertContextServer);
 
   if((sspi_status != SEC_E_OK) || !pCertContextServer) {
     char buffer[STRERROR_LEN];
@@ -698,6 +773,7 @@ CURLcode Curl_verify_certificate(struct Curl_cfilter *cf,
     result = CURLE_PEER_FAILED_VERIFICATION;
   }
 
+#ifndef UNDER_CE
   if(result == CURLE_OK &&
       (conn_config->CAfile || conn_config->ca_info_blob) &&
       BACKEND->use_manual_cred_validation) {
@@ -782,6 +858,7 @@ CURLcode Curl_verify_certificate(struct Curl_cfilter *cf,
       }
     }
   }
+#endif /* !UNDER_CE */
 
   if(result == CURLE_OK) {
     CERT_CHAIN_PARA ChainPara;
@@ -848,6 +925,7 @@ CURLcode Curl_verify_certificate(struct Curl_cfilter *cf,
     }
   }
 
+#ifndef UNDER_CE
   if(cert_chain_engine) {
     CertFreeCertificateChainEngine(cert_chain_engine);
   }
@@ -855,6 +933,7 @@ CURLcode Curl_verify_certificate(struct Curl_cfilter *cf,
   if(own_trust_store) {
     CertCloseStore(own_trust_store, 0);
   }
+#endif /* !UNDER_CE */
 
   if(pChainContext)
     CertFreeCertificateChain(pChainContext);
index 2618bc86cbcbcc0d146fdcb68db5bfc3506afed4..f93eecd2ae2b985a627dac029c82b38e08a5c0e2 100644 (file)
@@ -385,7 +385,10 @@ static CURLcode cf_ssl_peer_key_add_path(struct dynbuf *buf,
      * valid when used in another process with different CWD. However,
      * when a path does not exist, this does not work. Then, we add
      * the path as is. */
-#ifdef _WIN32
+#ifdef UNDER_CE
+    (void)is_local;
+    return Curl_dyn_addf(buf, ":%s-%s", name, path);
+#elif defined(_WIN32)
     char abspath[_MAX_PATH];
     if(_fullpath(abspath, path, _MAX_PATH))
       return Curl_dyn_addf(buf, ":%s-%s", name, abspath);
index ab4ebf96ce2ceabb32139f4b92e08407879029d7..9e62d4f3543955925d02e96d1816bc430d1da871 100644 (file)
@@ -107,7 +107,7 @@ if(CURL_HAS_LTO)
   set_target_properties(${EXE_NAME} PROPERTIES INTERPROCEDURAL_OPTIMIZATION TRUE)
 endif()
 
-if(ENABLE_UNICODE AND MINGW)
+if(ENABLE_UNICODE AND MINGW AND NOT MINGW32CE)
   target_link_libraries(${EXE_NAME} "-municode")
 endif()
 
index 4bcfc662d353fb45d6f9c57d88cabc19e2fe42ab..cbee7ca386de903cd85719b9dd496a693f5926fe 100644 (file)
@@ -66,7 +66,7 @@ unsigned int get_terminal_columns(void)
     struct winsize ts;
     if(!ioctl(STDIN_FILENO, TIOCGWINSZ, &ts))
       cols = (int)ts.ws_col;
-#elif defined(_WIN32) && !defined(CURL_WINDOWS_UWP)
+#elif defined(_WIN32) && !defined(CURL_WINDOWS_UWP) && !defined(UNDER_CE)
     {
       HANDLE  stderr_hnd = GetStdHandle(STD_ERROR_HANDLE);
       CONSOLE_SCREEN_BUFFER_INFO console_info;
index d9cf52437d91e9ad16f9c8c2bdf0a6b8a60420d3..5696b414722364a9b6f9389b7b0f711ef150e4de 100644 (file)
@@ -158,7 +158,7 @@ size_t tool_header_cb(char *ptr, size_t size, size_t nmemb, void *userdata)
           /*
            * Truncate the etag save stream, it can have an existing etag value.
            */
-#ifdef HAVE_FTRUNCATE
+#if defined(HAVE_FTRUNCATE) && !defined(__MINGW32CE__)
           if(ftruncate(fileno(etag_save->stream), 0)) {
             return CURL_WRITEFUNC_ERROR;
           }
index fb8d7a3a7ead6b1ae00a10ad4ac73ea645e06336..c3f4c5916c0a6272a86a4df6713cf9fbae4585b4 100644 (file)
@@ -91,7 +91,7 @@ size_t tool_read_cb(char *buffer, size_t sz, size_t nmemb, void *userdata)
   rc = read(per->infd, buffer, sz*nmemb);
   if(rc < 0) {
     if(errno == EAGAIN) {
-      errno = 0;
+      CURL_SETERRNO(0);
       config->readbusy = TRUE;
       return CURL_READFUNC_PAUSE;
     }
index 08eb7c354b7f6efc697bfd5f79bcb756d1499dbb..ca2f13a0c5255048eb15d4d8b11b32e246ed8bcc 100644 (file)
@@ -80,7 +80,7 @@ int tool_seek_cb(void *userdata, curl_off_t offset, int whence)
   }
 #endif
 
-#ifdef __AMIGA__
+#if defined(__AMIGA__) || defined(__MINGW32CE__)
   if(LSEEK_ERROR == lseek(per->infd, (off_t)offset, whence))
 #else
   if(LSEEK_ERROR == lseek(per->infd, offset, whence))
index 5d6ef1735d42ca93f5990600cfc0d78b5975fba5..f33f338d6562d96beedf5eb7db05c83012e4d6c8 100644 (file)
@@ -138,7 +138,7 @@ size_t tool_write_cb(char *buffer, size_t sz, size_t nmemb, void *userdata)
   struct OperationConfig *config = per->config;
   size_t bytes = sz * nmemb;
   bool is_tty = config->global->isatty;
-#ifdef _WIN32
+#if defined(_WIN32) && !defined(UNDER_CE)
   CONSOLE_SCREEN_BUFFER_INFO console_info;
   intptr_t fhnd;
 #endif
@@ -210,7 +210,7 @@ size_t tool_write_cb(char *buffer, size_t sz, size_t nmemb, void *userdata)
     }
   }
 
-#ifdef _WIN32
+#if defined(_WIN32) && !defined(UNDER_CE)
   fhnd = _get_osfhandle(fileno(outs->stream));
   /* if Windows console then UTF-8 must be converted to UTF-16 */
   if(isatty(fileno(outs->stream)) &&
index 772664c5fb49cd456a8f8516f95c24c2da420d1a..0536dff7d25c0530cc0c2ba77e97aa98e5d9ad97 100644 (file)
@@ -25,7 +25,7 @@
 
 #include <sys/stat.h>
 
-#ifdef _WIN32
+#if defined(_WIN32) && !defined(UNDER_CE)
 #  include <direct.h>
 #endif
 
index c075912318f4901dc4abd4735031f5bf5194a3cc..84227c110404d403f18986dc9d82212cb6dfd7e1 100644 (file)
@@ -561,7 +561,7 @@ char **__crt0_glob_function(char *arg)
 
 #ifdef _WIN32
 
-#if !defined(CURL_WINDOWS_UWP) && \
+#if !defined(CURL_WINDOWS_UWP) && !defined(UNDER_CE) && \
   !defined(CURL_DISABLE_CA_SEARCH) && !defined(CURL_CA_SEARCH_SAFE)
 /* Search and set the CA cert file for Windows.
  *
@@ -613,7 +613,7 @@ CURLcode FindWin32CACert(struct OperationConfig *config,
 struct curl_slist *GetLoadedModulePaths(void)
 {
   struct curl_slist *slist = NULL;
-#if !defined(CURL_WINDOWS_UWP)
+#if !defined(CURL_WINDOWS_UWP) && !defined(UNDER_CE)
   HANDLE hnd = INVALID_HANDLE_VALUE;
   MODULEENTRY32 mod = {0};
 
@@ -664,7 +664,7 @@ cleanup:
 
 bool tool_term_has_bold;
 
-#ifndef CURL_WINDOWS_UWP
+#if !defined(CURL_WINDOWS_UWP) && !defined(UNDER_CE)
 /* The terminal settings to restore on exit */
 static struct TerminalSettings {
   HANDLE hStdOut;
@@ -747,7 +747,7 @@ CURLcode win32_init(void)
 
   QueryPerformanceFrequency(&tool_freq);
 
-#ifndef CURL_WINDOWS_UWP
+#if !defined(CURL_WINDOWS_UWP) && !defined(UNDER_CE)
   init_terminal();
 #endif
 
index 4deddf64a1daf08fa94206a09412f612a3feeb59..1e9656f30f9f81bfe1dbe4b61e1e3ad9872dc9bb 100644 (file)
@@ -47,7 +47,7 @@ char **__crt0_glob_function(char *arg);
 
 #ifdef _WIN32
 
-#if !defined(CURL_WINDOWS_UWP) && \
+#if !defined(CURL_WINDOWS_UWP) && !defined(UNDER_CE) && \
   !defined(CURL_DISABLE_CA_SEARCH) && !defined(CURL_CA_SEARCH_SAFE)
 CURLcode FindWin32CACert(struct OperationConfig *config,
                          const TCHAR *bundle_file);
index 8d6b69d777b6054710b2037e01b108c6459c0c6d..e2ca982718cf5bcee5ffb16462dd4619c00370f4 100644 (file)
@@ -125,7 +125,11 @@ static struct tool_mime *tool_mime_new_filedata(struct tool_mime *parent,
     }
   }
   else {        /* Standard input. */
+#ifdef UNDER_CE
+    int fd = STDIN_FILENO;
+#else
     int fd = fileno(stdin);
+#endif
     char *data = NULL;
     curl_off_t size;
     curl_off_t origin;
index 6944059df740e32a3358b3b5c5f01867d2a38509..2b3bf04730784fccad92f787f3b8ab9931579e61 100644 (file)
@@ -2714,7 +2714,7 @@ ParameterError getparameter(const char *flag, /* f or -long-flag */
     case C_BUFFER: /* --buffer */
       /* disable the output I/O buffering. note that the option is called
          --buffer but is mostly used in the negative form: --no-buffer */
-      config->nobuffer = longopt ? !toggle : TRUE;
+      config->nobuffer = (bool)(longopt ? !toggle : TRUE);
       break;
     case C_REMOTE_NAME_ALL: /* --remote-name-all */
       config->default_node_flags = toggle ? GETOUT_USEREMOTE : 0;
@@ -2873,7 +2873,11 @@ ParameterError parse_args(struct GlobalConfig *global, int argc,
   struct OperationConfig *config = global->first;
 
   for(i = 1, stillflags = TRUE; i < argc && !result; i++) {
+#ifdef UNDER_CE
+    orig_opt = strdup(argv[i]);
+#else
     orig_opt = curlx_convert_tchar_to_UTF8(argv[i]);
+#endif
     if(!orig_opt)
       return PARAM_NO_MEM;
 
@@ -2887,7 +2891,11 @@ ParameterError parse_args(struct GlobalConfig *global, int argc,
       else {
         char *nextarg = NULL;
         if(i < (argc - 1)) {
+#ifdef UNDER_CE
+          nextarg = strdup(argv[i + 1]);
+#else
           nextarg = curlx_convert_tchar_to_UTF8(argv[i + 1]);
+#endif
           if(!nextarg) {
             curlx_unicodefree(orig_opt);
             return PARAM_NO_MEM;
index 91dfb4638ab910e77f429eb8daa91e5d2abd036c..eea46fb52672b916447d140474feb06216b22a6d 100644 (file)
@@ -46,7 +46,7 @@
 #  include iodef
 #endif
 
-#ifdef _WIN32
+#if defined(_WIN32) && !defined(UNDER_CE)
 #  include <conio.h>
 #endif
 
@@ -94,7 +94,7 @@ char *getpass_r(const char *prompt, char *buffer, size_t buflen)
 #define DONE
 #endif /* __VMS */
 
-#if defined(_WIN32)
+#ifdef _WIN32
 
 char *getpass_r(const char *prompt, char *buffer, size_t buflen)
 {
@@ -122,7 +122,7 @@ char *getpass_r(const char *prompt, char *buffer, size_t buflen)
   return buffer; /* we always return success */
 }
 #define DONE
-#endif /* _WIN32 */
+#endif /* _WIN32 && !UNDER_CE */
 
 #ifndef DONE /* not previously provided */
 
index c4ab858d12ba272e1ea6c3b5e9f6dbb243235407..5910adeb3b72d1def04c9147c99218f8c2901b17 100644 (file)
@@ -29,7 +29,9 @@
 #include <tchar.h>
 #endif
 
+#ifndef UNDER_CE
 #include <signal.h>
+#endif
 
 #ifdef HAVE_FCNTL_H
 #include <fcntl.h>
@@ -224,7 +226,7 @@ static void main_free(struct GlobalConfig *config)
 /*
 ** curl tool main function.
 */
-#ifdef _UNICODE
+#if defined(_UNICODE) && !defined(UNDER_CE)
 #if defined(__GNUC__) || defined(__clang__)
 /* GCC does not know about wmain() */
 #pragma GCC diagnostic push
@@ -242,7 +244,7 @@ int main(int argc, char *argv[])
 
   tool_init_stderr();
 
-#ifdef _WIN32
+#if defined(_WIN32) && !defined(UNDER_CE)
   /* Undocumented diagnostic option to list the full paths of all loaded
      modules. This is purposely pre-init. */
   if(argc == 2 && !_tcscmp(argv[1], _T("--dump-module-paths"))) {
@@ -252,6 +254,8 @@ int main(int argc, char *argv[])
     curl_slist_free_all(head);
     return head ? 0 : 1;
   }
+#endif
+#ifdef _WIN32
   /* win32_init must be called before other init routines. */
   result = win32_init();
   if(result) {
@@ -295,7 +299,7 @@ int main(int argc, char *argv[])
 #endif
 }
 
-#ifdef _UNICODE
+#if defined(_UNICODE) && !defined(UNDER_CE)
 #if defined(__GNUC__) || defined(__clang__)
 #pragma GCC diagnostic pop
 #endif
index 54cc47cd8386a5dc23e9632dc28877bb80cccef4..341775053127d11967af1417108434684cf15bdf 100644 (file)
@@ -664,7 +664,8 @@ static CURLcode post_per_transfer(struct GlobalConfig *global,
               outs->bytes);
         fflush(outs->stream);
         /* truncate file at the position where we started appending */
-#if defined(HAVE_FTRUNCATE) && !defined(__DJGPP__) && !defined(__AMIGA__)
+#if defined(HAVE_FTRUNCATE) && !defined(__DJGPP__) && !defined(__AMIGA__) && \
+  !defined(__MINGW32CE__)
         if(ftruncate(fileno(outs->stream), outs->init)) {
           /* when truncate fails, we cannot just append as then we will
              create something strange, bail out */
@@ -3003,7 +3004,8 @@ static CURLcode cacertpaths(struct OperationConfig *config)
       fclose(cafile);
       config->cacert = strdup(cacert);
     }
-#elif !defined(CURL_WINDOWS_UWP) && !defined(CURL_DISABLE_CA_SEARCH)
+#elif !defined(CURL_WINDOWS_UWP) && !defined(UNDER_CE) && \
+  !defined(CURL_DISABLE_CA_SEARCH)
     result = FindWin32CACert(config, TEXT("curl-ca-bundle.crt"));
     if(result)
       goto fail;
@@ -3130,7 +3132,12 @@ static CURLcode run_all_transfers(struct GlobalConfig *global,
 CURLcode operate(struct GlobalConfig *global, int argc, argv_item_t argv[])
 {
   CURLcode result = CURLE_OK;
-  char *first_arg = argc > 1 ? curlx_convert_tchar_to_UTF8(argv[1]) : NULL;
+  char *first_arg;
+#ifdef UNDER_CE
+  first_arg = argc > 1 ? strdup(argv[1]) : NULL;
+#else
+  first_arg = argc > 1 ? curlx_convert_tchar_to_UTF8(argv[1]) : NULL;
+#endif
 
 #ifdef HAVE_SETLOCALE
   /* Override locale for number parsing (only) */
index fc6da854548ac29edf8ec63558ff6de4731cf51a..7cd1354a66268217b9f660e736a71f23c0779781 100644 (file)
@@ -230,7 +230,7 @@ static ParameterError getnum(long *val, const char *str, int base)
     long num;
     if(!str[0])
       return PARAM_BLANK_STRING;
-    errno = 0;
+    CURL_SETERRNO(0);
     num = strtol(str, &endptr, base);
     if(errno == ERANGE)
       return PARAM_NUMBER_TOO_LARGE;
@@ -319,7 +319,7 @@ static ParameterError str2double(double *val, const char *str, double max)
   if(str) {
     char *endptr;
     double num;
-    errno = 0;
+    CURL_SETERRNO(0);
     num = strtod(str, &endptr);
     if(errno == ERANGE)
       return PARAM_NUMBER_TOO_LARGE;
@@ -577,7 +577,7 @@ ParameterError str2offset(curl_off_t *val, const char *str)
       return PARAM_BAD_NUMERIC;
   }
 #else
-  errno = 0;
+  CURL_SETERRNO(0);
   *val = strtol(str, &endptr, 0);
   if((*val == LONG_MIN || *val == LONG_MAX) && errno == ERANGE)
     return PARAM_NUMBER_TOO_LARGE;
index b9fd56b300bad550f0df09208f9662ce0de3a7b8..2ac34e9d13983c947949e875bca44670d3f86a59 100644 (file)
@@ -64,7 +64,7 @@ int parseconfig(const char *filename, struct GlobalConfig *global)
       }
       filename = pathalloc = curlrc;
     }
-#ifdef _WIN32 /* Windows */
+#if defined(_WIN32) && !defined(UNDER_CE)
     else {
       char *fullp;
       /* check for .curlrc then _curlrc in the dir of the executable */
index 8c89e60275978344d74ceb6cba8a554730d2eca7..cafe373ea83501c3c0f5cc0b0224e34ea0215bbf 100644 (file)
@@ -81,15 +81,25 @@ extern FILE *tool_stderr;
 #  define CURL_STRICMP(p1, p2)  strcmp(p1, p2)
 #endif
 
-#if defined(_WIN32)
+#ifdef _WIN32
 /* set in win32_init() */
 extern LARGE_INTEGER tool_freq;
 extern bool tool_isVistaOrGreater;
 /* set in init_terminal() */
 extern bool tool_term_has_bold;
+
+#ifdef UNDER_CE
+#  undef isatty
+#  define isatty(fd) 0  /* fd is void*, expects int */
+#  undef _get_osfhandle
+#  define _get_osfhandle(fd) (fd)
+#  undef _getch
+#  define _getch() 0
+#  undef STDIN_FILENO
+#  define STDIN_FILENO 0
 #endif
 
-#if defined(_WIN32) && !defined(HAVE_FTRUNCATE)
+#ifndef HAVE_FTRUNCATE
 
 int tool_ftruncate64(int fd, curl_off_t where);
 
@@ -99,7 +109,8 @@ int tool_ftruncate64(int fd, curl_off_t where);
 #define HAVE_FTRUNCATE 1
 #define USE_TOOL_FTRUNCATE 1
 
-#endif /* _WIN32 && ! HAVE_FTRUNCATE */
+#endif /* ! HAVE_FTRUNCATE */
+#endif /* _WIN32 */
 
 
 #endif /* HEADER_CURL_TOOL_SETUP_H */
index 0fb8004f6b0481e19befcb244aa2b6db470337af..8370058661a31198663274470b6a28e454270543 100644 (file)
@@ -215,7 +215,7 @@ static CURLcode glob_range(struct URLGlob *glob, char **patternp,
 
       if(end_c == ':') {
         char *endp;
-        errno = 0;
+        CURL_SETERRNO(0);
         step = strtoul(&pattern[4], &endp, 10);
         if(errno || &pattern[4] == endp || *endp != ']')
           step = 0;
@@ -269,7 +269,7 @@ static CURLcode glob_range(struct URLGlob *glob, char **patternp,
       }
     }
 
-    errno = 0;
+    CURL_SETERRNO(0);
     min_n = strtoul(pattern, &endp, 10);
     if(errno || (endp == pattern))
       endp = NULL;
@@ -284,14 +284,14 @@ static CURLcode glob_range(struct URLGlob *glob, char **patternp,
           endp = NULL;
           goto fail;
         }
-        errno = 0;
+        CURL_SETERRNO(0);
         max_n = strtoul(pattern, &endp, 10);
         if(errno)
           /* overflow */
           endp = NULL;
         else if(*endp == ':') {
           pattern = endp + 1;
-          errno = 0;
+          CURL_SETERRNO(0);
           step_n = strtoul(pattern, &endp, 10);
           if(errno)
             /* over/underflow situation */
index 8a078890d4d449621c5781c5f2544408f9891a7d..c1891283b5129593dd5679938858b8dcdda52254 100644 (file)
@@ -188,12 +188,10 @@ int struplocompare4sort(const void *p1, const void *p2)
 
 #ifdef USE_TOOL_FTRUNCATE
 
-#ifdef _WIN32_WCE
+#ifdef UNDER_CE
 /* 64-bit lseek-like function unavailable */
 #  undef _lseeki64
 #  define _lseeki64(hnd,ofs,whence) lseek(hnd,ofs,whence)
-#  undef _get_osfhandle
-#  define _get_osfhandle(fd) (fd)
 #endif
 
 /*
@@ -215,7 +213,7 @@ int tool_ftruncate64(int fd, curl_off_t where)
 
 #endif /* USE_TOOL_FTRUNCATE */
 
-#ifdef _WIN32
+#if defined(_WIN32) && !defined(UNDER_CE)
 FILE *Curl_execpath(const char *filename, char **pathp)
 {
   static char filebuffer[512];
index 9a4e87dc438030ea010899a8b9b3c278109e00ac..c10a43f166bab6b65ede0a5581e627fcc8281166 100644 (file)
@@ -48,7 +48,7 @@ long tvdiff(struct timeval t1, struct timeval t2);
 int struplocompare(const char *p1, const char *p2);
 int struplocompare4sort(const void *p1, const void *p2);
 
-#ifdef _WIN32
+#if defined(_WIN32) && !defined(UNDER_CE)
 FILE *Curl_execpath(const char *filename, char **pathp);
 #endif
 
index e6e39c17096a5c418d7d0353f600a0dcdd439db4..0cf939fc6461aa12a2ca4c312b147f26b8d8c6a5 100644 (file)
@@ -29,8 +29,6 @@
 
 #include <stdio.h>
 #include <stdlib.h>
-/* #include <error.h> */
-#include <errno.h>
 
 static void log_line_start(FILE *log, const char *idsbuf, curl_infotype type)
 {
index 8e8d635597301c3bbb48c0be1a39cb169c484a23..9a63e779b32c1abbc0a3084e4a305a1febe72341 100644 (file)
@@ -30,8 +30,6 @@
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
-/* #include <error.h> */
-#include <errno.h>
 
 static void log_line_start(FILE *log, const char *idsbuf, curl_infotype type)
 {
index 61c70eb3b9b1704bd1cf69e86b7a6d2ebc592d0f..dd3732b465dc34aaf90e4c176e06b69e70b9df57 100644 (file)
@@ -29,7 +29,7 @@
 #define NUM_THREADS 100
 
 #ifdef _WIN32
-#if defined(_WIN32_WCE) || defined(CURL_WINDOWS_UWP)
+#if defined(CURL_WINDOWS_UWP) || defined(UNDER_CE)
 static DWORD WINAPI run_thread(LPVOID ptr)
 #else
 #include <process.h>
@@ -47,7 +47,7 @@ static unsigned int WINAPI run_thread(void *ptr)
 
 CURLcode test(char *URL)
 {
-#if defined(_WIN32_WCE) || defined(CURL_WINDOWS_UWP)
+#if defined(CURL_WINDOWS_UWP) || defined(UNDER_CE)
   typedef HANDLE curl_win_thread_handle_t;
 #else
   typedef uintptr_t curl_win_thread_handle_t;
@@ -78,7 +78,7 @@ CURLcode test(char *URL)
   for(i = 0; i < tid_count; i++) {
     curl_win_thread_handle_t th;
     results[i] = CURL_LAST; /* initialize with invalid value */
-#if defined(_WIN32_WCE) || defined(CURL_WINDOWS_UWP)
+#if defined(CURL_WINDOWS_UWP) || defined(UNDER_CE)
     th = CreateThread(NULL, 0, run_thread, &results[i], 0, NULL);
 #else
     th = _beginthreadex(NULL, 0, run_thread, &results[i], 0, NULL);
index a78608156d2c5bdbbc79d5d01167d9a1866f2561..0f69d266e849e708a7e0e01a687e614db71445cf 100644 (file)
@@ -74,7 +74,7 @@ static size_t write_memory_callback(char *contents, size_t size,
 
 static
 #if defined(USE_THREADS_POSIX) || defined(USE_THREADS_WIN32)
-#if defined(_WIN32_WCE) || defined(CURL_WINDOWS_UWP)
+#if defined(CURL_WINDOWS_UWP) || defined(UNDER_CE)
 DWORD
 #else
 unsigned int
index de383232ca2069f97f6a14e957ca031c05e499ee..7bc60ce764301d3cdaac0eeb03520e0a7af7a1a6 100644 (file)
@@ -63,7 +63,11 @@ CURLcode test(char *URL)
   }
 
   /* get the file size of the local file */
+#ifdef UNDER_CE
+  hd = stat(libtest_arg2, &file_info);
+#else
   hd = fstat(fileno(hd_src), &file_info);
+#endif
   if(hd == -1) {
     /* can't open file, bail out */
     fprintf(stderr, "fstat() failed with error: %d %s\n",
index f64070b56b86a16acd907d982790253bf3823662..17eb147c7a3dde379a40ce6736b6245305cccbe6 100644 (file)
@@ -63,7 +63,11 @@ CURLcode test(char *URL)
   }
 
   /* get the file size of the local file */
+#ifdef UNDER_CE
+  hd = stat(libtest_arg2, &file_info);
+#else
   hd = fstat(fileno(hd_src), &file_info);
+#endif
   if(hd == -1) {
     /* can't open file, bail out */
     fprintf(stderr, "fstat() failed with error: %d (%s)\n",
index 7dd53195e7e16fc5334076d4176692415a3c268d..2d2b8e55e5a0027ef98b7231dbbaa55738cbda70 100644 (file)
@@ -55,7 +55,11 @@ CURLcode test(char *URL)
   }
 
   /* get the file size of the local file */
+#ifdef UNDER_CE
+  hd = stat(libtest_arg2, &file_info);
+#else
   hd = fstat(fileno(hd_src), &file_info);
+#endif
   if(hd == -1) {
     /* can't open file, bail out */
     fprintf(stderr, "fstat() failed with error: %d %s\n",
index da9aea091e33d34ed3ad77261c4b34e1bef341cc..03c364164ab95e2828fe9c243627996122156ef2 100644 (file)
@@ -94,7 +94,11 @@ again:
 
       if(nread) {
         /* send received stuff to stdout */
+#ifdef UNDER_CE
+        if((size_t)fwrite(buf, sizeof(buf[0]), nread, stdout) != nread) {
+#else
         if((size_t)write(STDOUT_FILENO, buf, nread) != nread) {
+#endif
           fprintf(stderr, "write() failed: errno %d (%s)\n",
                   errno, strerror(errno));
           res = TEST_ERR_FAILURE;
index 5cbe8426be51284544fe5fb74ebe5de5594aeaac..e5e3583dc442d10b2476b2d485569f893a816010 100644 (file)
@@ -256,7 +256,11 @@ CURLcode test(char *URL)
   }
 
   /* get the file size of the local file */
+#ifdef UNDER_CE
+  hd = stat(libtest_arg2, &file_info);
+#else
   hd = fstat(fileno(hd_src), &file_info);
+#endif
   if(hd == -1) {
     /* can't open file, bail out */
     fprintf(stderr, "fstat() failed with error: %d (%s)\n",
index 49c15d5951a500886d74676855791d03282555e4..51593501ff6f78b45fb189bb0aeddccbbfb19b90 100644 (file)
@@ -133,7 +133,7 @@ double tutil_tvdiff_secs(struct timeval newer, struct timeval older)
 #ifdef _WIN32
 HMODULE win32_load_system_library(const TCHAR *filename)
 {
-#ifdef CURL_WINDOWS_UWP
+#if defined(CURL_WINDOWS_UWP) || defined(UNDER_CE)
   (void)filename;
   return NULL;
 #else
index 7927b9c7e799641bcd26a1a7c8c5c526180f5551..edf317710764a5c457778d1c713ade796e1f9456 100644 (file)
@@ -64,7 +64,9 @@ USEFUL = \
 
 UTIL = \
  util.c \
- util.h
+ util.h \
+ ../../lib/strerror.c \
+ ../../lib/strerror.h
 
 getpart_SOURCES = $(CURLX_SRCS) $(CURLX_HDRS) $(USEFUL) \
  testpart.c
index 759a66c5b6eab0aeb08e7f4bd53a17400862b4e6..7070a4f688d96e3ca3f1a9619ee13ae527fed542 100644 (file)
@@ -37,7 +37,9 @@
 
 /* based on sockfilt.c */
 
+#ifndef UNDER_CE
 #include <signal.h>
+#endif
 #ifdef HAVE_NETINET_IN_H
 #include <netinet/in.h>
 #endif
index 78a76daffcde6d3d98572acfd0517d3353aee212..b09d50368f65d699a7a62616d1674637e0bf0ff9 100644 (file)
@@ -33,7 +33,6 @@
  *
  */
 
-#include <signal.h>
 #ifdef HAVE_NETINET_IN_H
 #include <netinet/in.h>
 #endif
index 691063304ec007dd23ba6bbe8030889eccbfacfd..d3acefc0daff7f39b8571facecc48d52b1a30d19 100644 (file)
@@ -29,7 +29,9 @@
  * This source file was started based on curl's HTTP test suite server.
  */
 
+#ifndef UNDER_CE
 #include <signal.h>
+#endif
 #ifdef HAVE_NETINET_IN_H
 #include <netinet/in.h>
 #endif
@@ -474,7 +476,7 @@ static int ProcessRequest(struct httprequest *req)
       while(*ptr && ISSPACE(*ptr))
         ptr++;
       endptr = ptr;
-      errno = 0;
+      CURL_SETERRNO(0);
       clen = strtoul(ptr, &endptr, 10);
       if((ptr == endptr) || !ISSPACE(*endptr) || (ERANGE == errno)) {
         /* this assumes that a zero Content-Length is valid */
index 1cb2c61f40ef2637843abe8bccf32ee386f44e9d..e164f5f2a5e4760dd2452b8b75847da4cb63a169 100644 (file)
@@ -85,7 +85,9 @@
  * it!
  */
 
+#ifndef UNDER_CE
 #include <signal.h>
+#endif
 #ifdef HAVE_NETINET_IN_H
 #include <netinet/in.h>
 #endif
@@ -151,7 +153,7 @@ enum sockmode {
   ACTIVE_DISCONNECT  /* as a client, disconnected from server */
 };
 
-#if defined(_WIN32) && !defined(CURL_WINDOWS_UWP)
+#if defined(_WIN32) && !defined(CURL_WINDOWS_UWP) && !defined(UNDER_CE)
 /*
  * read-wrapper to support reading from stdin on Windows.
  */
@@ -178,7 +180,7 @@ static ssize_t read_wincon(int fd, void *buf, size_t count)
     return rcount;
   }
 
-  errno = (int)GetLastError();
+  CURL_SETERRNO((int)GetLastError());
   return -1;
 }
 #undef  read
@@ -213,13 +215,15 @@ static ssize_t write_wincon(int fd, const void *buf, size_t count)
     return wcount;
   }
 
-  errno = (int)GetLastError();
+  CURL_SETERRNO((int)GetLastError());
   return -1;
 }
 #undef  write
 #define write(a,b,c) write_wincon(a,b,c)
 #endif
 
+#ifndef UNDER_CE
+
 /* On Windows, we sometimes get this for a broken pipe, seemingly
  * when the client just closed stdin? */
 #define CURL_WIN32_EPIPE      109
@@ -337,6 +341,7 @@ static bool read_stdin(void *buffer, size_t nbytes)
   }
   return TRUE;
 }
+#endif
 
 /*
  * write_stdout tries to write to stdio nbytes from the given buffer. This is a
@@ -347,7 +352,13 @@ static bool read_stdin(void *buffer, size_t nbytes)
 
 static bool write_stdout(const void *buffer, size_t nbytes)
 {
-  ssize_t nwrite = fullwrite(fileno(stdout), buffer, nbytes);
+  ssize_t nwrite;
+#ifdef UNDER_CE
+  puts(buffer);
+  nwrite = nbytes;
+#else
+  nwrite = fullwrite(fileno(stdout), buffer, nbytes);
+#endif
   if(nwrite != (ssize_t)nbytes) {
     logmsg("exiting...");
     return FALSE;
@@ -355,6 +366,7 @@ static bool write_stdout(const void *buffer, size_t nbytes)
   return TRUE;
 }
 
+#ifndef UNDER_CE
 static void lograw(unsigned char *buffer, ssize_t len)
 {
   char data[120];
@@ -426,9 +438,10 @@ static bool read_data_block(unsigned char *buffer, ssize_t maxlen,
 
   return TRUE;
 }
+#endif
 
 
-#if defined(USE_WINSOCK) && !defined(CURL_WINDOWS_UWP)
+#if defined(USE_WINSOCK) && !defined(CURL_WINDOWS_UWP) && !defined(UNDER_CE)
 /*
  * Winsock select() does not support standard file descriptors,
  * it can only check SOCKETs. The following function is an attempt
@@ -446,12 +459,8 @@ struct select_ws_wait_data {
   HANDLE signal; /* internal event to signal handle trigger */
   HANDLE abort;  /* internal event to abort waiting threads */
 };
-#ifdef _WIN32_WCE
-static DWORD WINAPI select_ws_wait_thread(LPVOID lpParameter)
-#else
 #include <process.h>
 static unsigned int WINAPI select_ws_wait_thread(void *lpParameter)
-#endif
 {
   struct select_ws_wait_data *data;
   HANDLE signal, handle, handles[2];
@@ -594,11 +603,7 @@ static unsigned int WINAPI select_ws_wait_thread(void *lpParameter)
 }
 static HANDLE select_ws_wait(HANDLE handle, HANDLE signal, HANDLE abort)
 {
-#ifdef _WIN32_WCE
-  typedef HANDLE curl_win_thread_handle_t;
-#else
   typedef uintptr_t curl_win_thread_handle_t;
-#endif
   struct select_ws_wait_data *data;
   curl_win_thread_handle_t thread;
 
@@ -610,11 +615,7 @@ static HANDLE select_ws_wait(HANDLE handle, HANDLE signal, HANDLE abort)
     data->abort = abort;
 
     /* launch waiting thread */
-#ifdef _WIN32_WCE
-    thread = CreateThread(NULL, 0,  &select_ws_wait_thread, data, 0, NULL);
-#else
     thread = _beginthreadex(NULL, 0, &select_ws_wait_thread, data, 0, NULL);
-#endif
 
     /* free data if thread failed to launch */
     if(!thread) {
@@ -646,7 +647,7 @@ static int select_ws(int nfds, fd_set *readfds, fd_set *writefds,
 
   /* check if the input value is valid */
   if(nfds < 0) {
-    errno = EINVAL;
+    CURL_SETERRNO(EINVAL);
     return -1;
   }
 
@@ -667,7 +668,7 @@ static int select_ws(int nfds, fd_set *readfds, fd_set *writefds,
   /* create internal event to abort waiting threads */
   abort = CreateEvent(NULL, TRUE, FALSE, NULL);
   if(!abort) {
-    errno = ENOMEM;
+    CURL_SETERRNO(ENOMEM);
     return -1;
   }
 
@@ -675,7 +676,7 @@ static int select_ws(int nfds, fd_set *readfds, fd_set *writefds,
   data = calloc(nfds, sizeof(struct select_ws_data));
   if(!data) {
     CloseHandle(abort);
-    errno = ENOMEM;
+    CURL_SETERRNO(ENOMEM);
     return -1;
   }
 
@@ -684,7 +685,7 @@ static int select_ws(int nfds, fd_set *readfds, fd_set *writefds,
   if(!handles) {
     CloseHandle(abort);
     free(data);
-    errno = ENOMEM;
+    CURL_SETERRNO(ENOMEM);
     return -1;
   }
 
@@ -900,6 +901,7 @@ static int select_ws(int nfds, fd_set *readfds, fd_set *writefds,
 #endif  /* USE_WINSOCK */
 
 
+#ifndef UNDER_CE
 /* Perform the disconnect handshake with sockfilt
  * This involves waiting for the disconnect acknowledgment after the DISC
  * command, while throwing away anything else that might come in before
@@ -954,6 +956,7 @@ static bool disc_handshake(void)
   } while(TRUE);
   return TRUE;
 }
+#endif
 
 /*
   sockfdp is a pointer to an established stream or CURL_SOCKET_BAD
@@ -965,6 +968,12 @@ static bool juggle(curl_socket_t *sockfdp,
                    curl_socket_t listenfd,
                    enum sockmode *mode)
 {
+#ifdef UNDER_CE
+  (void)sockfdp;
+  (void)listenfd;
+  (void)mode;
+  return FALSE;
+#else
   struct timeval timeout;
   fd_set fds_read;
   fd_set fds_write;
@@ -1236,6 +1245,7 @@ static bool juggle(curl_socket_t *sockfdp,
   }
 
   return TRUE;
+#endif
 }
 
 static curl_socket_t sockdaemon(curl_socket_t sock,
index f74d0b7ac2639a0051fe3621a85e22a3907db469..f63ffdb51b64ed2dcbe7340ff0fabc57dcccf396 100644 (file)
@@ -57,7 +57,9 @@
 
 /* based on sockfilt.c */
 
+#ifndef UNDER_CE
 #include <signal.h>
+#endif
 #ifdef HAVE_NETINET_IN_H
 #include <netinet/in.h>
 #endif
index ee7f74627295a01facca079a8a92acf7039aafe5..c42bfe90b5e68f5c4c17c79b406eef9a46b6325d 100644 (file)
@@ -30,7 +30,9 @@
 
  */
 
+#ifndef UNDER_CE
 #include <signal.h>
+#endif
 #ifdef HAVE_NETINET_IN_H
 #include <netinet/in.h>
 #endif
@@ -622,7 +624,7 @@ static int ProcessRequest(struct httprequest *req)
       while(*ptr && ISSPACE(*ptr))
         ptr++;
       endptr = ptr;
-      errno = 0;
+      CURL_SETERRNO(0);
       clen = strtoul(ptr, &endptr, 10);
       if((ptr == endptr) || !ISSPACE(*endptr) || (ERANGE == errno)) {
         /* this assumes that a zero Content-Length is valid */
index 2313d6d1f1a234f4d5103a13e51bcf89a4ea2a82..c296f7e20fe4ce6b3b13b9ed1cdf10f88a9063b8 100644 (file)
@@ -55,7 +55,9 @@
 #ifdef HAVE_SYS_IOCTL_H
 #include <sys/ioctl.h>
 #endif
+#ifndef UNDER_CE
 #include <signal.h>
+#endif
 #ifdef HAVE_FCNTL_H
 #include <fcntl.h>
 #endif
index 57ce45b0ec7da762e0f03b74777a48e0f6646d15..42a4f857e850f5674a8b6a64a3b1699e20f9144d 100644 (file)
@@ -23,7 +23,9 @@
  ***************************************************************************/
 #include "server_setup.h"
 
+#ifndef UNDER_CE
 #include <signal.h>
+#endif
 #ifdef HAVE_NETINET_IN_H
 #include <netinet/in.h>
 #endif
 #include <dos.h>  /* delay() */
 #endif
 
+#ifdef _WIN32
+#include "strerror.h"
+#endif
+
 #include "curlx.h" /* from the private lib dir */
 #include "getpart.h"
 #include "util.h"
@@ -136,22 +142,12 @@ void logmsg(const char *msg, ...)
 }
 
 #ifdef _WIN32
-/* use instead of strerror() on generic Windows */
-static const char *win32_strerror(int err, char *buf, size_t buflen)
-{
-  if(!FormatMessageA((FORMAT_MESSAGE_FROM_SYSTEM |
-                      FORMAT_MESSAGE_IGNORE_INSERTS), NULL, (DWORD)err,
-                     LANG_NEUTRAL, buf, (DWORD)buflen, NULL))
-    msnprintf(buf, buflen, "Unknown error %d (%#x)", err, err);
-  return buf;
-}
-
 /* use instead of perror() on generic Windows */
 void win32_perror(const char *msg)
 {
   char buf[512];
   int err = SOCKERRNO;
-  win32_strerror(err, buf, sizeof(buf));
+  Curl_winapi_strerror(err, buf, sizeof(buf));
   if(msg)
     fprintf(stderr, "%s: ", msg);
   fprintf(stderr, "%s\n", buf);
@@ -193,11 +189,11 @@ void win32_cleanup(void)
   _flushall();
 }
 
-/* socket-safe strerror (works on Winsock errors, too */
+/* socket-safe strerror (works on Winsock errors, too) */
 const char *sstrerror(int err)
 {
   static char buf[512];
-  return win32_strerror(err, buf, sizeof(buf));
+  return Curl_winapi_strerror(err, buf, sizeof(buf));
 }
 #endif  /* _WIN32 */
 
@@ -244,7 +240,7 @@ int wait_ms(int timeout_ms)
   if(!timeout_ms)
     return 0;
   if(timeout_ms < 0) {
-    errno = EINVAL;
+    CURL_SETERRNO(EINVAL);
     return -1;
   }
 #if defined(MSDOS)
@@ -503,12 +499,8 @@ static SIGHANDLER_T old_sigterm_handler = SIG_ERR;
 static SIGHANDLER_T old_sigbreak_handler = SIG_ERR;
 #endif
 
-#if defined(_WIN32) && !defined(CURL_WINDOWS_UWP)
-#ifdef _WIN32_WCE
-static DWORD thread_main_id = 0;
-#else
+#if defined(_WIN32) && !defined(CURL_WINDOWS_UWP) && !defined(UNDER_CE)
 static unsigned int thread_main_id = 0;
-#endif
 static HANDLE thread_main_window = NULL;
 static HWND hidden_main_window = NULL;
 #endif
@@ -529,6 +521,7 @@ HANDLE exit_event = NULL;
  * The first time this is called it will set got_exit_signal to one and
  * store in exit_signal the signal that triggered its execution.
  */
+#ifndef UNDER_CE
 static void exit_signal_handler(int signum)
 {
   int old_errno = errno;
@@ -542,10 +535,11 @@ static void exit_signal_handler(int signum)
 #endif
   }
   (void)signal(signum, exit_signal_handler);
-  errno = old_errno;
+  CURL_SETERRNO(old_errno);
 }
+#endif
 
-#ifdef _WIN32
+#if defined(_WIN32) && !defined(UNDER_CE)
 /* CTRL event handler for Windows Console applications to simulate
  * SIGINT, SIGTERM and SIGBREAK on CTRL events and trigger signal handler.
  *
@@ -593,7 +587,7 @@ static BOOL WINAPI ctrl_event_handler(DWORD dwCtrlType)
 }
 #endif
 
-#if defined(_WIN32) && !defined(CURL_WINDOWS_UWP)
+#if defined(_WIN32) && !defined(CURL_WINDOWS_UWP) && !defined(UNDER_CE)
 /* Window message handler for Windows applications to add support
  * for graceful process termination via taskkill (without /f) which
  * sends WM_CLOSE to all Windows of a process (even hidden ones).
@@ -625,12 +619,8 @@ static LRESULT CALLBACK main_window_proc(HWND hwnd, UINT uMsg,
 }
 /* Window message queue loop for hidden main window, details see above.
  */
-#ifdef _WIN32_WCE
-static DWORD WINAPI main_window_loop(LPVOID lpParameter)
-#else
 #include <process.h>
 static unsigned int WINAPI main_window_loop(void *lpParameter)
-#endif
 {
   WNDCLASS wc;
   BOOL ret;
@@ -678,6 +668,7 @@ static unsigned int WINAPI main_window_loop(void *lpParameter)
 }
 #endif
 
+#ifndef UNDER_CE
 static SIGHANDLER_T set_signal(int signum, SIGHANDLER_T handler,
                                bool restartable)
 {
@@ -707,6 +698,7 @@ static SIGHANDLER_T set_signal(int signum, SIGHANDLER_T handler,
   return oldhdlr;
 #endif
 }
+#endif
 
 void install_signal_handlers(bool keep_sigalrm)
 {
@@ -757,24 +749,17 @@ void install_signal_handlers(bool keep_sigalrm)
     logmsg("cannot install SIGBREAK handler: %s", strerror(errno));
 #endif
 #ifdef _WIN32
+#ifndef UNDER_CE
   if(!SetConsoleCtrlHandler(ctrl_event_handler, TRUE))
     logmsg("cannot install CTRL event handler");
+#endif
 
-#ifndef CURL_WINDOWS_UWP
+#if !defined(CURL_WINDOWS_UWP) && !defined(UNDER_CE)
   {
-#ifdef _WIN32_WCE
-    typedef HANDLE curl_win_thread_handle_t;
-#else
     typedef uintptr_t curl_win_thread_handle_t;
-#endif
     curl_win_thread_handle_t thread;
-#ifdef _WIN32_WCE
-    thread = CreateThread(NULL, 0, &main_window_loop,
-                          (LPVOID)GetModuleHandle(NULL), 0, &thread_main_id);
-#else
     thread = _beginthreadex(NULL, 0, &main_window_loop,
                             (void *)GetModuleHandle(NULL), 0, &thread_main_id);
-#endif
     thread_main_window = (HANDLE)thread;
     if(!thread_main_window || !thread_main_id)
       logmsg("cannot start main window loop");
@@ -814,8 +799,10 @@ void restore_signal_handlers(bool keep_sigalrm)
     (void) set_signal(SIGBREAK, old_sigbreak_handler, FALSE);
 #endif
 #ifdef _WIN32
+#ifndef UNDER_CE
   (void)SetConsoleCtrlHandler(ctrl_event_handler, FALSE);
-#ifndef CURL_WINDOWS_UWP
+#endif
+#if !defined(CURL_WINDOWS_UWP) && !defined(UNDER_CE)
   if(thread_main_window && thread_main_id) {
     if(PostThreadMessage(thread_main_id, WM_APP, 0, 0)) {
       if(WaitForSingleObjectEx(thread_main_window, INFINITE, TRUE)) {
index 6b2aca842c8817067311f30be1be1eb8ebc3c0d4..8d2dd042eaa4bdb5ca371a0c619762ed98876d4f 100644 (file)
@@ -40,9 +40,6 @@
 #include <inet.h>
 #endif
 
-#include <setjmp.h>
-#include <signal.h>
-
 #include "urldata.h"
 #include "connect.h"
 #include "cfilters.h"