<commit_before>/**
 * Copyright (C) 2005-2008 <NAME> (<EMAIL>).
 *
 * This program is free software; you can redistribute it and/or modify it
 * under the terms of the GNU General Public License as published by the
 * Free Software Foundation; either version 2 of the License, or 
 * (at your option) any later version.
 *
 * See files COPYING.* for License information.
 *
 */

#include "config.h"

#include <ham/hamsterdb.h>
#include <ham/types.h>

#define _GNU_SOURCE   1 /* for O_LARGEFILE */
#define __USE_XOPEN2K 1 /* for ftruncate() */
#include <stdio.h>
#include <errno.h>
#include <string.h>
#if HAVE_MMAP
#  include <sys/mman.h>
#endif
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/file.h>
#include <fcntl.h>
#include <unistd.h>
#include "error.h"
#include "os.h"

static ham_status_t
__lock_exclusive(int fd, ham_bool_t lock)
{
#if HAM_SOLARIS
    /*
     * SunOS 5.9 doesn't have LOCK_* unless i include /usr/ucbinclude; but then,
     * mmap behaves strangely (the first write-access to the mmapped buffer
     * leads to a segmentation fault.
     *
     * Tell me if this troubles you/if you have suggestions for fixes.
     */
    return (HAM_NOT_IMPLEMENTED);
#else
    int flags;

    if (lock)
        flags=LOCK_EX|LOCK_NB;
    else
        flags=LOCK_UN;

    if (0!=flock(fd, flags)) {
        ham_log(("flock failed with status %u (%s)", errno, strerror(errno)));
        /* it seems that linux does not only return EWOULDBLOCK, as stated
         * in the documentation (flock(2)), but also other errors... */
        if (errno)
            return (HAM_WOULD_BLOCK);
        return (HAM_IO_ERROR);
    }

    return (0);
#endif
}

static void
my_enable_largefile(int fd)
{
    /*
     * not available on cygwin...
     */
#ifdef HAVE_O_LARGEFILE
    int oflag=fcntl(fd, F_GETFL, 0);
    fcntl(fd, F_SETFL, oflag|O_LARGEFILE);
#endif
}
<commit_msg>fixed another test which broke when exclusive locking became the default behaviour<commit_after>/**
 * Copyright (C) 2005-2008 <NAME> (<EMAIL>).
 *
 * This program is free software; you can redistribute it and/or modify it
 * under the terms of the GNU General Public License as published by the
 * Free Software Foundation; either version 2 of the License, or 
 * (at your option) any later version.
 *
 * See files COPYING.* for License information.
 *
 */

#include "config.h"

#include <ham/hamsterdb.h>
#include <ham/types.h>

#define _GNU_SOURCE   1 /* for O_LARGEFILE */
#define __USE_XOPEN2K 1 /* for ftruncate() */
#include <stdio.h>
#include <errno.h>
#include <string.h>
#if HAVE_MMAP
#  include <sys/mman.h>
#endif
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/file.h>
#include <fcntl.h>
#include <unistd.h>
#include "error.h"
#include "os.h"

static ham_status_t
__lock_exclusive(int fd, ham_bool_t lock)
{
#if HAM_SOLARIS
    /*
     * SunOS 5.9 doesn't have LOCK_* unless i include /usr/ucbinclude; but then,
     * mmap behaves strangely (the first write-access to the mmapped buffer
     * leads to a segmentation fault.
     *
     * Tell me if this troubles you/if you have suggestions for fixes.
     */
    return (HAM_NOT_IMPLEMENTED);
#else
    int flags;

    if (lock)
        flags=LOCK_EX|LOCK_NB;
    else
        flags=LOCK_UN;

    if (0!=flock(fd, flags)) {
        ham_log(("flock failed with status %u (%s)", errno, strerror(errno)));
        /* it seems that linux does not only return EWOULDBLOCK, as stated
         * in the documentation (flock(2)), but also other errors... */
        if (errno)
            if (lock)
                return (HAM_WOULD_BLOCK);
        return (HAM_IO_ERROR);
    }

    return (0);
#endif
}

static void
my_enable_largefile(int fd)
{
    /*
     * not available on cygwin...
     */
#ifdef HAVE_O_LARGEFILE
    int oflag=fcntl(fd, F_GETFL, 0);
    fcntl(fd, F_SETFL, oflag|O_LARGEFILE);
#endif
}

{'fraction_non_alphanumeric': 0.11856070411597204, 'fraction_numerical': 0.009319181982914834, 'mean_word_length': 3.0166320166320166, 'pattern_counts': {'":': 0, '<': 29, '<?xml version=': 0, '>': 29, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, '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': '6909387', 'n_tokens_mistral': 1396, 'n_tokens_neox': 1333, 'n_words': 425}