From e31795501c38a9380291fed9d62c903989cfede1 Mon Sep 17 00:00:00 2001 From: Christian Grothoff Date: Sun, 6 Oct 2019 22:18:01 +0200 Subject: indentation fixes --- src/examples/fileserver_example.c | 84 +++++++------- src/microhttpd/basicauth.c | 87 +++++++------- src/microhttpd/memorypool.c | 239 +++++++++++++++++++------------------- src/microhttpd/mhd_threads.c | 165 +++++++++++++------------- 4 files changed, 295 insertions(+), 280 deletions(-) diff --git a/src/examples/fileserver_example.c b/src/examples/fileserver_example.c index b8935fa1..46e6aad6 100644 --- a/src/examples/fileserver_example.c +++ b/src/examples/fileserver_example.c @@ -34,7 +34,8 @@ #include #endif /* HAVE_FCNTL_H */ -#define PAGE "File not foundFile not found" +#define PAGE \ + "File not foundFile not found" #ifndef S_ISREG #define S_ISREG(x) (S_IFREG == (x & S_IFREG)) @@ -47,67 +48,67 @@ ahc_echo (void *cls, const char *method, const char *version, const char *upload_data, - size_t *upload_data_size, void **ptr) + size_t *upload_data_size, void **ptr) { static int aptr; struct MHD_Response *response; int ret; int fd; struct stat buf; - (void)cls; /* Unused. Silent compiler warning. */ - (void)version; /* Unused. Silent compiler warning. */ - (void)upload_data; /* Unused. Silent compiler warning. */ - (void)upload_data_size; /* Unused. Silent compiler warning. */ + (void) cls; /* Unused. Silent compiler warning. */ + (void) version; /* Unused. Silent compiler warning. */ + (void) upload_data; /* Unused. Silent compiler warning. */ + (void) upload_data_size; /* Unused. Silent compiler warning. */ if ( (0 != strcmp (method, MHD_HTTP_METHOD_GET)) && (0 != strcmp (method, MHD_HTTP_METHOD_HEAD)) ) return MHD_NO; /* unexpected method */ if (&aptr != *ptr) - { - /* do never respond on first call */ - *ptr = &aptr; - return MHD_YES; - } + { + /* do never respond on first call */ + *ptr = &aptr; + return MHD_YES; + } *ptr = NULL; /* reset when done */ /* WARNING: direct usage of url as filename is for example only! * NEVER pass received data directly as parameter to file manipulation * functions. Always check validity of data before using. */ - if (NULL != strstr(url, "../")) /* Very simplified check! */ + if (NULL != strstr (url, "../")) /* Very simplified check! */ fd = -1; /* Do not allow usage of parent directories. */ else fd = open (url + 1, O_RDONLY); if (-1 != fd) + { + if ( (0 != fstat (fd, &buf)) || + (! S_ISREG (buf.st_mode)) ) { - if ( (0 != fstat (fd, &buf)) || - (! S_ISREG (buf.st_mode)) ) - { - /* not a regular file, refuse to serve */ - if (0 != close (fd)) - abort (); - fd = -1; - } + /* not a regular file, refuse to serve */ + if (0 != close (fd)) + abort (); + fd = -1; } + } if (-1 == fd) - { - response = MHD_create_response_from_buffer (strlen (PAGE), - (void *) PAGE, - MHD_RESPMEM_PERSISTENT); - ret = MHD_queue_response (connection, MHD_HTTP_NOT_FOUND, response); - MHD_destroy_response (response); - } + { + response = MHD_create_response_from_buffer (strlen (PAGE), + (void *) PAGE, + MHD_RESPMEM_PERSISTENT); + ret = MHD_queue_response (connection, MHD_HTTP_NOT_FOUND, response); + MHD_destroy_response (response); + } else + { + response = MHD_create_response_from_fd64 (buf.st_size, fd); + if (NULL == response) { - response = MHD_create_response_from_fd64 (buf.st_size, fd); - if (NULL == response) - { - if (0 != close (fd)) - abort (); - return MHD_NO; - } - ret = MHD_queue_response (connection, MHD_HTTP_OK, response); - MHD_destroy_response (response); + if (0 != close (fd)) + abort (); + return MHD_NO; } + ret = MHD_queue_response (connection, MHD_HTTP_OK, response); + MHD_destroy_response (response); + } return ret; } @@ -118,11 +119,12 @@ main (int argc, char *const *argv) struct MHD_Daemon *d; if (argc != 2) - { - printf ("%s PORT\n", argv[0]); - return 1; - } - d = MHD_start_daemon (MHD_USE_THREAD_PER_CONNECTION | MHD_USE_INTERNAL_POLLING_THREAD | MHD_USE_ERROR_LOG, + { + printf ("%s PORT\n", argv[0]); + return 1; + } + d = MHD_start_daemon (MHD_USE_THREAD_PER_CONNECTION + | MHD_USE_INTERNAL_POLLING_THREAD | MHD_USE_ERROR_LOG, atoi (argv[1]), NULL, NULL, &ahc_echo, PAGE, MHD_OPTION_END); if (d == NULL) diff --git a/src/microhttpd/basicauth.c b/src/microhttpd/basicauth.c index 1d0c53ad..f1e38af4 100644 --- a/src/microhttpd/basicauth.c +++ b/src/microhttpd/basicauth.c @@ -31,7 +31,7 @@ /** * Beginning string for any valid Basic authentication header. */ -#define _BASIC_BASE "Basic " +#define _BASIC_BASE "Basic " /** @@ -40,12 +40,12 @@ * @param connection The MHD connection structure * @param password a pointer for the password * @return NULL if no username could be found, a pointer - * to the username if found + * to the username if found * @ingroup authentication */ char * MHD_basic_auth_get_username_password (struct MHD_Connection *connection, - char** password) + char**password) { const char *header; char *decode; @@ -55,7 +55,8 @@ MHD_basic_auth_get_username_password (struct MHD_Connection *connection, if ( (MHD_NO == MHD_lookup_connection_value_n (connection, MHD_HEADER_KIND, MHD_HTTP_HEADER_AUTHORIZATION, - MHD_STATICSTR_LEN_ (MHD_HTTP_HEADER_AUTHORIZATION), + MHD_STATICSTR_LEN_ ( + MHD_HTTP_HEADER_AUTHORIZATION), &header, NULL)) || (0 != strncmp (header, @@ -64,44 +65,44 @@ MHD_basic_auth_get_username_password (struct MHD_Connection *connection, return NULL; header += MHD_STATICSTR_LEN_ (_BASIC_BASE); if (NULL == (decode = BASE64Decode (header))) - { + { #ifdef HAVE_MESSAGES - MHD_DLOG (connection->daemon, - _("Error decoding basic authentication\n")); + MHD_DLOG (connection->daemon, + _ ("Error decoding basic authentication\n")); #endif - return NULL; - } + return NULL; + } /* Find user:password pattern */ if (NULL == (separator = strchr (decode, ':'))) - { + { #ifdef HAVE_MESSAGES - MHD_DLOG(connection->daemon, - _("Basic authentication doesn't contain ':' separator\n")); + MHD_DLOG (connection->daemon, + _ ("Basic authentication doesn't contain ':' separator\n")); #endif - free (decode); - return NULL; - } + free (decode); + return NULL; + } if (NULL == (user = strdup (decode))) - { - free (decode); - return NULL; - } + { + free (decode); + return NULL; + } user[separator - decode] = '\0'; /* cut off at ':' */ if (NULL != password) + { + *password = strdup (separator + 1); + if (NULL == *password) { - *password = strdup (separator + 1); - if (NULL == *password) - { #ifdef HAVE_MESSAGES - MHD_DLOG(connection->daemon, - _("Failed to allocate memory for password\n")); + MHD_DLOG (connection->daemon, + _ ("Failed to allocate memory for password\n")); #endif - free (decode); - free (user); - return NULL; - } + free (decode); + free (user); + return NULL; } + } free (decode); return user; } @@ -121,20 +122,20 @@ MHD_basic_auth_get_username_password (struct MHD_Connection *connection, */ int MHD_queue_basic_auth_fail_response (struct MHD_Connection *connection, - const char *realm, - struct MHD_Response *response) + const char *realm, + struct MHD_Response *response) { int ret; int res; - size_t hlen = strlen(realm) + strlen("Basic realm=\"\"") + 1; + size_t hlen = strlen (realm) + strlen ("Basic realm=\"\"") + 1; char *header; - header = (char *) malloc(hlen); + header = (char *) malloc (hlen); if (NULL == header) { #ifdef HAVE_MESSAGES - MHD_DLOG(connection->daemon, - "Failed to allocate memory for auth header\n"); + MHD_DLOG (connection->daemon, + "Failed to allocate memory for auth header\n"); #endif /* HAVE_MESSAGES */ return MHD_NO; } @@ -142,25 +143,27 @@ MHD_queue_basic_auth_fail_response (struct MHD_Connection *connection, hlen, "Basic realm=\"%s\"", realm); - if (res > 0 && (size_t)res < hlen) + if ((res > 0)&&((size_t) res < hlen)) ret = MHD_add_response_header (response, MHD_HTTP_HEADER_WWW_AUTHENTICATE, header); else ret = MHD_NO; - free(header); + free (header); if (MHD_YES == ret) + { ret = MHD_queue_response (connection, - MHD_HTTP_UNAUTHORIZED, - response); + MHD_HTTP_UNAUTHORIZED, + response); + } else - { + { #ifdef HAVE_MESSAGES - MHD_DLOG (connection->daemon, - _("Failed to add Basic auth header\n")); + MHD_DLOG (connection->daemon, + _ ("Failed to add Basic auth header\n")); #endif /* HAVE_MESSAGES */ - } + } return ret; } diff --git a/src/microhttpd/memorypool.c b/src/microhttpd/memorypool.c index 96c20ea6..ddfd08d3 100644 --- a/src/microhttpd/memorypool.c +++ b/src/microhttpd/memorypool.c @@ -45,13 +45,13 @@ #endif /* HAVE_SYSCONF */ /* define MAP_ANONYMOUS for Mac OS X */ -#if defined(MAP_ANON) && !defined(MAP_ANONYMOUS) +#if defined(MAP_ANON) && ! defined(MAP_ANONYMOUS) #define MAP_ANONYMOUS MAP_ANON #endif #if defined(_WIN32) #define MAP_FAILED NULL -#elif !defined(MAP_FAILED) -#define MAP_FAILED ((void*)-1) +#elif ! defined(MAP_FAILED) +#define MAP_FAILED ((void*) -1) #endif /** @@ -62,7 +62,8 @@ /** * Round up 'n' to a multiple of ALIGN_SIZE. */ -#define ROUND_TO_ALIGN(n) (((n)+(ALIGN_SIZE-1)) / (ALIGN_SIZE) * (ALIGN_SIZE)) +#define ROUND_TO_ALIGN(n) (((n) + (ALIGN_SIZE - 1)) \ + / (ALIGN_SIZE) *(ALIGN_SIZE)) #if defined(PAGE_SIZE) #define MHD_DEF_PAGE_SIZE_ PAGE_SIZE @@ -93,7 +94,7 @@ MHD_init_mem_pools_ (void) #elif defined(_WIN32) SYSTEM_INFO si; GetSystemInfo (&si); - MHD_sys_page_size_ = (size_t)si.dwPageSize; + MHD_sys_page_size_ = (size_t) si.dwPageSize; #else MHD_sys_page_size_ = MHD_DEF_PAGE_SIZE_; #endif /* _WIN32 */ @@ -151,45 +152,47 @@ MHD_pool_create (size_t max) #if defined(MAP_ANONYMOUS) || defined(_WIN32) if ( (max <= 32 * 1024) || (max < MHD_sys_page_size_ * 4 / 3) ) + { pool->memory = MAP_FAILED; + } else - { - /* Round up allocation to page granularity. */ - alloc_size = max + MHD_sys_page_size_ - 1; - alloc_size -= alloc_size % MHD_sys_page_size_; -#if defined(MAP_ANONYMOUS) && !defined(_WIN32) - pool->memory = mmap (NULL, - alloc_size, - PROT_READ | PROT_WRITE, - MAP_PRIVATE | MAP_ANONYMOUS, - -1, - 0); + { + /* Round up allocation to page granularity. */ + alloc_size = max + MHD_sys_page_size_ - 1; + alloc_size -= alloc_size % MHD_sys_page_size_; +#if defined(MAP_ANONYMOUS) && ! defined(_WIN32) + pool->memory = mmap (NULL, + alloc_size, + PROT_READ | PROT_WRITE, + MAP_PRIVATE | MAP_ANONYMOUS, + -1, + 0); #elif defined(_WIN32) - pool->memory = VirtualAlloc (NULL, - alloc_size, - MEM_COMMIT | MEM_RESERVE, - PAGE_READWRITE); + pool->memory = VirtualAlloc (NULL, + alloc_size, + MEM_COMMIT | MEM_RESERVE, + PAGE_READWRITE); #endif /* _WIN32 */ - } + } #else /* ! _WIN32 && ! MAP_ANONYMOUS */ pool->memory = MAP_FAILED; #endif /* ! _WIN32 && ! MAP_ANONYMOUS */ if (MAP_FAILED == pool->memory) + { + alloc_size = ROUND_TO_ALIGN (max); + pool->memory = malloc (alloc_size); + if (NULL == pool->memory) { - alloc_size = ROUND_TO_ALIGN(max); - pool->memory = malloc (alloc_size); - if (NULL == pool->memory) - { - free (pool); - return NULL; - } - pool->is_mmap = false; + free (pool); + return NULL; } + pool->is_mmap = false; + } #if defined(MAP_ANONYMOUS) || defined(_WIN32) else - { - pool->is_mmap = true; - } + { + pool->is_mmap = true; + } #endif /* _WIN32 || MAP_ANONYMOUS */ pool->pos = 0; pool->end = alloc_size; @@ -211,10 +214,10 @@ MHD_pool_destroy (struct MemoryPool *pool) mhd_assert (pool->end >= pool->pos); mhd_assert (pool->size >= pool->end - pool->pos); - if (!pool->is_mmap) + if (! pool->is_mmap) free (pool->memory); else -#if defined(MAP_ANONYMOUS) && !defined(_WIN32) +#if defined(MAP_ANONYMOUS) && ! defined(_WIN32) munmap (pool->memory, pool->size); #elif defined(_WIN32) @@ -256,7 +259,7 @@ MHD_pool_get_free (struct MemoryPool *pool) */ void * MHD_pool_allocate (struct MemoryPool *pool, - size_t size, + size_t size, bool from_end) { void *ret; @@ -271,15 +274,15 @@ MHD_pool_allocate (struct MemoryPool *pool, (pool->pos + asize < pool->pos)) return NULL; if (from_end) - { - ret = &pool->memory[pool->end - asize]; - pool->end -= asize; - } + { + ret = &pool->memory[pool->end - asize]; + pool->end -= asize; + } else - { - ret = &pool->memory[pool->pos]; - pool->pos += asize; - } + { + ret = &pool->memory[pool->pos]; + pool->pos += asize; + } return ret; } @@ -304,8 +307,8 @@ MHD_pool_allocate (struct MemoryPool *pool, void * MHD_pool_reallocate (struct MemoryPool *pool, void *old, - size_t old_size, - size_t new_size) + size_t old_size, + size_t new_size) { size_t asize; uint8_t *new_blc; @@ -313,36 +316,37 @@ MHD_pool_reallocate (struct MemoryPool *pool, mhd_assert (pool->end >= pool->pos); mhd_assert (pool->size >= pool->end - pool->pos); mhd_assert (old != NULL || old_size == 0); - mhd_assert (old == NULL || pool->memory <= (uint8_t*)old); - mhd_assert (old == NULL || pool->memory + pool->size >= (uint8_t*)old + old_size); + mhd_assert (old == NULL || pool->memory <= (uint8_t*) old); + mhd_assert (old == NULL || pool->memory + pool->size >= (uint8_t*) old + + old_size); /* Blocks "from the end" must not be reallocated */ - mhd_assert (old == NULL || pool->memory + pool->pos > (uint8_t*)old); + mhd_assert (old == NULL || pool->memory + pool->pos > (uint8_t*) old); if (0 != old_size) - { /* Need to save some data */ - const size_t old_offset = (uint8_t*)old - pool->memory; - const bool shrinking = (old_size > new_size); - /* Try resizing in-place */ - if (shrinking) - { /* Shrinking in-place, zero-out freed part */ - memset ((uint8_t*)old + new_size, 0, old_size - new_size); - } - if (pool->pos == ROUND_TO_ALIGN (old_offset + old_size)) - { /* "old" block is the last allocated block */ - const size_t new_apos = ROUND_TO_ALIGN (old_offset + new_size); - if (!shrinking) - { /* Grow in-place, check for enough space. */ - if ( (new_apos > pool->end) || - (new_apos < pool->pos) ) /* Value wrap */ - return NULL; /* No space */ - } - /* Resized in-place */ - pool->pos = new_apos; - return old; - } - if (shrinking) - return old; /* Resized in-place, freed part remains allocated */ + { /* Need to save some data */ + const size_t old_offset = (uint8_t*) old - pool->memory; + const bool shrinking = (old_size > new_size); + /* Try resizing in-place */ + if (shrinking) + { /* Shrinking in-place, zero-out freed part */ + memset ((uint8_t*) old + new_size, 0, old_size - new_size); + } + if (pool->pos == ROUND_TO_ALIGN (old_offset + old_size)) + { /* "old" block is the last allocated block */ + const size_t new_apos = ROUND_TO_ALIGN (old_offset + new_size); + if (! shrinking) + { /* Grow in-place, check for enough space. */ + if ( (new_apos > pool->end) || + (new_apos < pool->pos) ) /* Value wrap */ + return NULL; /* No space */ + } + /* Resized in-place */ + pool->pos = new_apos; + return old; } + if (shrinking) + return old; /* Resized in-place, freed part remains allocated */ + } /* Need to allocate new block */ asize = ROUND_TO_ALIGN (new_size); if ( ( (0 == asize) && @@ -354,12 +358,12 @@ MHD_pool_reallocate (struct MemoryPool *pool, pool->pos += asize; if (0 != old_size) - { - /* Move data to new block, old block remains allocated */ - memcpy (new_blc, old, old_size); - /* Zero-out old block */ - memset (old, 0, old_size); - } + { + /* Move data to new block, old block remains allocated */ + memcpy (new_blc, old, old_size); + /* Zero-out old block */ + memset (old, 0, old_size); + } return new_blc; } @@ -379,59 +383,60 @@ MHD_pool_reallocate (struct MemoryPool *pool, */ void * MHD_pool_reset (struct MemoryPool *pool, - void *keep, - size_t copy_bytes, + void *keep, + size_t copy_bytes, size_t new_size) { mhd_assert (pool->end >= pool->pos); mhd_assert (pool->size >= pool->end - pool->pos); mhd_assert (copy_bytes < new_size); mhd_assert (keep != NULL || copy_bytes == 0); - mhd_assert (keep == NULL || pool->memory <= (uint8_t*)keep); - mhd_assert (keep == NULL || pool->memory + pool->size >= (uint8_t*)keep + copy_bytes); + mhd_assert (keep == NULL || pool->memory <= (uint8_t*) keep); + mhd_assert (keep == NULL || pool->memory + pool->size >= (uint8_t*) keep + + copy_bytes); if ( (NULL != keep) && (keep != pool->memory) ) - { - if (0 != copy_bytes) - memmove (pool->memory, - keep, - copy_bytes); - } + { + if (0 != copy_bytes) + memmove (pool->memory, + keep, + copy_bytes); + } /* technically not needed, but safer to zero out */ if (pool->size > copy_bytes) - { - size_t to_zero; /** Size of area to zero-out */ + { + size_t to_zero; /** Size of area to zero-out */ - to_zero = pool->size - copy_bytes; + to_zero = pool->size - copy_bytes; #ifdef _WIN32 - if (pool->is_mmap) - { - size_t to_recommit; /** Size of decommitted and re-committed area. */ - uint8_t *recommit_addr; - /* Round down to page size */ - to_recommit = to_zero - to_zero % MHD_sys_page_size_; - recommit_addr = pool->memory + pool->size - to_recommit; - - /* De-committing and re-committing again clear memory and make - * pages free / available for other needs until accessed. */ - if (VirtualFree (recommit_addr, - to_recommit, - MEM_DECOMMIT)) - { - to_zero -= to_recommit; - - if (recommit_addr != VirtualAlloc (recommit_addr, - to_recommit, - MEM_COMMIT, - PAGE_READWRITE)) - abort(); /* Serious error, must never happen */ - } - } -#endif /* _WIN32 */ - memset (&pool->memory[copy_bytes], - 0, - to_zero); + if (pool->is_mmap) + { + size_t to_recommit; /** Size of decommitted and re-committed area. */ + uint8_t *recommit_addr; + /* Round down to page size */ + to_recommit = to_zero - to_zero % MHD_sys_page_size_; + recommit_addr = pool->memory + pool->size - to_recommit; + + /* De-committing and re-committing again clear memory and make + * pages free / available for other needs until accessed. */ + if (VirtualFree (recommit_addr, + to_recommit, + MEM_DECOMMIT)) + { + to_zero -= to_recommit; + + if (recommit_addr != VirtualAlloc (recommit_addr, + to_recommit, + MEM_COMMIT, + PAGE_READWRITE)) + abort (); /* Serious error, must never happen */ + } } +#endif /* _WIN32 */ + memset (&pool->memory[copy_bytes], + 0, + to_zero); + } pool->pos = ROUND_TO_ALIGN (new_size); pool->end = pool->size; return pool->memory; diff --git a/src/microhttpd/mhd_threads.c b/src/microhttpd/mhd_threads.c index 6578e4b1..6be4cb44 100644 --- a/src/microhttpd/mhd_threads.c +++ b/src/microhttpd/mhd_threads.c @@ -46,12 +46,14 @@ #else /* MHD_USE_THREAD_NAME_ */ #if defined(MHD_USE_POSIX_THREADS) -#if defined(HAVE_PTHREAD_ATTR_SETNAME_NP_NETBSD) || defined(HAVE_PTHREAD_ATTR_SETNAME_NP_IBMI) +#if defined(HAVE_PTHREAD_ATTR_SETNAME_NP_NETBSD) || \ + defined(HAVE_PTHREAD_ATTR_SETNAME_NP_IBMI) # define MHD_USE_THREAD_ATTR_SETNAME 1 #endif /* HAVE_PTHREAD_ATTR_SETNAME_NP_NETBSD || HAVE_PTHREAD_ATTR_SETNAME_NP_IBMI */ -#if defined(HAVE_PTHREAD_SETNAME_NP_GNU) || defined(HAVE_PTHREAD_SET_NAME_NP_FREEBSD) \ - || defined(HAVE_PTHREAD_SETNAME_NP_NETBSD) +#if defined(HAVE_PTHREAD_SETNAME_NP_GNU) || \ + defined(HAVE_PTHREAD_SET_NAME_NP_FREEBSD) \ + || defined(HAVE_PTHREAD_SETNAME_NP_NETBSD) /** * Set thread name @@ -61,25 +63,25 @@ * @return non-zero on success, zero otherwise */ static int -MHD_set_thread_name_(const MHD_thread_ID_ thread_id, - const char *thread_name) +MHD_set_thread_name_ (const MHD_thread_ID_ thread_id, + const char *thread_name) { if (NULL == thread_name) return 0; #if defined(HAVE_PTHREAD_SETNAME_NP_GNU) - return !pthread_setname_np (thread_id, thread_name); + return ! pthread_setname_np (thread_id, thread_name); #elif defined(HAVE_PTHREAD_SET_NAME_NP_FREEBSD) /* FreeBSD and OpenBSD use different name and void return type */ pthread_set_name_np (thread_id, thread_name); - return !0; + return ! 0; #elif defined(HAVE_PTHREAD_SETNAME_NP_NETBSD) /* NetBSD use 3 arguments: second argument is string in printf-like format, * third argument is single argument for printf; * OSF1 use 3 arguments too, but last one always must be zero (NULL). * MHD doesn't use '%' in thread names, so both form are used in same way. */ - return !pthread_setname_np (thread_id, thread_name, 0); + return ! pthread_setname_np (thread_id, thread_name, 0); #endif /* HAVE_PTHREAD_SETNAME_NP_NETBSD */ } @@ -90,10 +92,10 @@ MHD_set_thread_name_(const MHD_thread_ID_ thread_id, * @param n name to set * @return non-zero on success, zero otherwise */ -#define MHD_set_cur_thread_name_(n) MHD_set_thread_name_(pthread_self(),(n)) +#define MHD_set_cur_thread_name_(n) MHD_set_thread_name_ (pthread_self (),(n)) #else /* __QNXNTO__ */ /* Special case for QNX Neutrino - using zero for thread ID sets name faster. */ -#define MHD_set_cur_thread_name_(n) MHD_set_thread_name_(0,(n)) +#define MHD_set_cur_thread_name_(n) MHD_set_thread_name_ (0,(n)) #endif /* __QNXNTO__ */ #elif defined(HAVE_PTHREAD_SETNAME_NP_DARWIN) @@ -102,7 +104,7 @@ MHD_set_thread_name_(const MHD_thread_ID_ thread_id, * @param n name to set * @return non-zero on success, zero otherwise */ -#define MHD_set_cur_thread_name_(n) (!(pthread_setname_np((n)))) +#define MHD_set_cur_thread_name_(n) (! (pthread_setname_np ((n)))) #endif /* HAVE_PTHREAD_SETNAME_NP_DARWIN */ #elif defined(MHD_USE_W32_THREADS) @@ -117,8 +119,8 @@ MHD_set_thread_name_(const MHD_thread_ID_ thread_id, * @return non-zero on success, zero otherwise */ static int -MHD_set_thread_name_(const MHD_thread_ID_ thread_id, - const char *thread_name) +MHD_set_thread_name_ (const MHD_thread_ID_ thread_id, + const char *thread_name) { static const DWORD VC_SETNAME_EXC = 0x406D1388; #pragma pack(push,8) @@ -149,7 +151,7 @@ MHD_set_thread_name_(const MHD_thread_ID_ thread_id, __except (EXCEPTION_EXECUTE_HANDLER) {} - return !0; + return ! 0; } @@ -158,7 +160,7 @@ MHD_set_thread_name_(const MHD_thread_ID_ thread_id, * @param n name to set * @return non-zero on success, zero otherwise */ -#define MHD_set_cur_thread_name_(n) MHD_set_thread_name_(-1,(n)) +#define MHD_set_cur_thread_name_(n) MHD_set_thread_name_ (-1,(n)) #endif /* _MSC_FULL_VER */ #endif /* MHD_USE_W32_THREADS */ @@ -184,21 +186,21 @@ MHD_create_thread_ (MHD_thread_handle_ID_ *thread, int res; if (0 != stack_size) + { + pthread_attr_t attr; + res = pthread_attr_init (&attr); + if (0 == res) { - pthread_attr_t attr; - res = pthread_attr_init (&attr); + res = pthread_attr_setstacksize (&attr, + stack_size); if (0 == res) - { - res = pthread_attr_setstacksize (&attr, - stack_size); - if (0 == res) - res = pthread_create (&(thread->handle), - &attr, - start_routine, - arg); - pthread_attr_destroy (&attr); - } + res = pthread_create (&(thread->handle), + &attr, + start_routine, + arg); + pthread_attr_destroy (&attr); } + } else res = pthread_create (&(thread->handle), NULL, @@ -208,28 +210,28 @@ MHD_create_thread_ (MHD_thread_handle_ID_ *thread, if (0 != res) errno = res; - return !res; + return ! res; #elif defined(MHD_USE_W32_THREADS) #if SIZE_MAX != UINT_MAX if (stack_size > UINT_MAX) - { - errno = EINVAL; - return 0; - } + { + errno = EINVAL; + return 0; + } #endif /* SIZE_MAX != UINT_MAX */ thread->handle = (MHD_thread_handle_) - _beginthreadex (NULL, - (unsigned int) stack_size, - start_routine, - arg, - 0, - NULL); - - if ((MHD_thread_handle_)-1 == thread->handle) + _beginthreadex (NULL, + (unsigned int) stack_size, + start_routine, + arg, + 0, + NULL); + + if ((MHD_thread_handle_) - 1 == thread->handle) return 0; - return !0; + return ! 0; #endif } @@ -258,21 +260,21 @@ struct MHD_named_helper_param_ static MHD_THRD_RTRN_TYPE_ MHD_THRD_CALL_SPEC_ named_thread_starter (void *data) { - struct MHD_named_helper_param_ * const param = - (struct MHD_named_helper_param_ *) data; - void * arg; + struct MHD_named_helper_param_ *const param = + (struct MHD_named_helper_param_ *) data; + void *arg; MHD_THREAD_START_ROUTINE_ thr_func; if (NULL == data) - return (MHD_THRD_RTRN_TYPE_)0; + return (MHD_THRD_RTRN_TYPE_) 0; MHD_set_cur_thread_name_ (param->name); arg = param->arg; thr_func = param->start_routine; - free(data); + free (data); - return thr_func(arg); + return thr_func (arg); } #endif /* ! MHD_USE_THREAD_ATTR_SETNAME */ @@ -289,7 +291,7 @@ named_thread_starter (void *data) */ int MHD_create_named_thread_ (MHD_thread_handle_ID_ *thread, - const char* thread_name, + const char*thread_name, size_t stack_size, MHD_THREAD_START_ROUTINE_ start_routine, void *arg) @@ -300,41 +302,44 @@ MHD_create_named_thread_ (MHD_thread_handle_ID_ *thread, res = pthread_attr_init (&attr); if (0 == res) - { + { #if defined(HAVE_PTHREAD_ATTR_SETNAME_NP_NETBSD) - /* NetBSD use 3 arguments: second argument is string in printf-like format, - * third argument is single argument for printf; - * OSF1 use 3 arguments too, but last one always must be zero (NULL). - * MHD doesn't use '%' in thread names, so both form are used in same way. - */ - res = pthread_attr_setname_np (&attr, thread_name, 0); + /* NetBSD use 3 arguments: second argument is string in printf-like format, + * third argument is single argument for printf; + * OSF1 use 3 arguments too, but last one always must be zero (NULL). + * MHD doesn't use '%' in thread names, so both form are used in same way. + */ + res = pthread_attr_setname_np (&attr, + thread_name, + 0); #elif defined(HAVE_PTHREAD_ATTR_SETNAME_NP_IBMI) - res = pthread_attr_setname_np (&attr, thread_name); + res = pthread_attr_setname_np (&attr, + thread_name); #else #error No pthread_attr_setname_np() function. #endif - if (res == 0 && 0 != stack_size) - res = pthread_attr_setstacksize (&attr, - stack_size); - if (0 == res) - res = pthread_create (&(thread->handle), - &attr, - start_routine, - arg); - pthread_attr_destroy (&attr); - } + if ((res == 0) &&(0 != stack_size) ) + res = pthread_attr_setstacksize (&attr, + stack_size); + if (0 == res) + res = pthread_create (&(thread->handle), + &attr, + start_routine, + arg); + pthread_attr_destroy (&attr); + } if (0 != res) errno = res; - return !res; + return ! res; #else /* ! MHD_USE_THREAD_ATTR_SETNAME */ struct MHD_named_helper_param_ *param; if (NULL == thread_name) - { - errno = EINVAL; - return 0; - } + { + errno = EINVAL; + return 0; + } param = malloc (sizeof (struct MHD_named_helper_param_)); if (NULL == param) @@ -347,16 +352,16 @@ MHD_create_named_thread_ (MHD_thread_handle_ID_ *thread, /* Set thread name in thread itself to avoid problems with * threads which terminated before name is set in other thread. */ - if (! MHD_create_thread_(thread, - stack_size, - &named_thread_starter, - (void*)param)) - { - free (param); - return 0; - } + if (! MHD_create_thread_ (thread, + stack_size, + &named_thread_starter, + (void*) param)) + { + free (param); + return 0; + } - return !0; + return ! 0; #endif /* ! MHD_USE_THREAD_ATTR_SETNAME */ } -- cgit v1.2.3