<commit_before>/* -*- Mode: C; tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*- */
/*
 *     Copyright 2014 Couchbase, Inc.
 *
 *   Licensed under the Apache License, Version 2.0 (the "License");
 *   you may not use this file except in compliance with the License.
 *   You may obtain a copy of the License at
 *
 *       http://www.apache.org/licenses/LICENSE-2.0
 *
 *   Unless required by applicable law or agreed to in writing, software
 *   distributed under the License is distributed on an "AS IS" BASIS,
 *   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *   See the License for the specific language governing permissions and
 *   limitations under the License.
 */

#include "settings.h"
#include "logging.h"
#include "internal.h" /* for lcb_getenv* */
#include <stdio.h>
#include <stdarg.h>

#ifdef _WIN32
#define flockfile(x) (void) 0
#define funlockfile(x) (void) 0
#endif


#if defined(unix) || defined(__unix__) || defined(__unix) || defined(_POSIX_VERSION)
    #include <unistd.h>
    #include <pthread.h>
    #include <sys/types.h>

    /** XXX: If any of these blocks give problems for your platform, just
     * erase it and have it use the fallback implementation. This isn't core
     * functionality of the library, but is a rather helpful feature in order
     * to get the thread/process identifier
     */

    #if defined(__linux__)
        #include <sys/syscall.h>
        #define GET_THREAD_ID() (long)syscall(SYS_gettid)
        #define THREAD_ID_FMT "ld"
    #elif defined(__APPLE__)
        #define GET_THREAD_ID() pthread_mach_thread_np(pthread_self())
        #define THREAD_ID_FMT "u"
    #elif defined(__sun) && defined(__SVR4)
        #include <thread.h>
        /* Thread IDs are not global in solaris, so it's nice to print the PID alongside it */
        #define GET_THREAD_ID() getpid(), thr_self()
        #define THREAD_ID_FMT "ld/%u"
    #elif defined(__FreeBSD__)
        /* Like solaris, but thr_self is a bit different here */
        #include <sys/thr.h>
        static long ret_thr_self(void) { long tmp; thr_self(&tmp); return tmp; }
        #define GET_THREAD_ID() getpid(), ret_thr_self()
        #define THREAD_ID_FMT "d/%ld"
    #else
        /* other unix? */
        #define GET_THREAD_ID() 0
        #define THREAD_ID_FMT "d"
    #endif
#elif defined(_WIN32)
    #define GET_THREAD_ID() GetCurrentThreadId()
    #define THREAD_ID_FMT "d"
#else<commit_msg>logging.c: Print mach port ID as hex<commit_after>/* -*- Mode: C; tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*- */
/*
 *     Copyright 2014 Couchbase, Inc.
 *
 *   Licensed under the Apache License, Version 2.0 (the "License");
 *   you may not use this file except in compliance with the License.
 *   You may obtain a copy of the License at
 *
 *       http://www.apache.org/licenses/LICENSE-2.0
 *
 *   Unless required by applicable law or agreed to in writing, software
 *   distributed under the License is distributed on an "AS IS" BASIS,
 *   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *   See the License for the specific language governing permissions and
 *   limitations under the License.
 */

#include "settings.h"
#include "logging.h"
#include "internal.h" /* for lcb_getenv* */
#include <stdio.h>
#include <stdarg.h>

#ifdef _WIN32
#define flockfile(x) (void) 0
#define funlockfile(x) (void) 0
#endif


#if defined(unix) || defined(__unix__) || defined(__unix) || defined(_POSIX_VERSION)
    #include <unistd.h>
    #include <pthread.h>
    #include <sys/types.h>

    /** XXX: If any of these blocks give problems for your platform, just
     * erase it and have it use the fallback implementation. This isn't core
     * functionality of the library, but is a rather helpful feature in order
     * to get the thread/process identifier
     */

    #if defined(__linux__)
        #include <sys/syscall.h>
        #define GET_THREAD_ID() (long)syscall(SYS_gettid)
        #define THREAD_ID_FMT "ld"
    #elif defined(__APPLE__)
        #define GET_THREAD_ID() pthread_mach_thread_np(pthread_self())
        #define THREAD_ID_FMT "x"
    #elif defined(__sun) && defined(__SVR4)
        #include <thread.h>
        /* Thread IDs are not global in solaris, so it's nice to print the PID alongside it */
        #define GET_THREAD_ID() getpid(), thr_self()
        #define THREAD_ID_FMT "ld/%u"
    #elif defined(__FreeBSD__)
        /* Like solaris, but thr_self is a bit different here */
        #include <sys/thr.h>
        static long ret_thr_self(void) { long tmp; thr_self(&tmp); return tmp; }
        #define GET_THREAD_ID() getpid(), ret_thr_self()
        #define THREAD_ID_FMT "d/%ld"
    #else
        /* other unix? */
        #define GET_THREAD_ID() 0
        #define THREAD_ID_FMT "d"
    #endif
#elif defined(_WIN32)
    #define GET_THREAD_ID() GetCurrentThreadId()
    #define THREAD_ID_FMT "d"
#else
{'fraction_non_alphanumeric': 0.10968921389396709, 'fraction_numerical': 0.007312614259597806, 'mean_word_length': 3.0829187396351574, 'pattern_counts': {'":': 0, '<': 19, '<?xml version=': 0, '>': 19, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4959209', 'n_tokens_mistral': 1584, 'n_tokens_neox': 1547, 'n_words': 523}