diff options
author | Viktor Szakats <commit@vsz.me> | 2022-11-01 22:27:28 +0000 |
---|---|---|
committer | Viktor Szakats <commit@vsz.me> | 2022-11-01 22:27:28 +0000 |
commit | b563a92cd6797ec40d7cd73d51f9c31e637463f4 (patch) | |
tree | 47afd98d829bf281aac506c010f7355537b014d5 /lib | |
parent | 480ac6e54daa1df1bf17a95931eab412e26bd608 (diff) | |
download | curl-b563a92cd6797ec40d7cd73d51f9c31e637463f4.tar.gz |
tidy-up: process.h detection and use
This patch aims to cleanup the use of `process.h` header and the macro
`HAVE_PROCESS_H` associated with it.
- `process.h` is always available on Windows. In curl, it is required
only for `_beginthreadex()` in `lib/curl_threads.c`.
- `process.h` is also available in MS-DOS. In curl, its only use was in
`lib/smb.c` for `getpid()`. But `getpid()` is in fact declared by
`unistd.h`, which is always enabled via `lib/config-dos.h`. So the
header is not necessary.
- `HAVE_PROCESS_H` was detected by CMake, forced to 1 on Windows and
left to real detection for other platforms.
It was also set to always-on in `lib/config-win32.h` and
`lib/config-dos.h`.
In autotools builds, there was no detection and the macro was never
set.
Based on these observations, in this patch we:
- Rework Windows `getpid` logic in `lib/smb.c` to always use the
equivalent direct Win32 API function `GetCurrentProcessId()`, as we
already did for Windows UWP apps. This makes `process.h` unnecessary
here on Windows.
- Stop #including `process.h` into files where it was not necessary.
This is everywhere, except `lib/curl_threads.c`.
> Strangely enough, `lib/curl_threads.c` compiled fine with autotools
> because `process.h` is also indirecty included via `unistd.h`. This
> might have been broken in autotools MSVC builds, where the latter
> header is missing.
- Delete all remaining `HAVE_PROCESS_H` feature guards, for they were
unnecessary.
- Delete `HAVE_PROCESS_H` detection from CMake and predefined values
from `lib/config-*.h` headers.
Reviewed-by: Jay Satiro
Closes #9703
Diffstat (limited to 'lib')
-rw-r--r-- | lib/asyn-ares.c | 4 | ||||
-rw-r--r-- | lib/asyn-thread.c | 10 | ||||
-rw-r--r-- | lib/config-dos.h | 1 | ||||
-rw-r--r-- | lib/config-win32.h | 5 | ||||
-rw-r--r-- | lib/config-win32ce.h | 3 | ||||
-rw-r--r-- | lib/curl_config.h.cmake | 3 | ||||
-rw-r--r-- | lib/curl_threads.c | 4 | ||||
-rw-r--r-- | lib/hostasyn.c | 4 | ||||
-rw-r--r-- | lib/hostip.c | 4 | ||||
-rw-r--r-- | lib/hostip4.c | 4 | ||||
-rw-r--r-- | lib/hostip6.c | 4 | ||||
-rw-r--r-- | lib/hostsyn.c | 4 | ||||
-rw-r--r-- | lib/smb.c | 7 | ||||
-rw-r--r-- | lib/vtls/mbedtls_threadlock.c | 13 | ||||
-rw-r--r-- | lib/vtls/mbedtls_threadlock.h | 2 |
15 files changed, 11 insertions, 61 deletions
diff --git a/lib/asyn-ares.c b/lib/asyn-ares.c index 33edba139..993222b83 100644 --- a/lib/asyn-ares.c +++ b/lib/asyn-ares.c @@ -47,10 +47,6 @@ #include <inet.h> #endif -#ifdef HAVE_PROCESS_H -#include <process.h> -#endif - #if (defined(NETWARE) && defined(__NOVELL_LIBC__)) #undef in_addr_t #define in_addr_t unsigned long diff --git a/lib/asyn-thread.c b/lib/asyn-thread.c index e121c516f..283629e84 100644 --- a/lib/asyn-thread.c +++ b/lib/asyn-thread.c @@ -44,14 +44,8 @@ #include <inet.h> #endif -#if defined(USE_THREADS_POSIX) -# ifdef HAVE_PTHREAD_H -# include <pthread.h> -# endif -#elif defined(USE_THREADS_WIN32) -# ifdef HAVE_PROCESS_H -# include <process.h> -# endif +#if defined(USE_THREADS_POSIX) && defined(HAVE_PTHREAD_H) +# include <pthread.h> #endif #if (defined(NETWARE) && defined(__NOVELL_LIBC__)) diff --git a/lib/config-dos.h b/lib/config-dos.h index 8e3c940d9..34e8c5f51 100644 --- a/lib/config-dos.h +++ b/lib/config-dos.h @@ -56,7 +56,6 @@ #define HAVE_NETINET_IN_H 1 #define HAVE_NETINET_TCP_H 1 #define HAVE_NET_IF_H 1 -#define HAVE_PROCESS_H 1 #define HAVE_RECV 1 #define HAVE_SELECT 1 #define HAVE_SEND 1 diff --git a/lib/config-win32.h b/lib/config-win32.h index 00e8663d2..283738022 100644 --- a/lib/config-win32.h +++ b/lib/config-win32.h @@ -66,11 +66,6 @@ /* Define if you have the <netinet/in.h> header file. */ /* #define HAVE_NETINET_IN_H 1 */ -/* Define if you have the <process.h> header file. */ -#ifndef __SALFORDC__ -#define HAVE_PROCESS_H 1 -#endif - /* Define if you have the <signal.h> header file. */ #define HAVE_SIGNAL_H 1 diff --git a/lib/config-win32ce.h b/lib/config-win32ce.h index 308bfe9e0..e702a0c32 100644 --- a/lib/config-win32ce.h +++ b/lib/config-win32ce.h @@ -65,9 +65,6 @@ /* Define if you have the <stdlib.h> header file. */ #define HAVE_STDLIB_H 1 -/* Define if you have the <process.h> header file. */ -/* #define HAVE_PROCESS_H 1 */ - /* Define if you have the <sys/param.h> header file. */ /* #define HAVE_SYS_PARAM_H 1 */ diff --git a/lib/curl_config.h.cmake b/lib/curl_config.h.cmake index 2ce4a43c0..e12d48901 100644 --- a/lib/curl_config.h.cmake +++ b/lib/curl_config.h.cmake @@ -595,9 +595,6 @@ /* Define to 1 if you have the ws2tcpip.h header file. */ #cmakedefine HAVE_WS2TCPIP_H 1 -/* Define if you have the <process.h> header file. */ -#cmakedefine HAVE_PROCESS_H 1 - /* Define to 1 if you need the lber.h header file even with ldap.h */ #cmakedefine NEED_LBER_H 1 diff --git a/lib/curl_threads.c b/lib/curl_threads.c index eb8e13608..dff61676c 100644 --- a/lib/curl_threads.c +++ b/lib/curl_threads.c @@ -31,9 +31,7 @@ # include <pthread.h> # endif #elif defined(USE_THREADS_WIN32) -# ifdef HAVE_PROCESS_H -# include <process.h> -# endif +# include <process.h> #endif #include "curl_threads.h" diff --git a/lib/hostasyn.c b/lib/hostasyn.c index 0bfbe2ef8..df50d13e1 100644 --- a/lib/hostasyn.c +++ b/lib/hostasyn.c @@ -43,10 +43,6 @@ #include <inet.h> #endif -#ifdef HAVE_PROCESS_H -#include <process.h> -#endif - #include "urldata.h" #include "sendf.h" #include "hostip.h" diff --git a/lib/hostip.c b/lib/hostip.c index 941ecacf4..dd427a2c6 100644 --- a/lib/hostip.c +++ b/lib/hostip.c @@ -48,10 +48,6 @@ #include <signal.h> #endif -#ifdef HAVE_PROCESS_H -#include <process.h> -#endif - #include "urldata.h" #include "sendf.h" #include "hostip.h" diff --git a/lib/hostip4.c b/lib/hostip4.c index 1dd54e879..b0280cd09 100644 --- a/lib/hostip4.c +++ b/lib/hostip4.c @@ -43,10 +43,6 @@ #include <inet.h> #endif -#ifdef HAVE_PROCESS_H -#include <process.h> -#endif - #include "urldata.h" #include "sendf.h" #include "hostip.h" diff --git a/lib/hostip6.c b/lib/hostip6.c index c62c254c7..af8bc2302 100644 --- a/lib/hostip6.c +++ b/lib/hostip6.c @@ -43,10 +43,6 @@ #include <inet.h> #endif -#ifdef HAVE_PROCESS_H -#include <process.h> -#endif - #include "urldata.h" #include "sendf.h" #include "hostip.h" diff --git a/lib/hostsyn.c b/lib/hostsyn.c index ee54363bf..73d1e5056 100644 --- a/lib/hostsyn.c +++ b/lib/hostsyn.c @@ -43,10 +43,6 @@ #include <inet.h> #endif -#ifdef HAVE_PROCESS_H -#include <process.h> -#endif - #include "urldata.h" #include "sendf.h" #include "hostip.h" @@ -30,13 +30,8 @@ #define BUILDING_CURL_SMB_C -#ifdef HAVE_PROCESS_H -#include <process.h> -#ifdef CURL_WINDOWS_APP +#ifdef WIN32 #define getpid GetCurrentProcessId -#elif defined(WIN32) -#define getpid _getpid -#endif #endif #include "smb.h" diff --git a/lib/vtls/mbedtls_threadlock.c b/lib/vtls/mbedtls_threadlock.c index 3971e69b2..7d019ede5 100644 --- a/lib/vtls/mbedtls_threadlock.c +++ b/lib/vtls/mbedtls_threadlock.c @@ -26,13 +26,12 @@ #if defined(USE_MBEDTLS) && \ ((defined(USE_THREADS_POSIX) && defined(HAVE_PTHREAD_H)) || \ - (defined(USE_THREADS_WIN32) && defined(HAVE_PROCESS_H))) + defined(USE_THREADS_WIN32)) #if defined(USE_THREADS_POSIX) && defined(HAVE_PTHREAD_H) # include <pthread.h> # define MBEDTLS_MUTEX_T pthread_mutex_t -#elif defined(USE_THREADS_WIN32) && defined(HAVE_PROCESS_H) -# include <process.h> +#elif defined(USE_THREADS_WIN32) # define MBEDTLS_MUTEX_T HANDLE #endif @@ -60,7 +59,7 @@ int Curl_mbedtlsthreadlock_thread_setup(void) #if defined(USE_THREADS_POSIX) && defined(HAVE_PTHREAD_H) if(pthread_mutex_init(&mutex_buf[i], NULL)) return 0; /* pthread_mutex_init failed */ -#elif defined(USE_THREADS_WIN32) && defined(HAVE_PROCESS_H) +#elif defined(USE_THREADS_WIN32) mutex_buf[i] = CreateMutex(0, FALSE, 0); if(mutex_buf[i] == 0) return 0; /* CreateMutex failed */ @@ -81,7 +80,7 @@ int Curl_mbedtlsthreadlock_thread_cleanup(void) #if defined(USE_THREADS_POSIX) && defined(HAVE_PTHREAD_H) if(pthread_mutex_destroy(&mutex_buf[i])) return 0; /* pthread_mutex_destroy failed */ -#elif defined(USE_THREADS_WIN32) && defined(HAVE_PROCESS_H) +#elif defined(USE_THREADS_WIN32) if(!CloseHandle(mutex_buf[i])) return 0; /* CloseHandle failed */ #endif /* USE_THREADS_POSIX && HAVE_PTHREAD_H */ @@ -101,7 +100,7 @@ int Curl_mbedtlsthreadlock_lock_function(int n) "Error: mbedtlsthreadlock_lock_function failed\n")); return 0; /* pthread_mutex_lock failed */ } -#elif defined(USE_THREADS_WIN32) && defined(HAVE_PROCESS_H) +#elif defined(USE_THREADS_WIN32) if(WaitForSingleObject(mutex_buf[n], INFINITE) == WAIT_FAILED) { DEBUGF(fprintf(stderr, "Error: mbedtlsthreadlock_lock_function failed\n")); @@ -121,7 +120,7 @@ int Curl_mbedtlsthreadlock_unlock_function(int n) "Error: mbedtlsthreadlock_unlock_function failed\n")); return 0; /* pthread_mutex_unlock failed */ } -#elif defined(USE_THREADS_WIN32) && defined(HAVE_PROCESS_H) +#elif defined(USE_THREADS_WIN32) if(!ReleaseMutex(mutex_buf[n])) { DEBUGF(fprintf(stderr, "Error: mbedtlsthreadlock_unlock_function failed\n")); diff --git a/lib/vtls/mbedtls_threadlock.h b/lib/vtls/mbedtls_threadlock.h index 3a50d0381..22e8725ab 100644 --- a/lib/vtls/mbedtls_threadlock.h +++ b/lib/vtls/mbedtls_threadlock.h @@ -29,7 +29,7 @@ #ifdef USE_MBEDTLS #if (defined(USE_THREADS_POSIX) && defined(HAVE_PTHREAD_H)) || \ - (defined(USE_THREADS_WIN32) && defined(HAVE_PROCESS_H)) + defined(USE_THREADS_WIN32) int Curl_mbedtlsthreadlock_thread_setup(void); int Curl_mbedtlsthreadlock_thread_cleanup(void); |