diff --git a/pool/shard000/C/0008448_Timeout.c b/pool/shard000/C/0008448_Timeout.c
new file mode 100644
index 0000000000000000000000000000000000000000..d4e5a37cccb4e0b2c33b7ff01855e0e53c5ecfd3
--- /dev/null
+++ b/pool/shard000/C/0008448_Timeout.c
@@ -0,0 +1,138 @@
+/* vim: set expandtab ts=4 sw=4: */
+/*
+ * You may redistribute this program and/or modify it under the terms of
+ * the GNU General Public License as published by the Free Software Foundation,
+ * either version 3 of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see .
+ */
+#include "util/events/libuv/UvWrapper.h"
+#include "memory/Allocator.h"
+#include "util/events/libuv/EventBase_pvt.h"
+#include "util/events/Timeout.h"
+#include "util/Identity.h"
+
+struct Timeout
+{
+ uv_timer_t timer;
+
+ void (* callback)(void* callbackContext);
+
+ void* callbackContext;
+
+ uint64_t milliseconds;
+
+ int isInterval;
+
+ struct Allocator* alloc;
+
+ Identity
+};
+
+/**
+ * The callback to be called by libuv.
+ */
+static void handleEvent(uv_timer_t* handle, int status)
+{
+ struct Timeout* timeout = Identity_check((struct Timeout*) handle);
+ if (!timeout->isInterval) {
+ Timeout_clearTimeout(timeout);
+ }
+ timeout->callback(timeout->callbackContext);
+}
+
+static void onFree2(uv_handle_t* timer)
+{
+ Allocator_onFreeComplete(timer->data);
+}
+
+static int onFree(struct Allocator_OnFreeJob* job)
+{
+ struct Timeout* t = Identity_check((struct Timeout*) job->userData);
+ t->timer.data = job;
+ uv_close((uv_handle_t*) &t->timer, onFree2);
+ return Allocator_ONFREE_ASYNC;
+}
+
+/**
+ * Create a timeout event.
+ * The timeout event will be triggered after the given number of milliseconds.
+ *
+ * @param callback the functiont to call.
+ * @param callbackContext a pointer to pass to the called function.
+ * @param milliseconds the number of milliseconds to wait before the event happens.
+ * @param interval if non-zero, this event will repeat instead of triggering once.
+ * @param eventBase the libevent event base.
+ * @param allocator the memory allocator to use for allocating the event.
+ * if this is freed, the event will be safely deleted.
+ * @return a timeout struct which can be used to clear the timeout.
+ */
+static struct Timeout* setTimeout(void (* const callback)(void* callbackContext),
+ void* const callbackContext,
+ const uint64_t milliseconds,
+ const uint32_t interval,
+ struct EventBase* eventBase,
+ struct Allocator* allocator)
+{
+ struct EventBase_pvt* base = EventBase_privatize(eventBase);
+ struct Allocator* alloc = Allocator_child(allocator);
+ struct Timeout* timeout = Allocator_calloc(alloc, sizeof(struct Timeout), 1);
+
+ timeout->callback = callback;
+ timeout->callbackContext = callbackContext;
+ timeout->milliseconds = milliseconds;
+ timeout->alloc = alloc;
+ timeout->isInterval = interval;
+ Identity_set(timeout);
+
+ uv_timer_init(base->loop, &timeout->timer);
+ uv_timer_start(&timeout->timer, handleEvent, milliseconds, (interval) ? milliseconds : 0);
+
+ timeout->timer.data = timeout;
+
+ Allocator_onFree(alloc, onFree, timeout);
+
+ return timeout;
+}
+
+/** See: Timeout.h */
+struct Timeout* Timeout_setTimeout(void (* const callback)(void* callbackContext),
+ void* const callbackContext,
+ const uint64_t milliseconds,
+ struct EventBase* eventBase,
+ struct Allocator* allocator)
+{
+ return setTimeout(callback, callbackContext, milliseconds, 0, eventBase, allocator);
+}
+
+/** See: Timeout.h */
+struct Timeout* Timeout_setInterval(void (* const callback)(void* callbackContext),
+ void* const callbackContext,
+ const uint64_t milliseconds,
+ struct EventBase* eventBase,
+ struct Allocator* allocator)
+{
+ return setTimeout(callback, callbackContext, milliseconds, 1, eventBase, allocator);
+}
+
+/** See: Timeout.h */
+void Timeout_resetTimeout(struct Timeout* timeout,
+ const uint64_t milliseconds)
+{
+ Timeout_clearTimeout(timeout);
+ uv_timer_start(&timeout->timer, handleEvent, milliseconds, 0);
+}
+
+/** See: Timeout.h */
+void Timeout_clearTimeout(struct Timeout* timeout)
+{
+ if (!uv_is_closing((uv_handle_t*) &timeout->timer)) {
+ uv_timer_stop(&timeout->timer);
+ }
+}
diff --git a/pool/shard000/C/0008450_en_clock.c b/pool/shard000/C/0008450_en_clock.c
new file mode 100644
index 0000000000000000000000000000000000000000..015198c14fa8531589f4443cb770989d629f51e6
--- /dev/null
+++ b/pool/shard000/C/0008450_en_clock.c
@@ -0,0 +1,308 @@
+/*
+ * Copyright (c) 2012 Mellanox Technologies. All rights reserved.
+ *
+ * This software is available to you under a choice of one of two
+ * licenses. You may choose to be licensed under the terms of the GNU
+ * General Public License (GPL) Version 2, available from the file
+ * COPYING in the main directory of this source tree, or the
+ * OpenIB.org BSD license below:
+ *
+ * Redistribution and use in source and binary forms, with or
+ * without modification, are permitted provided that the following
+ * conditions are met:
+ *
+ * - Redistributions of source code must retain the above
+ * copyright notice, this list of conditions and the following
+ * disclaimer.
+ *
+ * - Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following
+ * disclaimer in the documentation and/or other materials
+ * provided with the distribution.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+ * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
+ * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
+ * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ *
+ */
+
+#include
+#include
+
+#include "mlx4_en.h"
+
+/* mlx4_en_read_clock - read raw cycle counter (to be used by time counter)
+ */
+static u64 mlx4_en_read_clock(const struct cyclecounter *tc)
+{
+ struct mlx4_en_dev *mdev =
+ container_of(tc, struct mlx4_en_dev, cycles);
+ struct mlx4_dev *dev = mdev->dev;
+
+ return mlx4_read_clock(dev) & tc->mask;
+}
+
+u64 mlx4_en_get_cqe_ts(struct mlx4_cqe *cqe)
+{
+ u64 hi, lo;
+ struct mlx4_ts_cqe *ts_cqe = (struct mlx4_ts_cqe *)cqe;
+
+ lo = (u64)be16_to_cpu(ts_cqe->timestamp_lo);
+ hi = ((u64)be32_to_cpu(ts_cqe->timestamp_hi) + !lo) << 16;
+
+ return hi | lo;
+}
+
+void mlx4_en_fill_hwtstamps(struct mlx4_en_dev *mdev,
+ struct skb_shared_hwtstamps *hwts,
+ u64 timestamp)
+{
+ unsigned long flags;
+ u64 nsec;
+
+ read_lock_irqsave(&mdev->clock_lock, flags);
+ nsec = timecounter_cyc2time(&mdev->clock, timestamp);
+ read_unlock_irqrestore(&mdev->clock_lock, flags);
+
+ memset(hwts, 0, sizeof(struct skb_shared_hwtstamps));
+ hwts->hwtstamp = ns_to_ktime(nsec);
+}
+
+/**
+ * mlx4_en_remove_timestamp - disable PTP device
+ * @mdev: board private structure
+ *
+ * Stop the PTP support.
+ **/
+void mlx4_en_remove_timestamp(struct mlx4_en_dev *mdev)
+{
+ if (mdev->ptp_clock) {
+ ptp_clock_unregister(mdev->ptp_clock);
+ mdev->ptp_clock = NULL;
+ mlx4_info(mdev, "removed PHC\n");
+ }
+}
+
+void mlx4_en_ptp_overflow_check(struct mlx4_en_dev *mdev)
+{
+ bool timeout = time_is_before_jiffies(mdev->last_overflow_check +
+ mdev->overflow_period);
+ unsigned long flags;
+
+ if (timeout) {
+ write_lock_irqsave(&mdev->clock_lock, flags);
+ timecounter_read(&mdev->clock);
+ write_unlock_irqrestore(&mdev->clock_lock, flags);
+ mdev->last_overflow_check = jiffies;
+ }
+}
+
+/**
+ * mlx4_en_phc_adjfreq - adjust the frequency of the hardware clock
+ * @ptp: ptp clock structure
+ * @delta: Desired frequency change in parts per billion
+ *
+ * Adjust the frequency of the PHC cycle counter by the indicated delta from
+ * the base frequency.
+ **/
+static int mlx4_en_phc_adjfreq(struct ptp_clock_info *ptp, s32 delta)
+{
+ u64 adj;
+ u32 diff, mult;
+ int neg_adj = 0;
+ unsigned long flags;
+ struct mlx4_en_dev *mdev = container_of(ptp, struct mlx4_en_dev,
+ ptp_clock_info);
+
+ if (delta < 0) {
+ neg_adj = 1;
+ delta = -delta;
+ }
+ mult = mdev->nominal_c_mult;
+ adj = mult;
+ adj *= delta;
+ diff = div_u64(adj, 1000000000ULL);
+
+ write_lock_irqsave(&mdev->clock_lock, flags);
+ timecounter_read(&mdev->clock);
+ mdev->cycles.mult = neg_adj ? mult - diff : mult + diff;
+ write_unlock_irqrestore(&mdev->clock_lock, flags);
+
+ return 0;
+}
+
+/**
+ * mlx4_en_phc_adjtime - Shift the time of the hardware clock
+ * @ptp: ptp clock structure
+ * @delta: Desired change in nanoseconds
+ *
+ * Adjust the timer by resetting the timecounter structure.
+ **/
+static int mlx4_en_phc_adjtime(struct ptp_clock_info *ptp, s64 delta)
+{
+ struct mlx4_en_dev *mdev = container_of(ptp, struct mlx4_en_dev,
+ ptp_clock_info);
+ unsigned long flags;
+
+ write_lock_irqsave(&mdev->clock_lock, flags);
+ timecounter_adjtime(&mdev->clock, delta);
+ write_unlock_irqrestore(&mdev->clock_lock, flags);
+
+ return 0;
+}
+
+/**
+ * mlx4_en_phc_gettime - Reads the current time from the hardware clock
+ * @ptp: ptp clock structure
+ * @ts: timespec structure to hold the current time value
+ *
+ * Read the timecounter and return the correct value in ns after converting
+ * it into a struct timespec.
+ **/
+static int mlx4_en_phc_gettime(struct ptp_clock_info *ptp,
+ struct timespec64 *ts)
+{
+ struct mlx4_en_dev *mdev = container_of(ptp, struct mlx4_en_dev,
+ ptp_clock_info);
+ unsigned long flags;
+ u64 ns;
+
+ write_lock_irqsave(&mdev->clock_lock, flags);
+ ns = timecounter_read(&mdev->clock);
+ write_unlock_irqrestore(&mdev->clock_lock, flags);
+
+ *ts = ns_to_timespec64(ns);
+
+ return 0;
+}
+
+/**
+ * mlx4_en_phc_settime - Set the current time on the hardware clock
+ * @ptp: ptp clock structure
+ * @ts: timespec containing the new time for the cycle counter
+ *
+ * Reset the timecounter to use a new base value instead of the kernel
+ * wall timer value.
+ **/
+static int mlx4_en_phc_settime(struct ptp_clock_info *ptp,
+ const struct timespec64 *ts)
+{
+ struct mlx4_en_dev *mdev = container_of(ptp, struct mlx4_en_dev,
+ ptp_clock_info);
+ u64 ns = timespec64_to_ns(ts);
+ unsigned long flags;
+
+ /* reset the timecounter */
+ write_lock_irqsave(&mdev->clock_lock, flags);
+ timecounter_init(&mdev->clock, &mdev->cycles, ns);
+ write_unlock_irqrestore(&mdev->clock_lock, flags);
+
+ return 0;
+}
+
+/**
+ * mlx4_en_phc_enable - enable or disable an ancillary feature
+ * @ptp: ptp clock structure
+ * @request: Desired resource to enable or disable
+ * @on: Caller passes one to enable or zero to disable
+ *
+ * Enable (or disable) ancillary features of the PHC subsystem.
+ * Currently, no ancillary features are supported.
+ **/
+static int mlx4_en_phc_enable(struct ptp_clock_info __always_unused *ptp,
+ struct ptp_clock_request __always_unused *request,
+ int __always_unused on)
+{
+ return -EOPNOTSUPP;
+}
+
+static const struct ptp_clock_info mlx4_en_ptp_clock_info = {
+ .owner = THIS_MODULE,
+ .max_adj = 100000000,
+ .n_alarm = 0,
+ .n_ext_ts = 0,
+ .n_per_out = 0,
+ .n_pins = 0,
+ .pps = 0,
+ .adjfreq = mlx4_en_phc_adjfreq,
+ .adjtime = mlx4_en_phc_adjtime,
+ .gettime64 = mlx4_en_phc_gettime,
+ .settime64 = mlx4_en_phc_settime,
+ .enable = mlx4_en_phc_enable,
+};
+
+#define MLX4_EN_WRAP_AROUND_SEC 10ULL
+
+/* This function calculates the max shift that enables the user range
+ * of MLX4_EN_WRAP_AROUND_SEC values in the cycles register.
+ */
+static u32 freq_to_shift(u16 freq)
+{
+ u32 freq_khz = freq * 1000;
+ u64 max_val_cycles = freq_khz * 1000 * MLX4_EN_WRAP_AROUND_SEC;
+ u64 tmp_rounded =
+ roundup_pow_of_two(max_val_cycles) > max_val_cycles ?
+ roundup_pow_of_two(max_val_cycles) - 1 : UINT_MAX;
+ u64 max_val_cycles_rounded = is_power_of_2(max_val_cycles + 1) ?
+ max_val_cycles : tmp_rounded;
+ /* calculate max possible multiplier in order to fit in 64bit */
+ u64 max_mul = div_u64(0xffffffffffffffffULL, max_val_cycles_rounded);
+
+ /* This comes from the reverse of clocksource_khz2mult */
+ return ilog2(div_u64(max_mul * freq_khz, 1000000));
+}
+
+void mlx4_en_init_timestamp(struct mlx4_en_dev *mdev)
+{
+ struct mlx4_dev *dev = mdev->dev;
+ unsigned long flags;
+ u64 ns, zero = 0;
+
+ /* mlx4_en_init_timestamp is called for each netdev.
+ * mdev->ptp_clock is common for all ports, skip initialization if
+ * was done for other port.
+ */
+ if (mdev->ptp_clock)
+ return;
+
+ rwlock_init(&mdev->clock_lock);
+
+ memset(&mdev->cycles, 0, sizeof(mdev->cycles));
+ mdev->cycles.read = mlx4_en_read_clock;
+ mdev->cycles.mask = CLOCKSOURCE_MASK(48);
+ mdev->cycles.shift = freq_to_shift(dev->caps.hca_core_clock);
+ mdev->cycles.mult =
+ clocksource_khz2mult(1000 * dev->caps.hca_core_clock, mdev->cycles.shift);
+ mdev->nominal_c_mult = mdev->cycles.mult;
+
+ write_lock_irqsave(&mdev->clock_lock, flags);
+ timecounter_init(&mdev->clock, &mdev->cycles,
+ ktime_to_ns(ktime_get_real()));
+ write_unlock_irqrestore(&mdev->clock_lock, flags);
+
+ /* Calculate period in seconds to call the overflow watchdog - to make
+ * sure counter is checked at least once every wrap around.
+ */
+ ns = cyclecounter_cyc2ns(&mdev->cycles, mdev->cycles.mask, zero, &zero);
+ do_div(ns, NSEC_PER_SEC / 2 / HZ);
+ mdev->overflow_period = ns;
+
+ /* Configure the PHC */
+ mdev->ptp_clock_info = mlx4_en_ptp_clock_info;
+ snprintf(mdev->ptp_clock_info.name, 16, "mlx4 ptp");
+
+ mdev->ptp_clock = ptp_clock_register(&mdev->ptp_clock_info,
+ &mdev->pdev->dev);
+ if (IS_ERR(mdev->ptp_clock)) {
+ mdev->ptp_clock = NULL;
+ mlx4_err(mdev, "ptp_clock_register failed\n");
+ } else if (mdev->ptp_clock) {
+ mlx4_info(mdev, "registered PHC clock\n");
+ }
+
+}
diff --git a/pool/shard000/C/0008452_rpc_sign.c b/pool/shard000/C/0008452_rpc_sign.c
new file mode 100644
index 0000000000000000000000000000000000000000..0bfdcee5ae5a55caf1687c3035d22a2e46853690
--- /dev/null
+++ b/pool/shard000/C/0008452_rpc_sign.c
@@ -0,0 +1,109 @@
+
+/*
+ * Licensed Materials - Property of IBM
+ *
+ * trousers - An open source TCG Software Stack
+ *
+ * (C) Copyright International Business Machines Corp. 2004-2006
+ *
+ */
+
+#include
+#include
+#include
+#include
+#include
+
+#include "trousers/tss.h"
+#include "trousers_types.h"
+#include "tcs_tsp.h"
+#include "tcs_utils.h"
+#include "tcs_int_literals.h"
+#include "capabilities.h"
+#include "tcslog.h"
+#include "tcsd_wrap.h"
+#include "tcsd.h"
+#include "tcs_utils.h"
+#include "rpc_tcstp_tcs.h"
+
+
+TSS_RESULT
+tcs_wrap_Sign(struct tcsd_thread_data *data)
+{
+ TCS_CONTEXT_HANDLE hContext;
+ TCS_KEY_HANDLE hKey;
+ UINT32 areaToSignSize;
+ BYTE *areaToSign;
+
+ TPM_AUTH auth;
+ TPM_AUTH *pAuth;
+
+ UINT32 sigSize;
+ BYTE *sig;
+ TSS_RESULT result;
+
+ int i;
+
+ if (getData(TCSD_PACKET_TYPE_UINT32, 0, &hContext, 0, &data->comm))
+ return TCSERR(TSS_E_INTERNAL_ERROR);
+
+ if ((result = ctx_verify_context(hContext)))
+ goto done;
+
+ LogDebugFn("thread %ld context %x", THREAD_ID, hContext);
+
+ if (getData(TCSD_PACKET_TYPE_UINT32, 1, &hKey, 0, &data->comm))
+ return TCSERR(TSS_E_INTERNAL_ERROR);
+ if (getData(TCSD_PACKET_TYPE_UINT32, 2, &areaToSignSize, 0, &data->comm))
+ return TCSERR(TSS_E_INTERNAL_ERROR);
+
+ areaToSign = calloc(1, areaToSignSize);
+ if (areaToSign == NULL) {
+ LogError("malloc of %d bytes failed.", areaToSignSize);
+ return TCSERR(TSS_E_OUTOFMEMORY);
+ }
+ if (getData(TCSD_PACKET_TYPE_PBYTE, 3, areaToSign, areaToSignSize, &data->comm)) {
+ free(areaToSign);
+ return TCSERR(TSS_E_INTERNAL_ERROR);
+ }
+ result = getData(TCSD_PACKET_TYPE_AUTH, 4, &auth, 0, &data->comm);
+ if (result == TSS_TCP_RPC_BAD_PACKET_TYPE)
+ pAuth = NULL;
+ else if (result) {
+ free(areaToSign);
+ return result;
+ } else
+ pAuth = &auth;
+
+ MUTEX_LOCK(tcsp_lock);
+
+ result = TCSP_Sign_Internal(hContext, hKey, areaToSignSize, areaToSign, pAuth, &sigSize,
+ &sig);
+
+ MUTEX_UNLOCK(tcsp_lock);
+ free(areaToSign);
+
+ if (result == TSS_SUCCESS) {
+ i = 0;
+ initData(&data->comm, 3);
+ if (pAuth != NULL) {
+ if (setData(TCSD_PACKET_TYPE_AUTH, i++, &auth, 0, &data->comm)) {
+ free(sig);
+ return TCSERR(TSS_E_INTERNAL_ERROR);
+ }
+ }
+ if (setData(TCSD_PACKET_TYPE_UINT32, i++, &sigSize, 0, &data->comm)) {
+ free(sig);
+ return TCSERR(TSS_E_INTERNAL_ERROR);
+ }
+ if (setData(TCSD_PACKET_TYPE_PBYTE, i++, sig, sigSize, &data->comm)) {
+ free(sig);
+ return TCSERR(TSS_E_INTERNAL_ERROR);
+ }
+ free(sig);
+ } else
+done: initData(&data->comm, 0);
+
+ data->comm.hdr.u.result = result;
+ return TSS_SUCCESS;
+}
diff --git a/pool/shard000/C/0008453_tcp_client.c b/pool/shard000/C/0008453_tcp_client.c
new file mode 100644
index 0000000000000000000000000000000000000000..e0dafd076d15d776bc53ec55f7dcd29c23282b4a
--- /dev/null
+++ b/pool/shard000/C/0008453_tcp_client.c
@@ -0,0 +1,61 @@
+
+#include
+#include
+#include
+#include
+#include
+
+#include
+#include
+
+
+int
+main(int argc, char *argv[])
+{
+ int sockfd;
+ struct sockaddr_in serv_addr;
+ int str_len, read_len, i;
+ char msg[128];
+
+ if (argc != 3) {
+ fprintf(stderr, "Usage: ./%s \n", argv[0]);
+ exit(EXIT_FAILURE);
+ }
+
+ // same as: socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
+ if ((sockfd = socket(AF_INET, SOCK_STREAM, 0)) == -1) {
+ perror("socket() failed");
+ exit(EXIT_FAILURE);
+ }
+
+ memset(&serv_addr, 0, sizeof(serv_addr));
+ serv_addr.sin_family = AF_INET;
+ serv_addr.sin_addr.s_addr = inet_addr(argv[1]);
+ serv_addr.sin_port = htons(atoi(argv[2]));
+
+ if (connect(sockfd, (struct sockaddr *) &serv_addr, sizeof(serv_addr)) == -1) {
+ fprintf(stderr, "connect() failed: %s\n", strerror(errno));
+ exit(EXIT_FAILURE);
+ }
+
+
+ i = 0;
+ while ((read_len = read(sockfd, &msg[i++], 1))) {
+ if (read_len == -1) {
+ perror("read() failed");
+ close(sockfd);
+ exit(EXIT_FAILURE);
+ }
+
+ str_len += read_len;
+ }
+
+ msg[str_len] = '\0';
+ printf("[recv %d bytes] %s\n", str_len, msg);
+
+ close(sockfd);
+
+ return 0;
+}
+
+
diff --git a/pool/shard000/C/0008478_gimpimage-pick-color.c b/pool/shard000/C/0008478_gimpimage-pick-color.c
new file mode 100644
index 0000000000000000000000000000000000000000..d6601b0ab7ebb79b196807fb476b67ee2f7925d9
--- /dev/null
+++ b/pool/shard000/C/0008478_gimpimage-pick-color.c
@@ -0,0 +1,86 @@
+/* GIMP - The GNU Image Manipulation Program
+ * Copyright (C) 1995-2001 Spencer Kimball, Peter Mattis, and others
+ *
+ * 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.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ */
+
+#include "config.h"
+
+#include
+
+#include "core-types.h"
+
+#include "gimpdrawable.h"
+#include "gimpimage.h"
+#include "gimpimage-pick-color.h"
+#include "gimppickable.h"
+
+
+gboolean
+gimp_image_pick_color (GimpImage *image,
+ GimpDrawable *drawable,
+ gint x,
+ gint y,
+ gboolean sample_merged,
+ gboolean sample_average,
+ gdouble average_radius,
+ GimpImageType *sample_type,
+ GimpRGB *color,
+ gint *color_index)
+{
+ GimpPickable *pickable;
+
+ g_return_val_if_fail (GIMP_IS_IMAGE (image), FALSE);
+ g_return_val_if_fail (drawable == NULL || GIMP_IS_DRAWABLE (drawable), FALSE);
+ g_return_val_if_fail (drawable == NULL ||
+ gimp_item_get_image (GIMP_ITEM (drawable)) == image,
+ FALSE);
+
+ if (! sample_merged)
+ {
+ if (! drawable)
+ drawable = gimp_image_get_active_drawable (image);
+
+ if (! drawable)
+ return FALSE;
+ }
+
+ if (sample_merged)
+ {
+ pickable = GIMP_PICKABLE (image->projection);
+ }
+ else
+ {
+ gint off_x, off_y;
+
+ gimp_item_offsets (GIMP_ITEM (drawable), &off_x, &off_y);
+ x -= off_x;
+ y -= off_y;
+
+ pickable = GIMP_PICKABLE (drawable);
+ }
+
+ /* Do *not* call gimp_pickable_flush() here because it's too expensive
+ * to call it unconditionally each time e.g. the cursor view is updated.
+ * Instead, call gimp_pickable_flush() in the callers if needed.
+ */
+
+ if (sample_type)
+ *sample_type = gimp_pickable_get_image_type (pickable);
+
+ return gimp_pickable_pick_color (pickable, x, y,
+ sample_average, average_radius,
+ color, color_index);
+}
diff --git a/pool/shard000/C/0008496_display.c b/pool/shard000/C/0008496_display.c
new file mode 100644
index 0000000000000000000000000000000000000000..15f9edab45e03905fd58e52083bbbe4960b3f217
--- /dev/null
+++ b/pool/shard000/C/0008496_display.c
@@ -0,0 +1,315 @@
+/*
+ * Copyright (C) 2009 Arnaud "arnau" Fontaine
+ *
+ * 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 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see
+ * .
+ */
+
+/** \file
+ * \brief Display management run on startup
+ */
+
+#include
+#include
+#include
+
+#include
+#include
+#include
+#include
+#include
+#include
+
+#include "structs.h"
+#include "display.h"
+#include "atoms.h"
+#include "event.h"
+#include "window.h"
+#include "util.h"
+
+/** Structure holding cookies for QueryVersion requests of
+ extensions */
+typedef struct {
+ /** XFixes QueryVersion request cookie */
+ xcb_xfixes_query_version_cookie_t xfixes;
+ /** Damage QueryVersion request cookie */
+ xcb_damage_query_version_cookie_t damage;
+ /** Composite QueryVersion request cookie */
+ xcb_composite_query_version_cookie_t composite;
+} init_extensions_cookies_t;
+
+/** NOTICE: All above variables are not thread-safe, but well, we
+ don't care as they are only used during initialisation */
+
+/** Initialise the QueryVersion extensions cookies with a 0 sequence
+ number, this is not thread-safe but we don't care here as it is
+ only used during initialisation */
+static init_extensions_cookies_t _init_extensions_cookies = { { 0 }, { 0 }, { 0 } };
+
+/** Cookie request used when acquiring ownership on _NET_WM_CM_Sn */
+static xcb_get_selection_owner_cookie_t _get_wm_cm_owner_cookie = { 0 };
+
+/** Cookie when querying the windows tree starting from the root
+ window */
+static xcb_query_tree_cookie_t _query_tree_cookie = { 0 };
+
+/** Check whether the needed X extensions are present on the
+ * server-side (all the data have been previously pre-fetched in the
+ * extension cache). Then send requests to check their version by
+ * sending QueryVersion requests which is compulsory because the
+ * client MUST negotiate the version of the extension before
+ * executing extension requests
+ */
+void
+display_init_extensions(void)
+{
+ globalconf.extensions.composite = xcb_get_extension_data(globalconf.connection,
+ &xcb_composite_id);
+
+ globalconf.extensions.xfixes = xcb_get_extension_data(globalconf.connection,
+ &xcb_xfixes_id);
+
+ globalconf.extensions.damage = xcb_get_extension_data(globalconf.connection,
+ &xcb_damage_id);
+
+ if(!globalconf.extensions.composite ||
+ !globalconf.extensions.composite->present)
+ fatal("No Composite extension");
+
+ debug("Composite: major_opcode=%ju",
+ (uintmax_t) globalconf.extensions.composite->major_opcode);
+
+ if(!globalconf.extensions.xfixes ||
+ !globalconf.extensions.xfixes->present)
+ fatal("No XFixes extension");
+
+ debug("XFixes: major_opcode=%ju",
+ (uintmax_t) globalconf.extensions.xfixes->major_opcode);
+
+ if(!globalconf.extensions.damage ||
+ !globalconf.extensions.damage->present)
+ fatal("No Damage extension");
+
+ debug("Damage: major_opcode=%ju",
+ (uintmax_t) globalconf.extensions.damage->major_opcode);
+
+ _init_extensions_cookies.composite =
+ xcb_composite_query_version_unchecked(globalconf.connection,
+ XCB_COMPOSITE_MAJOR_VERSION,
+ XCB_COMPOSITE_MINOR_VERSION);
+
+ _init_extensions_cookies.damage =
+ xcb_damage_query_version_unchecked(globalconf.connection,
+ XCB_DAMAGE_MAJOR_VERSION,
+ XCB_DAMAGE_MINOR_VERSION);
+
+ _init_extensions_cookies.xfixes =
+ xcb_xfixes_query_version_unchecked(globalconf.connection,
+ XCB_XFIXES_MAJOR_VERSION,
+ XCB_XFIXES_MINOR_VERSION);
+}
+
+/** Get the replies of the QueryVersion requests previously sent and
+ * check if their version actually matched the versions needed
+ *
+ * \see display_init_extensions
+ */
+void
+display_init_extensions_finalise(void)
+{
+ assert(_init_extensions_cookies.composite.sequence);
+
+ xcb_composite_query_version_reply_t *composite_version_reply =
+ xcb_composite_query_version_reply(globalconf.connection,
+ _init_extensions_cookies.composite,
+ NULL);
+
+ /* Need NameWindowPixmap support introduced in version >= 0.2 */
+ if(!composite_version_reply || composite_version_reply->minor_version < 2)
+ {
+ free(composite_version_reply);
+ fatal("Need Composite extension 0.2 at least");
+ }
+
+ free(composite_version_reply);
+
+ assert(_init_extensions_cookies.damage.sequence);
+
+ xcb_damage_query_version_reply_t *damage_version_reply =
+ xcb_damage_query_version_reply(globalconf.connection,
+ _init_extensions_cookies.damage,
+ NULL);
+
+ if(!damage_version_reply)
+ fatal("Can't initialise Damage extension");
+
+ free(damage_version_reply);
+
+ assert(_init_extensions_cookies.xfixes.sequence);
+
+ xcb_xfixes_query_version_reply_t *xfixes_version_reply =
+ xcb_xfixes_query_version_reply(globalconf.connection,
+ _init_extensions_cookies.xfixes,
+ NULL);
+
+ /* Need Region objects support introduced in version >= 2.0 */
+ if(!xfixes_version_reply || xfixes_version_reply->major_version < 2)
+ {
+ free(xfixes_version_reply);
+ fatal("Need XFixes extension 2.0 at least");
+ }
+
+ free(xfixes_version_reply);
+}
+
+/** Handler for PropertyNotify event meaningful to set the timestamp
+ * (given in the PropertyNotify event field) when acquiring the
+ * ownership of _NET_WM_CM_Sn using SetOwner request (as specified in
+ * ICCCM and EWMH)
+ *
+ * \see display_register_cm
+ * \param event The X PropertyNotify event
+ */
+static int
+display_event_set_owner_property(void *data __attribute__((unused)),
+ xcb_connection_t *c __attribute__((unused)),
+ xcb_property_notify_event_t *event)
+{
+ debug("Set _NET_WM_CM_Sn ownership");
+
+ /* Set ownership on _NET_WM_CM_Sn giving the Compositing Manager window */
+ xcb_ewmh_set_wm_cm_owner(&globalconf.ewmh, globalconf.screen_nbr,
+ globalconf.cm_window, event->time, 0, 0);
+
+ /* Send request to check whether the ownership succeeded */
+ _get_wm_cm_owner_cookie = xcb_ewmh_get_wm_cm_owner_unchecked(&globalconf.ewmh,
+ globalconf.screen_nbr);
+
+ return 0;
+}
+
+/** Register Compositing Manager, e.g. set ownership on EMWH
+ * _NET_WM_CM_Sn atom used to politely stating that a Compositing
+ * Manager is currently running. Acquiring ownership is done in the
+ * following steps (ICCCM explains the principles of selection
+ * ownership):
+ *
+ * 0/ Check whether this selection is already owned by another
+ * program
+ *
+ * 1/ Create a Window whose identifier is set as the _NET_WM_CM_Sn
+ * value
+ *
+ * 2/ Change a Window property to generate a PropertyNotify event
+ * used as the timestamp to SetOwner request as multiple attempts
+ * may be sent at the same time
+ *
+ * 3/ Send SetOwner request
+ *
+ * 4/ Check whether the SetOwner request succeeds
+ */
+void
+display_register_cm(void)
+{
+ globalconf.cm_window = xcb_generate_id(globalconf.connection);
+
+ /* Create a dummy window meaningful to set the ownership on
+ _NET_WM_CM_Sn atom */
+ const uint32_t create_win_val[] = { true, XCB_EVENT_MASK_PROPERTY_CHANGE };
+
+ xcb_create_window(globalconf.connection, XCB_COPY_FROM_PARENT,
+ globalconf.cm_window, globalconf.screen->root, 0, 0, 1, 1, 0,
+ XCB_COPY_FROM_PARENT, XCB_COPY_FROM_PARENT,
+ XCB_CW_OVERRIDE_REDIRECT | XCB_CW_EVENT_MASK,
+ create_win_val);
+
+ xcb_event_set_property_notify_handler(&globalconf.evenths,
+ display_event_set_owner_property,
+ NULL);
+
+ xcb_change_property(globalconf.connection, XCB_PROP_MODE_REPLACE,
+ globalconf.cm_window, globalconf.ewmh._NET_WM_NAME,
+ globalconf.ewmh.UTF8_STRING, 8,
+ sizeof(PACKAGE_NAME), PACKAGE_NAME);
+}
+
+/** Finish acquiring ownership by checking whether the SetOwner
+ * request succeeded
+ *
+ * \see display_register_cm
+ * \return bool true if it succeeded, false otherwise
+ */
+bool
+display_register_cm_finalise(void)
+{
+ assert(_get_wm_cm_owner_cookie.sequence);
+
+ xcb_window_t wm_cm_owner_win;
+
+ /* Check whether the ownership of WM_CM_Sn succeeded */
+ return (xcb_ewmh_get_wm_cm_owner_reply(&globalconf.ewmh, _get_wm_cm_owner_cookie,
+ &wm_cm_owner_win, NULL) &&
+ wm_cm_owner_win == globalconf.cm_window);
+}
+
+/** Redirect all the windows to the off-screen buffer starting from
+ * the root window and change root window attributes to make the
+ * server reporting meaningful events
+ */
+void
+display_init_redirect(void)
+{
+ /* Manage all children windows from the root window */
+ _query_tree_cookie = xcb_query_tree_unchecked(globalconf.connection,
+ globalconf.screen->root);
+
+ xcb_composite_redirect_subwindows(globalconf.connection,
+ globalconf.screen->root,
+ XCB_COMPOSITE_REDIRECT_MANUAL);
+
+ /* Declare interest in meaningful events */
+ const uint32_t select_input_val =
+ XCB_EVENT_MASK_KEY_PRESS |
+ XCB_EVENT_MASK_KEY_RELEASE |
+ XCB_EVENT_MASK_BUTTON_RELEASE |
+ XCB_EVENT_MASK_SUBSTRUCTURE_NOTIFY |
+ XCB_EVENT_MASK_STRUCTURE_NOTIFY |
+ XCB_EVENT_MASK_PROPERTY_CHANGE;
+
+ xcb_change_window_attributes(globalconf.connection, globalconf.screen->root,
+ XCB_CW_EVENT_MASK, &select_input_val);
+}
+
+/** Finish redirection by adding all the existing windows in the
+ * hierarchy
+ */
+void
+display_init_redirect_finalise(void)
+{
+ assert(_query_tree_cookie.sequence);
+
+ /* Get all the windows below the root window */
+ xcb_query_tree_reply_t *query_tree_reply =
+ xcb_query_tree_reply(globalconf.connection,
+ _query_tree_cookie,
+ NULL);
+
+ /* Add all these windows excluding the root window of course */
+ const int nwindows = xcb_query_tree_children_length(query_tree_reply);
+ if(nwindows)
+ window_manage_existing(nwindows,
+ xcb_query_tree_children(query_tree_reply));
+
+ free(query_tree_reply);
+}
diff --git a/pool/shard000/C/0008502_gnutls_global.c b/pool/shard000/C/0008502_gnutls_global.c
new file mode 100644
index 0000000000000000000000000000000000000000..30828a3ab8eb9fe6b386aaae26c561f08255a531
--- /dev/null
+++ b/pool/shard000/C/0008502_gnutls_global.c
@@ -0,0 +1,341 @@
+/*
+ * Copyright (C) 2001-2012 Free Software Foundation, Inc.
+ *
+ * Author: Nikos Mavrogiannopoulos
+ *
+ * This file is part of GnuTLS.
+ *
+ * The GnuTLS is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public License
+ * as published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program. If not, see .
+ *
+ */
+
+#include
+#include
+#include
+#include
+#include
+#include
+
+#include /* for _gnutls_ext_init */
+#include
+#include
+#include
+#include
+
+#include "sockets.h"
+#include "gettext.h"
+
+/* Minimum library versions we accept. */
+#define GNUTLS_MIN_LIBTASN1_VERSION "0.3.4"
+
+/* created by asn1c */
+extern const ASN1_ARRAY_TYPE gnutls_asn1_tab[];
+extern const ASN1_ARRAY_TYPE pkix_asn1_tab[];
+void *_gnutls_file_mutex;
+
+ASN1_TYPE _gnutls_pkix1_asn;
+ASN1_TYPE _gnutls_gnutls_asn;
+
+gnutls_log_func _gnutls_log_func = NULL;
+gnutls_audit_log_func _gnutls_audit_log_func = NULL;
+int _gnutls_log_level = 0; /* default log level */
+
+static void default_log_func(int level, const char* str)
+{
+ fprintf(stderr, "gnutls[%d]: %s\n", level, str);
+}
+
+/**
+ * gnutls_global_set_log_function:
+ * @log_func: it's a log function
+ *
+ * This is the function where you set the logging function gnutls is
+ * going to use. This function only accepts a character array.
+ * Normally you may not use this function since it is only used for
+ * debugging purposes.
+ *
+ * @gnutls_log_func is of the form,
+ * void (*gnutls_log_func)( int level, const char*);
+ **/
+void gnutls_global_set_log_function(gnutls_log_func log_func)
+{
+ _gnutls_log_func = log_func;
+}
+
+/**
+ * gnutls_global_set_audit_log_function:
+ * @log_func: it is the audit log function
+ *
+ * This is the function to set the audit logging function. This
+ * is a function to report important issues, such as possible
+ * attacks in the protocol. This is different from gnutls_global_set_log_function()
+ * because it will report also session-specific events. The session
+ * parameter will be null if there is no corresponding TLS session.
+ *
+ * @gnutls_audit_log_func is of the form,
+ * void (*gnutls_audit_log_func)( gnutls_session_t, const char*);
+ *
+ * Since: 3.0
+ **/
+void gnutls_global_set_audit_log_function(gnutls_audit_log_func log_func)
+{
+ _gnutls_audit_log_func = log_func;
+}
+
+/**
+ * gnutls_global_set_time_function:
+ * @time_func: it's the system time function, a gnutls_time_func() callback.
+ *
+ * This is the function where you can override the default system time
+ * function. The application provided function should behave the same
+ * as the standard function.
+ *
+ * Since: 2.12.0
+ **/
+void gnutls_global_set_time_function(gnutls_time_func time_func)
+{
+ gnutls_time = time_func;
+}
+
+/**
+ * gnutls_global_set_log_level:
+ * @level: it's an integer from 0 to 9.
+ *
+ * This is the function that allows you to set the log level. The
+ * level is an integer between 0 and 9. Higher values mean more
+ * verbosity. The default value is 0. Larger values should only be
+ * used with care, since they may reveal sensitive information.
+ *
+ * Use a log level over 10 to enable all debugging options.
+ **/
+void gnutls_global_set_log_level(int level)
+{
+ _gnutls_log_level = level;
+}
+
+/**
+ * gnutls_global_set_mem_functions:
+ * @alloc_func: it's the default memory allocation function. Like malloc().
+ * @secure_alloc_func: This is the memory allocation function that will be used for sensitive data.
+ * @is_secure_func: a function that returns 0 if the memory given is not secure. May be NULL.
+ * @realloc_func: A realloc function
+ * @free_func: The function that frees allocated data. Must accept a NULL pointer.
+ *
+ * This is the function where you set the memory allocation functions
+ * gnutls is going to use. By default the libc's allocation functions
+ * (malloc(), free()), are used by gnutls, to allocate both sensitive
+ * and not sensitive data. This function is provided to set the
+ * memory allocation functions to something other than the defaults
+ *
+ * This function must be called before gnutls_global_init() is called.
+ * This function is not thread safe.
+ **/
+void
+gnutls_global_set_mem_functions(gnutls_alloc_function alloc_func,
+ gnutls_alloc_function secure_alloc_func,
+ gnutls_is_secure_function is_secure_func,
+ gnutls_realloc_function realloc_func,
+ gnutls_free_function free_func)
+{
+ gnutls_secure_malloc = secure_alloc_func;
+ gnutls_malloc = alloc_func;
+ gnutls_realloc = realloc_func;
+ gnutls_free = free_func;
+
+ /* if using the libc's default malloc
+ * use libc's calloc as well.
+ */
+ if (gnutls_malloc == malloc) {
+ gnutls_calloc = calloc;
+ } else { /* use the included ones */
+ gnutls_calloc = _gnutls_calloc;
+ }
+ gnutls_strdup = _gnutls_strdup;
+
+}
+
+static int _gnutls_init = 0;
+
+/**
+ * gnutls_global_init:
+ *
+ * This function performs any required precalculations, detects
+ * the supported CPU capabilities and initializes the underlying
+ * cryptographic backend. In order to free any resources
+ * taken by this call you should gnutls_global_deinit()
+ * when gnutls usage is no longer needed.
+ *
+ * This function increments a global counter, so that
+ * gnutls_global_deinit() only releases resources when it has been
+ * called as many times as gnutls_global_init(). This is useful when
+ * GnuTLS is used by more than one library in an application. This
+ * function can be called many times, but will only do something the
+ * first time.
+ *
+ * Note! This function is not thread safe. If two threads call this
+ * function simultaneously, they can cause a race between checking
+ * the global counter and incrementing it, causing both threads to
+ * execute the library initialization code. That could lead to a
+ * memory leak or even a crash. To handle this, your application should
+ * invoke this function after aquiring a thread mutex.
+ *
+ * Returns: On success, %GNUTLS_E_SUCCESS (0) is returned,
+ * otherwise a negative error code is returned.
+ **/
+int gnutls_global_init(void)
+{
+ int result = 0;
+ int res, level;
+ const char* e;
+
+ if (_gnutls_init++)
+ goto out;
+
+ e = getenv("GNUTLS_DEBUG_LEVEL");
+ if (e != NULL) {
+ level = atoi(e);
+ gnutls_global_set_log_level(level);
+ if (_gnutls_log_func == NULL)
+ gnutls_global_set_log_function(default_log_func);
+ _gnutls_debug_log("Enabled GnuTLS logging...\n");
+ }
+
+ if (gl_sockets_startup(SOCKETS_1_1))
+ return gnutls_assert_val(GNUTLS_E_FILE_ERROR);
+
+ bindtextdomain(PACKAGE, LOCALEDIR);
+
+ res = gnutls_crypto_init();
+ if (res != 0) {
+ gnutls_assert();
+ return GNUTLS_E_CRYPTO_INIT_FAILED;
+ }
+
+ _gnutls_register_accel_crypto();
+
+ /* initialize ASN.1 parser
+ * This should not deal with files in the final
+ * version.
+ */
+ if (asn1_check_version(GNUTLS_MIN_LIBTASN1_VERSION) == NULL) {
+ gnutls_assert();
+ _gnutls_debug_log
+ ("Checking for libtasn1 failed: %s < %s\n",
+ asn1_check_version(NULL),
+ GNUTLS_MIN_LIBTASN1_VERSION);
+ return GNUTLS_E_INCOMPATIBLE_LIBTASN1_LIBRARY;
+ }
+
+ res = asn1_array2tree(pkix_asn1_tab, &_gnutls_pkix1_asn, NULL);
+ if (res != ASN1_SUCCESS) {
+ result = _gnutls_asn2err(res);
+ goto out;
+ }
+
+ res = asn1_array2tree(gnutls_asn1_tab, &_gnutls_gnutls_asn, NULL);
+ if (res != ASN1_SUCCESS) {
+ result = _gnutls_asn2err(res);
+ goto out;
+ }
+
+ /* Initialize the random generator */
+ result = _gnutls_rnd_init();
+ if (result < 0) {
+ gnutls_assert();
+ goto out;
+ }
+
+ /* Initialize the default TLS extensions */
+ result = _gnutls_ext_init();
+ if (result < 0) {
+ gnutls_assert();
+ goto out;
+ }
+
+ result = gnutls_mutex_init(&_gnutls_file_mutex);
+ if (result < 0) {
+ gnutls_assert();
+ goto out;
+ }
+
+ result = gnutls_system_global_init();
+ if (result < 0) {
+ gnutls_assert();
+ goto out;
+ }
+#ifdef ENABLE_PKCS11
+ gnutls_pkcs11_init(GNUTLS_PKCS11_FLAG_AUTO, NULL);
+#endif
+
+ _gnutls_cryptodev_init();
+
+ out:
+ return result;
+}
+
+/**
+ * gnutls_global_deinit:
+ *
+ * This function deinitializes the global data, that were initialized
+ * using gnutls_global_init().
+ *
+ * Note! This function is not thread safe. See the discussion for
+ * gnutls_global_init() for more information.
+ **/
+void gnutls_global_deinit(void)
+{
+ if (_gnutls_init == 1) {
+ gl_sockets_cleanup();
+ gnutls_crypto_deinit();
+ _gnutls_rnd_deinit();
+ _gnutls_ext_deinit();
+ asn1_delete_structure(&_gnutls_gnutls_asn);
+ asn1_delete_structure(&_gnutls_pkix1_asn);
+ _gnutls_crypto_deregister();
+ _gnutls_cryptodev_deinit();
+ gnutls_system_global_deinit();
+#ifdef ENABLE_PKCS11
+ gnutls_pkcs11_deinit();
+#endif
+ gnutls_mutex_deinit(&_gnutls_file_mutex);
+ }
+ _gnutls_init--;
+}
+
+/* These functions should be elsewere. Kept here for
+ * historical reasons.
+ */
+
+
+/**
+ * gnutls_check_version:
+ * @req_version: version string to compare with, or %NULL.
+ *
+ * Check GnuTLS Library version.
+ *
+ * See %GNUTLS_VERSION for a suitable @req_version string.
+ *
+ * Returns: Check that the version of the library is at
+ * minimum the one given as a string in @req_version and return the
+ * actual version string of the library; return %NULL if the
+ * condition is not met. If %NULL is passed to this function no
+ * check is done and only the version string is returned.
+ **/
+const char *gnutls_check_version(const char *req_version)
+{
+ if (!req_version || strverscmp(req_version, VERSION) <= 0)
+ return VERSION;
+
+ return NULL;
+}
diff --git a/pool/shard000/C/0008506_avic.c b/pool/shard000/C/0008506_avic.c
new file mode 100644
index 0000000000000000000000000000000000000000..322caa21bcb36f76f94f77e930161b1df8572379
--- /dev/null
+++ b/pool/shard000/C/0008506_avic.c
@@ -0,0 +1,222 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright 2004-2007 Freescale Semiconductor, Inc. All Rights Reserved.
+ * Copyright 2008 Juergen Beisert, kernel@pengutronix.de
+ */
+
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+
+#include "common.h"
+#include "hardware.h"
+#include "irq-common.h"
+
+#define AVIC_INTCNTL 0x00 /* int control reg */
+#define AVIC_NIMASK 0x04 /* int mask reg */
+#define AVIC_INTENNUM 0x08 /* int enable number reg */
+#define AVIC_INTDISNUM 0x0C /* int disable number reg */
+#define AVIC_INTENABLEH 0x10 /* int enable reg high */
+#define AVIC_INTENABLEL 0x14 /* int enable reg low */
+#define AVIC_INTTYPEH 0x18 /* int type reg high */
+#define AVIC_INTTYPEL 0x1C /* int type reg low */
+#define AVIC_NIPRIORITY(x) (0x20 + 4 * (7 - (x))) /* int priority */
+#define AVIC_NIVECSR 0x40 /* norm int vector/status */
+#define AVIC_FIVECSR 0x44 /* fast int vector/status */
+#define AVIC_INTSRCH 0x48 /* int source reg high */
+#define AVIC_INTSRCL 0x4C /* int source reg low */
+#define AVIC_INTFRCH 0x50 /* int force reg high */
+#define AVIC_INTFRCL 0x54 /* int force reg low */
+#define AVIC_NIPNDH 0x58 /* norm int pending high */
+#define AVIC_NIPNDL 0x5C /* norm int pending low */
+#define AVIC_FIPNDH 0x60 /* fast int pending high */
+#define AVIC_FIPNDL 0x64 /* fast int pending low */
+
+#define AVIC_NUM_IRQS 64
+
+/* low power interrupt mask registers */
+#define MX25_CCM_LPIMR0 0x68
+#define MX25_CCM_LPIMR1 0x6C
+
+static void __iomem *avic_base;
+static void __iomem *mx25_ccm_base;
+static struct irq_domain *domain;
+
+#ifdef CONFIG_FIQ
+static int avic_set_irq_fiq(unsigned int hwirq, unsigned int type)
+{
+ unsigned int irqt;
+
+ if (hwirq >= AVIC_NUM_IRQS)
+ return -EINVAL;
+
+ if (hwirq < AVIC_NUM_IRQS / 2) {
+ irqt = imx_readl(avic_base + AVIC_INTTYPEL) & ~(1 << hwirq);
+ imx_writel(irqt | (!!type << hwirq), avic_base + AVIC_INTTYPEL);
+ } else {
+ hwirq -= AVIC_NUM_IRQS / 2;
+ irqt = imx_readl(avic_base + AVIC_INTTYPEH) & ~(1 << hwirq);
+ imx_writel(irqt | (!!type << hwirq), avic_base + AVIC_INTTYPEH);
+ }
+
+ return 0;
+}
+#endif /* CONFIG_FIQ */
+
+
+static struct mxc_extra_irq avic_extra_irq = {
+#ifdef CONFIG_FIQ
+ .set_irq_fiq = avic_set_irq_fiq,
+#endif
+};
+
+#ifdef CONFIG_PM
+static u32 avic_saved_mask_reg[2];
+
+static void avic_irq_suspend(struct irq_data *d)
+{
+ struct irq_chip_generic *gc = irq_data_get_irq_chip_data(d);
+ struct irq_chip_type *ct = gc->chip_types;
+ int idx = d->hwirq >> 5;
+
+ avic_saved_mask_reg[idx] = imx_readl(avic_base + ct->regs.mask);
+ imx_writel(gc->wake_active, avic_base + ct->regs.mask);
+
+ if (mx25_ccm_base) {
+ u8 offs = d->hwirq < AVIC_NUM_IRQS / 2 ?
+ MX25_CCM_LPIMR0 : MX25_CCM_LPIMR1;
+ /*
+ * The interrupts which are still enabled will be used as wakeup
+ * sources. Allow those interrupts in low-power mode.
+ * The LPIMR registers use 0 to allow an interrupt, the AVIC
+ * registers use 1.
+ */
+ imx_writel(~gc->wake_active, mx25_ccm_base + offs);
+ }
+}
+
+static void avic_irq_resume(struct irq_data *d)
+{
+ struct irq_chip_generic *gc = irq_data_get_irq_chip_data(d);
+ struct irq_chip_type *ct = gc->chip_types;
+ int idx = d->hwirq >> 5;
+
+ imx_writel(avic_saved_mask_reg[idx], avic_base + ct->regs.mask);
+
+ if (mx25_ccm_base) {
+ u8 offs = d->hwirq < AVIC_NUM_IRQS / 2 ?
+ MX25_CCM_LPIMR0 : MX25_CCM_LPIMR1;
+
+ imx_writel(0xffffffff, mx25_ccm_base + offs);
+ }
+}
+
+#else
+#define avic_irq_suspend NULL
+#define avic_irq_resume NULL
+#endif
+
+static __init void avic_init_gc(int idx, unsigned int irq_start)
+{
+ struct irq_chip_generic *gc;
+ struct irq_chip_type *ct;
+
+ gc = irq_alloc_generic_chip("mxc-avic", 1, irq_start, avic_base,
+ handle_level_irq);
+ gc->private = &avic_extra_irq;
+ gc->wake_enabled = IRQ_MSK(32);
+
+ ct = gc->chip_types;
+ ct->chip.irq_mask = irq_gc_mask_clr_bit;
+ ct->chip.irq_unmask = irq_gc_mask_set_bit;
+ ct->chip.irq_ack = irq_gc_mask_clr_bit;
+ ct->chip.irq_set_wake = irq_gc_set_wake;
+ ct->chip.irq_suspend = avic_irq_suspend;
+ ct->chip.irq_resume = avic_irq_resume;
+ ct->regs.mask = !idx ? AVIC_INTENABLEL : AVIC_INTENABLEH;
+ ct->regs.ack = ct->regs.mask;
+
+ irq_setup_generic_chip(gc, IRQ_MSK(32), 0, IRQ_NOREQUEST, 0);
+}
+
+static void __exception_irq_entry avic_handle_irq(struct pt_regs *regs)
+{
+ u32 nivector;
+
+ do {
+ nivector = imx_readl(avic_base + AVIC_NIVECSR) >> 16;
+ if (nivector == 0xffff)
+ break;
+
+ handle_domain_irq(domain, nivector, regs);
+ } while (1);
+}
+
+/*
+ * This function initializes the AVIC hardware and disables all the
+ * interrupts. It registers the interrupt enable and disable functions
+ * to the kernel for each interrupt source.
+ */
+void __init mxc_init_irq(void __iomem *irqbase)
+{
+ struct device_node *np;
+ int irq_base;
+ int i;
+
+ avic_base = irqbase;
+
+ np = of_find_compatible_node(NULL, NULL, "fsl,imx25-ccm");
+ mx25_ccm_base = of_iomap(np, 0);
+
+ if (mx25_ccm_base) {
+ /*
+ * By default, we mask all interrupts. We set the actual mask
+ * before we go into low-power mode.
+ */
+ imx_writel(0xffffffff, mx25_ccm_base + MX25_CCM_LPIMR0);
+ imx_writel(0xffffffff, mx25_ccm_base + MX25_CCM_LPIMR1);
+ }
+
+ /* put the AVIC into the reset value with
+ * all interrupts disabled
+ */
+ imx_writel(0, avic_base + AVIC_INTCNTL);
+ imx_writel(0x1f, avic_base + AVIC_NIMASK);
+
+ /* disable all interrupts */
+ imx_writel(0, avic_base + AVIC_INTENABLEH);
+ imx_writel(0, avic_base + AVIC_INTENABLEL);
+
+ /* all IRQ no FIQ */
+ imx_writel(0, avic_base + AVIC_INTTYPEH);
+ imx_writel(0, avic_base + AVIC_INTTYPEL);
+
+ irq_base = irq_alloc_descs(-1, 0, AVIC_NUM_IRQS, numa_node_id());
+ WARN_ON(irq_base < 0);
+
+ np = of_find_compatible_node(NULL, NULL, "fsl,avic");
+ domain = irq_domain_add_legacy(np, AVIC_NUM_IRQS, irq_base, 0,
+ &irq_domain_simple_ops, NULL);
+ WARN_ON(!domain);
+
+ for (i = 0; i < AVIC_NUM_IRQS / 32; i++, irq_base += 32)
+ avic_init_gc(i, irq_base);
+
+ /* Set default priority value (0) for all IRQ's */
+ for (i = 0; i < 8; i++)
+ imx_writel(0, avic_base + AVIC_NIPRIORITY(i));
+
+ set_handle_irq(avic_handle_irq);
+
+#ifdef CONFIG_FIQ
+ /* Initialize FIQ */
+ init_FIQ(FIQ_START);
+#endif
+
+ printk(KERN_INFO "MXC IRQ initialized\n");
+}
diff --git a/pool/shard000/C/0008520_abspath.c b/pool/shard000/C/0008520_abspath.c
new file mode 100644
index 0000000000000000000000000000000000000000..057b2b8933c1be98bf270645f9b2957b1959f51a
--- /dev/null
+++ b/pool/shard000/C/0008520_abspath.c
@@ -0,0 +1,97 @@
+/* Copyright (c) 2009-2014 Dovecot authors, see the included COPYING file */
+
+#include "lib.h"
+#include "str.h"
+#include "abspath.h"
+
+#include
+#include
+
+const char *t_abspath(const char *path)
+{
+ const char *dir;
+
+ if (*path == '/')
+ return path;
+
+ if (t_get_current_dir(&dir) < 0)
+ i_fatal("getcwd() failed: %m");
+ return t_strconcat(dir, "/", path, NULL);
+}
+
+const char *t_abspath_to(const char *path, const char *root)
+{
+ if (*path == '/')
+ return path;
+
+ return t_strconcat(root, "/", path, NULL);
+}
+
+int t_get_current_dir(const char **dir_r)
+{
+ /* @UNSAFE */
+ char *dir;
+ size_t size = 128;
+
+ dir = t_buffer_get(size);
+ while (getcwd(dir, size) == NULL) {
+ if (errno != ERANGE)
+ return -1;
+ size = nearest_power(size+1);
+ dir = t_buffer_get(size);
+ }
+ t_buffer_alloc(strlen(dir) + 1);
+ *dir_r = dir;
+ return 0;
+}
+
+int t_readlink(const char *path, const char **dest_r)
+{
+ /* @UNSAFE */
+ ssize_t ret;
+ char *dest;
+ size_t size = 128;
+
+ dest = t_buffer_get(size);
+ while ((ret = readlink(path, dest, size)) >= (ssize_t)size) {
+ size = nearest_power(size+1);
+ dest = t_buffer_get(size);
+ }
+ if (ret < 0)
+ return -1;
+
+ dest[ret] = '\0';
+ t_buffer_alloc(ret + 1);
+ *dest_r = dest;
+ return 0;
+}
+
+bool t_binary_abspath(const char **binpath)
+{
+ const char *path_env, *const *paths;
+ string_t *path;
+
+ if (**binpath == '/') {
+ /* already have absolute path */
+ return TRUE;
+ } else if (strchr(*binpath, '/') != NULL) {
+ /* relative to current directory */
+ *binpath = t_abspath(*binpath);
+ return TRUE;
+ } else if ((path_env = getenv("PATH")) != NULL) {
+ /* we have to find our executable from path */
+ path = t_str_new(256);
+ paths = t_strsplit(path_env, ":");
+ for (; *paths != NULL; paths++) {
+ str_append(path, *paths);
+ str_append_c(path, '/');
+ str_append(path, *binpath);
+ if (access(str_c(path), X_OK) == 0) {
+ *binpath = str_c(path);
+ return TRUE;
+ }
+ str_truncate(path, 0);
+ }
+ }
+ return FALSE;
+}
diff --git a/pool/shard000/C/0008521_msm7kv2-dai.c b/pool/shard000/C/0008521_msm7kv2-dai.c
new file mode 100644
index 0000000000000000000000000000000000000000..dbb4973f15f3ce1f07c63ac1e0ff3685af1b009c
--- /dev/null
+++ b/pool/shard000/C/0008521_msm7kv2-dai.c
@@ -0,0 +1,121 @@
+
+
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include "msm7kv2-pcm.h"
+
+struct snd_soc_dai msm_dais[] = {
+{
+ .name = "CODEC_DAI",
+ .playback = {
+ .stream_name = "Playback",
+ .channels_min = USE_CHANNELS_MIN,
+ .channels_max = USE_CHANNELS_MAX,
+ .rates = USE_RATE,
+ .rate_min = USE_RATE_MIN,
+ .rate_max = USE_RATE_MAX,
+ .formats = USE_FORMATS,
+ },
+ .capture = {
+ .stream_name = "Capture",
+ .channels_min = USE_CHANNELS_MIN,
+ .channels_max = USE_CHANNELS_MAX,
+ .rate_min = USE_RATE_MIN,
+ .rates = USE_RATE,
+ .formats = USE_FORMATS,
+ },
+},
+{
+ .name = "CPU_DAI",
+ .id = 0,
+ .playback = {
+ .channels_min = USE_CHANNELS_MIN,
+ .channels_max = USE_CHANNELS_MAX,
+ .rates = USE_RATE,
+ .rate_min = USE_RATE_MIN,
+ .rate_max = USE_RATE_MAX,
+ .formats = USE_FORMATS,
+ },
+ .capture = {
+ .channels_min = USE_CHANNELS_MIN,
+ .channels_max = USE_CHANNELS_MAX,
+ .rate_min = USE_RATE_MIN,
+ .rates = USE_RATE,
+ .formats = USE_FORMATS,
+ },
+},
+};
+EXPORT_SYMBOL_GPL(msm_dais);
+
+int msm_pcm_probe(struct platform_device *devptr)
+{
+ struct snd_soc_codec *codec;
+ int ret;
+
+ struct snd_soc_device *socdev = platform_get_drvdata(devptr);
+
+ printk(KERN_ERR "msm_soc: create pcms\n");
+ codec = kzalloc(sizeof(struct snd_soc_codec), GFP_KERNEL);
+ if (codec == NULL)
+ return -ENOMEM;
+
+ codec->name = "MSM-CARD";
+ codec->owner = THIS_MODULE;
+ socdev->card->codec = codec;
+ mutex_init(&codec->mutex);
+
+ INIT_LIST_HEAD(&codec->dapm_widgets);
+ INIT_LIST_HEAD(&codec->dapm_paths);
+
+
+ ret = snd_soc_new_pcms(socdev, SNDRV_DEFAULT_IDX1, SNDRV_DEFAULT_STR1);
+ if (ret < 0) {
+ printk(KERN_ERR "msm_soc: failed to create pcms\n");
+ goto __nopcm;
+ }
+
+ ret = snd_soc_init_card(socdev);
+ if (ret < 0) {
+ printk(KERN_ERR "msm_soc: failed to register card\n");
+ goto __nodev;
+ }
+
+ return 0;
+
+__nodev:
+ snd_soc_free_pcms(socdev);
+__nopcm:
+ kfree(codec);
+ return ret;
+}
+
+struct snd_soc_codec_device soc_codec_dev_msm = {
+ .probe = msm_pcm_probe,
+};
+EXPORT_SYMBOL_GPL(soc_codec_dev_msm);
+
+
+static int __init msm_dai_init(void)
+{
+ return snd_soc_register_dais(msm_dais, ARRAY_SIZE(msm_dais));
+}
+
+static void __exit msm_dai_exit(void)
+{
+ snd_soc_unregister_dais(msm_dais, ARRAY_SIZE(msm_dais));
+}
+
+module_init(msm_dai_init);
+module_exit(msm_dai_exit);
+
+
+MODULE_DESCRIPTION("MSM Codec/Cpu Dai driver");
+MODULE_LICENSE("GPL v2");
diff --git a/pool/shard000/C/0008538_10903.c b/pool/shard000/C/0008538_10903.c
new file mode 100644
index 0000000000000000000000000000000000000000..18bca997ac207ad5267804170b3ea59377202f3b
--- /dev/null
+++ b/pool/shard000/C/0008538_10903.c
@@ -0,0 +1,82 @@
+// [ACM] #10903 - Rock-Paper-Scissors Tournament
+// Problem Status CPU Date&Time(UTC) ID Best CPU
+// 10903 Accepted 1.203 2006-11-07 11:24:36 5114450 0.148
+
+#include
+
+int main(void)
+{
+ int n, k, v , u, i = 0, pw[100], pl[100];
+ float w;
+ char vt[9], ut[9];
+ char type[3] = {'s', 'p', 'r'};
+
+ while(scanf("%d %d" , &n, &k) == 2)
+ {
+ if(i != 0)
+ printf("\n");
+ for(i = 0; i < 100; i ++)
+ {
+ pw[i] = 0;
+ pl[i] = 0;
+ }
+ for(i = 0; i < k * n * (n - 1) / 2 ;i ++)
+ {
+ scanf("%d %s %d %s" , &v, vt, &u, ut);
+ if(vt[0] == type[0] && ut[0] == type[0]);
+ else if(vt[0] == type[1] && ut[0] == type[1]);
+ else if(vt[0] == type[2] && ut[0] == type[2]);
+ else if(vt[0] == type[0])
+ {
+ if(ut[0] == type[1])
+ {
+ pw[v - 1] ++;
+ pl[u - 1] ++;
+ }
+ else
+ {
+ pw[u - 1] ++;
+ pl[v - 1] ++;
+ }
+ }
+ else if(vt[0] == type[1])
+ {
+ if(ut[0] == type[0])
+ {
+ pw[u - 1] ++;
+ pl[v - 1] ++;
+ }
+ else
+ {
+ pw[v - 1] ++;
+ pl[u - 1] ++;
+ }
+ }
+ else
+ {
+ if(ut[0] == type[0])
+ {
+ pw[v - 1] ++;
+ pl[u - 1] ++;
+ }
+ else
+ {
+ pw[u - 1] ++;
+ pl[v - 1] ++;
+ }
+ }
+ }
+ for(i = 0; i < n; i ++)
+ {
+ w = pw[i] + pl[i];
+ if(w == 0)
+ printf("-\n");
+ else
+ {
+ w = pw[i] / w;
+ printf("%.3f\n" , w);
+ }
+ }
+ }
+ return 0;
+}
diff --git a/pool/shard000/C/0008544_windir.c b/pool/shard000/C/0008544_windir.c
new file mode 100644
index 0000000000000000000000000000000000000000..23ce8c221e411c9a6fe0884837c353b2cb82f168
--- /dev/null
+++ b/pool/shard000/C/0008544_windir.c
@@ -0,0 +1,80 @@
+/***********************************************************************/
+/* */
+/* Objective Caml */
+/* */
+/* Pascal Cuoq and Xavier Leroy, projet Cristal, INRIA Rocquencourt */
+/* */
+/* Copyright 1996 Institut National de Recherche en Informatique et */
+/* en Automatique. All rights reserved. This file is distributed */
+/* under the terms of the GNU Library General Public License, with */
+/* the special exception on linking described in file ../../LICENSE. */
+/* */
+/***********************************************************************/
+
+/* $Id: windir.c 5029 2002-07-23 14:12:03Z doligez $ */
+
+#include
+#include
+#include
+#include
+#include
+#include "unixsupport.h"
+
+CAMLprim value win_findfirst(name)
+ value name;
+{
+ HANDLE h;
+ value v;
+ WIN32_FIND_DATA fileinfo;
+ value valname = Val_unit;
+ value valh = Val_unit;
+
+ Begin_roots2 (valname,valh);
+ h = FindFirstFile(String_val(name),&fileinfo);
+ if (h == INVALID_HANDLE_VALUE) {
+ DWORD err = GetLastError();
+ if (err == ERROR_NO_MORE_FILES)
+ raise_end_of_file();
+ else {
+ win32_maperr(err);
+ uerror("opendir", Nothing);
+ }
+ }
+ valname = copy_string(fileinfo.cFileName);
+ valh = win_alloc_handle(h);
+ v = alloc_small(2, 0);
+ Field(v,0) = valname;
+ Field(v,1) = valh;
+ End_roots();
+ return v;
+}
+
+CAMLprim value win_findnext(valh)
+ value valh;
+{
+ WIN32_FIND_DATA fileinfo;
+ BOOL retcode;
+
+ retcode = FindNextFile(Handle_val(valh), &fileinfo);
+ if (!retcode) {
+ DWORD err = GetLastError();
+ if (err == ERROR_NO_MORE_FILES)
+ raise_end_of_file();
+ else {
+ win32_maperr(err);
+ uerror("readdir", Nothing);
+ }
+ }
+ return copy_string(fileinfo.cFileName);
+}
+
+CAMLprim value win_findclose(valh)
+ value valh;
+{
+ if (! FindClose(Handle_val(valh))) {
+ win32_maperr(GetLastError());
+ uerror("closedir", Nothing);
+ }
+ return Val_unit;
+}
+
diff --git a/pool/shard000/C/0008546_psychic.c b/pool/shard000/C/0008546_psychic.c
new file mode 100644
index 0000000000000000000000000000000000000000..a12215bb0dccd9a0f44705accec0c02b1405981f
--- /dev/null
+++ b/pool/shard000/C/0008546_psychic.c
@@ -0,0 +1,182 @@
+
+
+#include "internal.h"
+
+#include "account.h"
+#include "blist.h"
+#include "conversation.h"
+#include "debug.h"
+#include "signals.h"
+#include "status.h"
+#include "version.h"
+#include "privacy.h"
+
+#include "plugin.h"
+#include "pluginpref.h"
+#include "prefs.h"
+
+
+#define PLUGIN_ID "core-psychic"
+#define PLUGIN_NAME N_("Psychic Mode")
+#define PLUGIN_SUMMARY N_("Psychic mode for incoming conversation")
+#define PLUGIN_DESC N_("Causes conversation windows to appear as other" \
+ " users begin to message you. This works for" \
+ " AIM, ICQ, XMPP, Sametime, and Yahoo!")
+#define PLUGIN_AUTHOR "Christopher O'Brien "
+
+
+#define PREFS_BASE "/plugins/core/psychic"
+#define PREF_BUDDIES PREFS_BASE "/buddies_only"
+#define PREF_NOTICE PREFS_BASE "/show_notice"
+#define PREF_STATUS PREFS_BASE "/activate_online"
+#define PREF_RAISE PREFS_BASE "/raise_conv"
+
+
+static void
+buddy_typing_cb(PurpleAccount *acct, const char *name, void *data) {
+ PurpleConversation *gconv;
+
+ if(purple_prefs_get_bool(PREF_STATUS) &&
+ ! purple_status_is_available(purple_account_get_active_status(acct))) {
+ purple_debug_info("psychic", "not available, doing nothing\n");
+ return;
+ }
+
+ if(purple_prefs_get_bool(PREF_BUDDIES) &&
+ ! purple_find_buddy(acct, name)) {
+ purple_debug_info("psychic", "not in blist, doing nothing\n");
+ return;
+ }
+
+ if(FALSE == purple_privacy_check(acct, name)) {
+ purple_debug_info("psychic", "user %s is blocked\n", name);
+ return;
+ }
+
+ gconv = purple_find_conversation_with_account(PURPLE_CONV_TYPE_IM, name, acct);
+ if(! gconv) {
+ purple_debug_info("psychic", "no previous conversation exists\n");
+ gconv = purple_conversation_new(PURPLE_CONV_TYPE_IM, acct, name);
+
+ if(purple_prefs_get_bool(PREF_RAISE)) {
+ purple_conversation_present(gconv);
+ }
+
+ if(purple_prefs_get_bool(PREF_NOTICE)) {
+
+ /* This is a quote from Star Wars. You should probably not
+ translate it literally. If you can't find a fitting cultural
+ reference in your language, consider translating something
+ like this instead: "You feel a new message coming." */
+ purple_conversation_write(gconv, NULL,
+ _("You feel a disturbance in the force..."),
+ PURPLE_MESSAGE_SYSTEM | PURPLE_MESSAGE_NO_LOG | PURPLE_MESSAGE_ACTIVE_ONLY,
+ time(NULL));
+ }
+
+ purple_conv_im_set_typing_state(PURPLE_CONV_IM(gconv), PURPLE_TYPING);
+ }
+}
+
+
+static PurplePluginPrefFrame *
+get_plugin_pref_frame(PurplePlugin *plugin) {
+
+ PurplePluginPrefFrame *frame;
+ PurplePluginPref *pref;
+
+ frame = purple_plugin_pref_frame_new();
+
+ pref = purple_plugin_pref_new_with_name(PREF_BUDDIES);
+ purple_plugin_pref_set_label(pref, _("Only enable for users on"
+ " the buddy list"));
+ purple_plugin_pref_frame_add(frame, pref);
+
+ pref = purple_plugin_pref_new_with_name(PREF_STATUS);
+ purple_plugin_pref_set_label(pref, _("Disable when away"));
+ purple_plugin_pref_frame_add(frame, pref);
+
+ pref = purple_plugin_pref_new_with_name(PREF_NOTICE);
+ purple_plugin_pref_set_label(pref, _("Display notification message in"
+ " conversations"));
+ purple_plugin_pref_frame_add(frame, pref);
+
+ pref = purple_plugin_pref_new_with_name(PREF_RAISE);
+ purple_plugin_pref_set_label(pref, _("Raise psychic conversations"));
+ purple_plugin_pref_frame_add(frame, pref);
+
+ return frame;
+}
+
+
+static gboolean
+plugin_load(PurplePlugin *plugin) {
+
+ void *convs_handle;
+ convs_handle = purple_conversations_get_handle();
+
+ purple_signal_connect(convs_handle, "buddy-typing", plugin,
+ PURPLE_CALLBACK(buddy_typing_cb), NULL);
+
+ return TRUE;
+}
+
+
+static PurplePluginUiInfo prefs_info = {
+ get_plugin_pref_frame,
+ 0, /* page_num (Reserved) */
+ NULL, /* frame (Reserved) */
+
+ /* padding */
+ NULL,
+ NULL,
+ NULL,
+ NULL
+};
+
+
+static PurplePluginInfo info = {
+ PURPLE_PLUGIN_MAGIC,
+ PURPLE_MAJOR_VERSION,
+ PURPLE_MINOR_VERSION,
+ PURPLE_PLUGIN_STANDARD, /**< type */
+ NULL, /**< ui_requirement */
+ 0, /**< flags */
+ NULL, /**< dependencies */
+ PURPLE_PRIORITY_DEFAULT, /**< priority */
+
+ PLUGIN_ID, /**< id */
+ PLUGIN_NAME, /**< name */
+ DISPLAY_VERSION, /**< version */
+ PLUGIN_SUMMARY, /**< summary */
+ PLUGIN_DESC, /**< description */
+ PLUGIN_AUTHOR, /**< author */
+ PURPLE_WEBSITE, /**< homepage */
+
+ plugin_load, /**< load */
+ NULL, /**< unload */
+ NULL, /**< destroy */
+
+ NULL, /**< ui_info */
+ NULL, /**< extra_info */
+ &prefs_info, /**< prefs_info */
+ NULL, /**< actions */
+
+ /* padding */
+ NULL,
+ NULL,
+ NULL,
+ NULL
+};
+
+
+static void
+init_plugin(PurplePlugin *plugin) {
+ purple_prefs_add_none(PREFS_BASE);
+ purple_prefs_add_bool(PREF_BUDDIES, FALSE);
+ purple_prefs_add_bool(PREF_NOTICE, TRUE);
+ purple_prefs_add_bool(PREF_STATUS, TRUE);
+}
+
+
+PURPLE_INIT_PLUGIN(psychic, init_plugin, info)
diff --git a/pool/shard000/C/0008549_wolfevent.c b/pool/shard000/C/0008549_wolfevent.c
new file mode 100644
index 0000000000000000000000000000000000000000..20848cddcdf56e3ccc47287b88940a67d73b993d
--- /dev/null
+++ b/pool/shard000/C/0008549_wolfevent.c
@@ -0,0 +1,283 @@
+/* wolfevent.c
+ *
+ * Copyright (C) 2006-2020 wolfSSL Inc.
+ *
+ * This file is part of wolfSSL.
+ *
+ * wolfSSL 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.
+ *
+ * wolfSSL is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335, USA
+ */
+
+#ifdef HAVE_CONFIG_H
+ #include
+#endif
+
+#include
+
+
+#ifdef HAVE_WOLF_EVENT
+
+#include
+#include
+#include
+
+#include
+
+
+int wolfEvent_Init(WOLF_EVENT* event, WOLF_EVENT_TYPE type, void* context)
+{
+ if (event == NULL) {
+ return BAD_FUNC_ARG;
+ }
+
+ if (event->state == WOLF_EVENT_STATE_PENDING) {
+ WOLFSSL_MSG("Event already pending!");
+ return BAD_COND_E;
+ }
+
+ XMEMSET(event, 0, sizeof(WOLF_EVENT));
+ event->type = type;
+ event->context = context;
+
+ return 0;
+}
+
+int wolfEvent_Poll(WOLF_EVENT* event, WOLF_EVENT_FLAG flags)
+{
+ int ret = BAD_COND_E;
+
+ /* Check hardware */
+#ifdef WOLFSSL_ASYNC_CRYPT
+ if (event->type >= WOLF_EVENT_TYPE_ASYNC_FIRST &&
+ event->type <= WOLF_EVENT_TYPE_ASYNC_LAST)
+ {
+ ret = wolfAsync_EventPoll(event, flags);
+ }
+#endif /* WOLFSSL_ASYNC_CRYPT */
+
+ return ret;
+}
+
+int wolfEventQueue_Init(WOLF_EVENT_QUEUE* queue)
+{
+ int ret = 0;
+
+ if (queue == NULL) {
+ return BAD_FUNC_ARG;
+ }
+
+ XMEMSET(queue, 0, sizeof(WOLF_EVENT_QUEUE));
+#ifndef SINGLE_THREADED
+ ret = wc_InitMutex(&queue->lock);
+#endif
+ return ret;
+}
+
+
+int wolfEventQueue_Push(WOLF_EVENT_QUEUE* queue, WOLF_EVENT* event)
+{
+ int ret;
+
+ if (queue == NULL || event == NULL) {
+ return BAD_FUNC_ARG;
+ }
+
+#ifndef SINGLE_THREADED
+ if ((ret = wc_LockMutex(&queue->lock)) != 0) {
+ return ret;
+ }
+#endif
+
+ ret = wolfEventQueue_Add(queue, event);
+
+#ifndef SINGLE_THREADED
+ wc_UnLockMutex(&queue->lock);
+#endif
+
+ return ret;
+}
+
+int wolfEventQueue_Pop(WOLF_EVENT_QUEUE* queue, WOLF_EVENT** event)
+{
+ int ret = 0;
+
+ if (queue == NULL || event == NULL) {
+ return BAD_FUNC_ARG;
+ }
+
+#ifndef SINGLE_THREADED
+ /* In single threaded mode "event_queue.lock" doesn't exist */
+ if ((ret = wc_LockMutex(&queue->lock)) != 0) {
+ return ret;
+ }
+#endif
+
+ /* Pop first item off queue */
+ *event = queue->head;
+ ret = wolfEventQueue_Remove(queue, *event);
+
+#ifndef SINGLE_THREADED
+ wc_UnLockMutex(&queue->lock);
+#endif
+
+ return ret;
+}
+
+/* assumes queue is locked by caller */
+int wolfEventQueue_Add(WOLF_EVENT_QUEUE* queue, WOLF_EVENT* event)
+{
+ if (queue == NULL || event == NULL) {
+ return BAD_FUNC_ARG;
+ }
+
+ event->next = NULL; /* added to end */
+ event->prev = NULL;
+ if (queue->tail == NULL) {
+ queue->head = event;
+ }
+ else {
+ queue->tail->next = event;
+ event->prev = queue->tail;
+ }
+ queue->tail = event; /* add to the end either way */
+ queue->count++;
+
+ return 0;
+}
+
+/* assumes queue is locked by caller */
+int wolfEventQueue_Remove(WOLF_EVENT_QUEUE* queue, WOLF_EVENT* event)
+{
+ int ret = 0;
+
+ if (queue == NULL || event == NULL) {
+ return BAD_FUNC_ARG;
+ }
+
+ if (event == queue->head && event == queue->tail) {
+ queue->head = NULL;
+ queue->tail = NULL;
+ }
+ else if (event == queue->head) {
+ queue->head = event->next;
+ queue->head->prev = NULL;
+ }
+ else if (event == queue->tail) {
+ queue->tail = event->prev;
+ queue->tail->next = NULL;
+ }
+ else {
+ WOLF_EVENT* next = event->next;
+ WOLF_EVENT* prev = event->prev;
+ next->prev = prev;
+ prev->next = next;
+ }
+ queue->count--;
+
+ return ret;
+}
+
+int wolfEventQueue_Poll(WOLF_EVENT_QUEUE* queue, void* context_filter,
+ WOLF_EVENT** events, int maxEvents, WOLF_EVENT_FLAG flags, int* eventCount)
+{
+ WOLF_EVENT* event;
+ int ret = 0, count = 0;
+
+ if (queue == NULL) {
+ return BAD_FUNC_ARG;
+ }
+
+#ifndef SINGLE_THREADED
+ /* In single threaded mode "event_queue.lock" doesn't exist */
+ if ((ret = wc_LockMutex(&queue->lock)) != 0) {
+ return ret;
+ }
+#endif
+
+ /* itterate event queue */
+ for (event = queue->head; event != NULL; event = event->next)
+ {
+ /* optional filter based on context */
+ if (context_filter == NULL || event->context == context_filter) {
+
+ /* poll event */
+ ret = wolfEvent_Poll(event, flags);
+ if (ret < 0) break; /* exit for */
+
+ /* If event is done then process */
+ if (event->state == WOLF_EVENT_STATE_DONE) {
+ /* remove from queue */
+ ret = wolfEventQueue_Remove(queue, event);
+ if (ret < 0) break; /* exit for */
+
+ /* return pointer in 'events' arg */
+ if (events) {
+ events[count] = event; /* return pointer */
+ }
+ count++;
+
+ /* check to make sure our event list isn't full */
+ if (events && count >= maxEvents) {
+ break; /* exit for */
+ }
+ }
+ }
+ }
+
+#ifndef SINGLE_THREADED
+ wc_UnLockMutex(&queue->lock);
+#endif
+
+ /* return number of properly populated events */
+ if (eventCount) {
+ *eventCount = count;
+ }
+
+ return ret;
+}
+
+int wolfEventQueue_Count(WOLF_EVENT_QUEUE* queue)
+{
+ int ret;
+
+ if (queue == NULL) {
+ return BAD_FUNC_ARG;
+ }
+
+#ifndef SINGLE_THREADED
+ /* In single threaded mode "event_queue.lock" doesn't exist */
+ if ((ret = wc_LockMutex(&queue->lock)) != 0) {
+ return ret;
+ }
+#endif
+
+ ret = queue->count;
+
+#ifndef SINGLE_THREADED
+ wc_UnLockMutex(&queue->lock);
+#endif
+
+ return ret;
+}
+
+void wolfEventQueue_Free(WOLF_EVENT_QUEUE* queue)
+{
+ if (queue) {
+ #ifndef SINGLE_THREADED
+ wc_FreeMutex(&queue->lock);
+ #endif
+ }
+}
+
+#endif /* HAVE_WOLF_EVENT */
diff --git a/pool/shard000/C/0008555_pkcs11-list.c b/pool/shard000/C/0008555_pkcs11-list.c
new file mode 100644
index 0000000000000000000000000000000000000000..4ef6a7a62dcbdbd00191ed911ee4dba30633f265
--- /dev/null
+++ b/pool/shard000/C/0008555_pkcs11-list.c
@@ -0,0 +1,264 @@
+/*
+ * Copyright (C) 2009, 2015 Internet Systems Consortium, Inc. ("ISC")
+ *
+ * Permission to use, copy, modify, and/or distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND ISC AND NETWORK ASSOCIATES DISCLAIMS
+ * ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE
+ * FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR
+ * IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ */
+
+/*
+ * Portions copyright (c) 2008 Nominet UK. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+/* $Id: pkcs11-list.c,v 1.7 2009/10/26 23:36:53 each Exp $ */
+
+/* pkcs11-list [-P] [-m module] [-s slot] [-i $id | -l $label] [-p $pin] */
+
+/*! \file */
+
+#include
+
+#include
+#include
+#include
+#include
+#include
+#include
+
+#include
+#include
+#include
+#include
+
+#include
+#include
+
+#if !(defined(HAVE_GETPASSPHRASE) || (defined (__SVR4) && defined (__sun)))
+#define getpassphrase(x) getpass(x)
+#endif
+
+int
+main(int argc, char *argv[]) {
+ isc_result_t result;
+ CK_RV rv;
+ CK_SLOT_ID slot = 0;
+ CK_SESSION_HANDLE hSession;
+ CK_BYTE attr_id[2];
+ CK_OBJECT_HANDLE akey[50];
+ pk11_context_t pctx;
+ char *lib_name = NULL;
+ char *label = NULL;
+ char *pin = NULL;
+ isc_boolean_t error = ISC_FALSE, logon = ISC_TRUE, all = ISC_FALSE;
+ unsigned int i = 0, id = 0;
+ int c, errflg = 0;
+ CK_ULONG ulObjectCount;
+ CK_ATTRIBUTE search_template[] = {
+ {CKA_ID, &attr_id, sizeof(attr_id)}
+ };
+
+ while ((c = isc_commandline_parse(argc, argv, ":m:s:i:l:p:P")) != -1) {
+ switch (c) {
+ case 'P':
+ logon = ISC_FALSE;
+ break;
+ case 'm':
+ lib_name = isc_commandline_argument;
+ break;
+ case 's':
+ slot = atoi(isc_commandline_argument);
+ break;
+ case 'i':
+ id = atoi(isc_commandline_argument);
+ id &= 0xffff;
+ break;
+ case 'l':
+ label = isc_commandline_argument;
+ break;
+ case 'p':
+ pin = isc_commandline_argument;
+ break;
+ case ':':
+ fprintf(stderr, "Option -%c requires an operand\n",
+ isc_commandline_option);
+ errflg++;
+ break;
+ case '?':
+ default:
+ fprintf(stderr, "Unrecognised option: -%c\n",
+ isc_commandline_option);
+ errflg++;
+ }
+ }
+
+ if (errflg) {
+ fprintf(stderr, "Usage:\n");
+ fprintf(stderr, "\tpkcs11-list [-P] [-m module] [-s slot] "
+ "[-i id | -l label] [-p pin]\n");
+ exit(1);
+ }
+
+ if (!id && (label == NULL))
+ all = ISC_TRUE;
+
+ if (slot)
+ printf("slot %lu\n", slot);
+
+ if (id) {
+ printf("id %i\n", id);
+ attr_id[0] = (id >> 8) & 0xff;
+ attr_id[1] = id & 0xff;
+ } else if (label != NULL) {
+ printf("label %s\n", label);
+ search_template[0].type = CKA_LABEL;
+ search_template[0].pValue = label;
+ search_template[0].ulValueLen = strlen(label);
+ }
+
+ pk11_result_register();
+
+ /* Initialize the CRYPTOKI library */
+ if (lib_name != NULL)
+ pk11_set_lib_name(lib_name);
+
+ if (logon && pin == NULL)
+ pin = getpassphrase("Enter Pin: ");
+
+ result = pk11_get_session(&pctx, OP_ANY, ISC_FALSE, ISC_FALSE,
+ logon, pin, slot);
+ if (result == PK11_R_NORANDOMSERVICE ||
+ result == PK11_R_NODIGESTSERVICE ||
+ result == PK11_R_NOAESSERVICE) {
+ fprintf(stderr, "Warning: %s\n", isc_result_totext(result));
+ fprintf(stderr, "This HSM will not work with BIND 9 "
+ "using native PKCS#11.\n");
+ } else if (result != ISC_R_SUCCESS) {
+ fprintf(stderr, "Unrecoverable error initializing "
+ "PKCS#11: %s\n", isc_result_totext(result));
+ fprintf(stderr, "Unrecoverable error initializing "
+ "PKCS#11: %s\n", isc_result_totext(result));
+ exit(1);
+ }
+
+ if (pin != NULL)
+ memset(pin, 0, strlen(pin));
+
+ hSession = pctx.session;
+
+ rv = pkcs_C_FindObjectsInit(hSession, search_template, all ? 0 : 1);
+ if (rv != CKR_OK) {
+ fprintf(stderr, "C_FindObjectsInit: Error = 0x%.8lX\n", rv);
+ error = 1;
+ goto exit_session;
+ }
+
+ ulObjectCount = 1;
+ while (ulObjectCount) {
+ rv = pkcs_C_FindObjects(hSession, akey, 50, &ulObjectCount);
+ if (rv != CKR_OK) {
+ fprintf(stderr,
+ "C_FindObjects: Error = 0x%.8lX\n",
+ rv);
+ error = 1;
+ goto exit_search;
+ }
+ for (i = 0; i < ulObjectCount; i++) {
+ unsigned int j, len;
+
+ CK_OBJECT_CLASS oclass = 0;
+ CK_BYTE labelbuf[64 + 1];
+ CK_BYTE idbuf[64];
+ CK_ATTRIBUTE template[] = {
+ {CKA_CLASS, &oclass, sizeof(oclass)},
+ {CKA_LABEL, labelbuf, sizeof(labelbuf) - 1},
+ {CKA_ID, idbuf, sizeof(idbuf)}
+ };
+
+ memset(labelbuf, 0, sizeof(labelbuf));
+ memset(idbuf, 0, sizeof(idbuf));
+
+ rv = pkcs_C_GetAttributeValue(hSession, akey[i],
+ template, 3);
+ if (rv != CKR_OK) {
+ fprintf(stderr,
+ "C_GetAttributeValue[%u]: "
+ "rv = 0x%.8lX\n",
+ i, rv);
+ if (rv == CKR_BUFFER_TOO_SMALL)
+ fprintf(stderr,
+ "%u too small: %lu %lu %lu\n",
+ i,
+ template[0].ulValueLen,
+ template[1].ulValueLen,
+ template[2].ulValueLen);
+ error = 1;
+ continue;
+ }
+
+ len = template[2].ulValueLen;
+ printf("object[%u]: handle %lu class %lu "
+ "label[%lu] '%s' id[%lu] ",
+ i, akey[i], oclass,
+ template[1].ulValueLen,
+ labelbuf,
+ template[2].ulValueLen);
+ if (len == 2) {
+ id = (idbuf[0] << 8) & 0xff00;
+ id |= idbuf[1] & 0xff;
+ printf("%u\n", id);
+ } else {
+ if (len > 8)
+ len = 8;
+ if (len > 0)
+ printf("0x");
+ for (j = 0; j < len; j++)
+ printf("%02x", idbuf[j]);
+ if (template[2].ulValueLen > len)
+ printf("...\n");
+ else
+ printf("\n");
+ }
+ }
+ }
+
+ exit_search:
+ rv = pkcs_C_FindObjectsFinal(hSession);
+ if (rv != CKR_OK) {
+ fprintf(stderr, "C_FindObjectsFinal: Error = 0x%.8lX\n", rv);
+ error = 1;
+ }
+
+ exit_session:
+ pk11_return_session(&pctx);
+ (void) pk11_finalize();
+
+ exit(error);
+}
diff --git a/pool/shard000/C/0008576_aigMffc.c b/pool/shard000/C/0008576_aigMffc.c
new file mode 100644
index 0000000000000000000000000000000000000000..daeed2810d7ee41d70ef798d3064fdab5358924b
--- /dev/null
+++ b/pool/shard000/C/0008576_aigMffc.c
@@ -0,0 +1,297 @@
+/**CFile****************************************************************
+
+ FileName [aigMffc.c]
+
+ SystemName [ABC: Logic synthesis and verification system.]
+
+ PackageName [AIG package.]
+
+ Synopsis [Computation of MFFCs.]
+
+ Author [Alan Mishchenko]
+
+ Affiliation [UC Berkeley]
+
+ Date [Ver. 1.0. Started - April 28, 2007.]
+
+ Revision [$Id: aigMffc.c,v 1.00 2007/04/28 00:00:00 alanmi Exp $]
+
+***********************************************************************/
+
+#include "aig.h"
+
+////////////////////////////////////////////////////////////////////////
+/// DECLARATIONS ///
+////////////////////////////////////////////////////////////////////////
+
+////////////////////////////////////////////////////////////////////////
+/// FUNCTION DEFINITIONS ///
+////////////////////////////////////////////////////////////////////////
+
+/**Function*************************************************************
+
+ Synopsis [Dereferences the node's MFFC.]
+
+ Description []
+
+ SideEffects []
+
+ SeeAlso []
+
+***********************************************************************/
+int Aig_NodeDeref_rec( Aig_Obj_t * pNode, unsigned LevelMin )
+{
+ Aig_Obj_t * pFanin;
+ int Counter = 0;
+ if ( Aig_ObjIsPi(pNode) )
+ return 0;
+ // consider the first fanin
+ pFanin = Aig_ObjFanin0(pNode);
+ assert( pFanin->nRefs > 0 );
+ if ( --pFanin->nRefs == 0 && (!LevelMin || pFanin->Level > LevelMin) )
+ Counter += Aig_NodeDeref_rec( pFanin, LevelMin );
+ // skip the buffer
+ if ( Aig_ObjIsBuf(pNode) )
+ return Counter;
+ assert( Aig_ObjIsNode(pNode) );
+ // consider the second fanin
+ pFanin = Aig_ObjFanin1(pNode);
+ assert( pFanin->nRefs > 0 );
+ if ( --pFanin->nRefs == 0 && (!LevelMin || pFanin->Level > LevelMin) )
+ Counter += Aig_NodeDeref_rec( pFanin, LevelMin );
+ return Counter + 1;
+}
+
+/**Function*************************************************************
+
+ Synopsis [References the node's MFFC.]
+
+ Description []
+
+ SideEffects []
+
+ SeeAlso []
+
+***********************************************************************/
+int Aig_NodeRef_rec( Aig_Obj_t * pNode, unsigned LevelMin )
+{
+ Aig_Obj_t * pFanin;
+ int Counter = 0;
+ if ( Aig_ObjIsPi(pNode) )
+ return 0;
+ // consider the first fanin
+ pFanin = Aig_ObjFanin0(pNode);
+ if ( pFanin->nRefs++ == 0 && (!LevelMin || pFanin->Level > LevelMin) )
+ Counter += Aig_NodeRef_rec( pFanin, LevelMin );
+ // skip the buffer
+ if ( Aig_ObjIsBuf(pNode) )
+ return Counter;
+ assert( Aig_ObjIsNode(pNode) );
+ // consider the second fanin
+ pFanin = Aig_ObjFanin1(pNode);
+ if ( pFanin->nRefs++ == 0 && (!LevelMin || pFanin->Level > LevelMin) )
+ Counter += Aig_NodeRef_rec( pFanin, LevelMin );
+ return Counter + 1;
+}
+
+/**Function*************************************************************
+
+ Synopsis [References the node's MFFC.]
+
+ Description []
+
+ SideEffects []
+
+ SeeAlso []
+
+***********************************************************************/
+int Aig_NodeRefLabel_rec( Aig_Man_t * p, Aig_Obj_t * pNode, unsigned LevelMin )
+{
+ Aig_Obj_t * pFanin;
+ int Counter = 0;
+ if ( Aig_ObjIsPi(pNode) )
+ return 0;
+ Aig_ObjSetTravIdCurrent( p, pNode );
+ // consider the first fanin
+ pFanin = Aig_ObjFanin0(pNode);
+ if ( pFanin->nRefs++ == 0 && (!LevelMin || pFanin->Level > LevelMin) )
+ Counter += Aig_NodeRefLabel_rec( p, pFanin, LevelMin );
+ if ( Aig_ObjIsBuf(pNode) )
+ return Counter;
+ assert( Aig_ObjIsNode(pNode) );
+ // consider the second fanin
+ pFanin = Aig_ObjFanin1(pNode);
+ if ( pFanin->nRefs++ == 0 && (!LevelMin || pFanin->Level > LevelMin) )
+ Counter += Aig_NodeRefLabel_rec( p, pFanin, LevelMin );
+ return Counter + 1;
+}
+
+/**Function*************************************************************
+
+ Synopsis [Collects the internal and boundary nodes in the derefed MFFC.]
+
+ Description []
+
+ SideEffects []
+
+ SeeAlso []
+
+***********************************************************************/
+void Aig_NodeMffsSupp_rec( Aig_Man_t * p, Aig_Obj_t * pNode, unsigned LevelMin, Vec_Ptr_t * vSupp, int fTopmost, Aig_Obj_t * pObjSkip )
+{
+ // skip visited nodes
+ if ( Aig_ObjIsTravIdCurrent(p, pNode) )
+ return;
+ Aig_ObjSetTravIdCurrent(p, pNode);
+ // add to the new support nodes
+ if ( !fTopmost && pNode != pObjSkip && (Aig_ObjIsPi(pNode) || pNode->nRefs > 0 || pNode->Level <= LevelMin) )
+ {
+ if ( vSupp ) Vec_PtrPush( vSupp, pNode );
+ return;
+ }
+ assert( Aig_ObjIsNode(pNode) );
+ // recur on the children
+ Aig_NodeMffsSupp_rec( p, Aig_ObjFanin0(pNode), LevelMin, vSupp, 0, pObjSkip );
+ Aig_NodeMffsSupp_rec( p, Aig_ObjFanin1(pNode), LevelMin, vSupp, 0, pObjSkip );
+}
+
+/**Function*************************************************************
+
+ Synopsis [Collects the support of depth-limited MFFC.]
+
+ Description [Returns the number of internal nodes in the MFFC.]
+
+ SideEffects []
+
+ SeeAlso []
+
+***********************************************************************/
+int Aig_NodeMffsSupp( Aig_Man_t * p, Aig_Obj_t * pNode, int LevelMin, Vec_Ptr_t * vSupp )
+{
+ int ConeSize1, ConeSize2;
+ assert( !Aig_IsComplement(pNode) );
+ assert( Aig_ObjIsNode(pNode) );
+ if ( vSupp ) Vec_PtrClear( vSupp );
+ Aig_ManIncrementTravId( p );
+ ConeSize1 = Aig_NodeDeref_rec( pNode, LevelMin );
+ Aig_NodeMffsSupp_rec( p, pNode, LevelMin, vSupp, 1, NULL );
+ ConeSize2 = Aig_NodeRef_rec( pNode, LevelMin );
+ assert( ConeSize1 == ConeSize2 );
+ assert( ConeSize1 > 0 );
+ return ConeSize1;
+}
+
+/**Function*************************************************************
+
+ Synopsis [Labels the nodes in the MFFC.]
+
+ Description [Returns the number of internal nodes in the MFFC.]
+
+ SideEffects []
+
+ SeeAlso []
+
+***********************************************************************/
+int Aig_NodeMffsLabel( Aig_Man_t * p, Aig_Obj_t * pNode )
+{
+ int ConeSize1, ConeSize2;
+ assert( !Aig_IsComplement(pNode) );
+ assert( Aig_ObjIsNode(pNode) );
+ Aig_ManIncrementTravId( p );
+ ConeSize1 = Aig_NodeDeref_rec( pNode, 0 );
+ ConeSize2 = Aig_NodeRefLabel_rec( p, pNode, 0 );
+ assert( ConeSize1 == ConeSize2 );
+ assert( ConeSize1 > 0 );
+ return ConeSize1;
+}
+
+/**Function*************************************************************
+
+ Synopsis [Labels the nodes in the MFFC.]
+
+ Description [Returns the number of internal nodes in the MFFC.]
+
+ SideEffects []
+
+ SeeAlso []
+
+***********************************************************************/
+int Aig_NodeMffsLabelCut( Aig_Man_t * p, Aig_Obj_t * pNode, Vec_Ptr_t * vLeaves )
+{
+ Aig_Obj_t * pObj;
+ int i, ConeSize1, ConeSize2;
+ assert( !Aig_IsComplement(pNode) );
+ assert( Aig_ObjIsNode(pNode) );
+ Aig_ManIncrementTravId( p );
+ Vec_PtrForEachEntry( vLeaves, pObj, i )
+ pObj->nRefs++;
+ ConeSize1 = Aig_NodeDeref_rec( pNode, 0 );
+ ConeSize2 = Aig_NodeRefLabel_rec( p, pNode, 0 );
+ Vec_PtrForEachEntry( vLeaves, pObj, i )
+ pObj->nRefs--;
+ assert( ConeSize1 == ConeSize2 );
+ assert( ConeSize1 > 0 );
+ return ConeSize1;
+}
+
+/**Function*************************************************************
+
+ Synopsis [Expands the cut by adding the most closely related node.]
+
+ Description [Returns 1 if the cut exists.]
+
+ SideEffects []
+
+ SeeAlso []
+
+***********************************************************************/
+int Aig_NodeMffsExtendCut( Aig_Man_t * p, Aig_Obj_t * pNode, Vec_Ptr_t * vLeaves, Vec_Ptr_t * vResult )
+{
+ Aig_Obj_t * pObj, * pLeafBest;
+ int i, LevelMax, ConeSize1, ConeSize2, ConeCur1, ConeCur2, ConeBest;
+ // dereference the current cut
+ LevelMax = 0;
+ Vec_PtrForEachEntry( vLeaves, pObj, i )
+ LevelMax = AIG_MAX( LevelMax, (int)pObj->Level );
+ if ( LevelMax == 0 )
+ return 0;
+ // dereference the cut
+ ConeSize1 = Aig_NodeDeref_rec( pNode, 0 );
+ // try expanding each node in the boundary
+ ConeBest = AIG_INFINITY;
+ pLeafBest = NULL;
+ Vec_PtrForEachEntry( vLeaves, pObj, i )
+ {
+ if ( (int)pObj->Level != LevelMax )
+ continue;
+ ConeCur1 = Aig_NodeDeref_rec( pObj, 0 );
+ if ( ConeBest > ConeCur1 )
+ {
+ ConeBest = ConeCur1;
+ pLeafBest = pObj;
+ }
+ ConeCur2 = Aig_NodeRef_rec( pObj, 0 );
+ assert( ConeCur1 == ConeCur2 );
+ }
+ assert( pLeafBest != NULL );
+ assert( Aig_ObjIsNode(pLeafBest) );
+ // deref the best leaf
+ ConeCur1 = Aig_NodeDeref_rec( pLeafBest, 0 );
+ // collect the cut nodes
+ Vec_PtrClear( vResult );
+ Aig_ManIncrementTravId( p );
+ Aig_NodeMffsSupp_rec( p, pNode, 0, vResult, 1, pLeafBest );
+ // ref the nodes
+ ConeCur2 = Aig_NodeRef_rec( pLeafBest, 0 );
+ assert( ConeCur1 == ConeCur2 );
+ // ref the original node
+ ConeSize2 = Aig_NodeRef_rec( pNode, 0 );
+ assert( ConeSize1 == ConeSize2 );
+ return 1;
+}
+
+////////////////////////////////////////////////////////////////////////
+/// END OF FILE ///
+////////////////////////////////////////////////////////////////////////
+
+
diff --git a/pool/shard000/C/0008609_logging.c b/pool/shard000/C/0008609_logging.c
new file mode 100644
index 0000000000000000000000000000000000000000..7c09777448a0f70291e1f76d59ebe6a3b152a2bb
--- /dev/null
+++ b/pool/shard000/C/0008609_logging.c
@@ -0,0 +1,211 @@
+/*
+ Copyright (C) 2010 ABRT team
+ Copyright (C) 2010, 2014 RedHat Inc
+
+ 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.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along
+ with this program; if not, write to the Free Software Foundation, Inc.,
+ 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+*/
+#include
+/* Suppress automatic CODE_* fields as we handle those here */
+#define SD_JOURNAL_SUPPRESS_LOCATION
+#include
+#include "internal_libreport.h"
+
+void (*libreport_g_custom_logger)(const char*);
+const char *libreport_msg_prefix = "";
+const char *libreport_msg_eol = "\n";
+int libreport_logmode = LOGMODE_STDIO;
+int libreport_xfunc_error_retval = EXIT_FAILURE;
+static enum libreport_diemode xfunc_diemode = DIEMODE_EXIT;
+int libreport_g_verbose;
+
+void libreport_set_xfunc_error_retval(int retval)
+{
+ libreport_xfunc_error_retval = retval;
+}
+
+void libreport_set_xfunc_diemode(enum libreport_diemode mode)
+{
+ xfunc_diemode = mode;
+}
+
+/* [p]error_msg[_and_die] must be safe after fork in multi-threaded programs.
+ * Therefore we avoid stdio, fflush(), and use _exit() instead of exit().
+ *
+ */
+void libreport_xfunc_die(void)
+{
+ char *const envmode = getenv("LIBREPORT_DIEMODE");
+ if ( xfunc_diemode == DIEMODE_ABORT
+ || (envmode != NULL && strcmp("abort", envmode) == 0))
+ abort();
+
+ _exit(libreport_xfunc_error_retval);
+}
+
+static bool should_log(int level)
+{
+ // LOG_DEBUG = 7, LOG_INFO = 6, LOG_NOTICE = 5, LOG_WARNING = 4, LOG_ERR = 3
+ // output only messages with LOG_ERR by default, overridden by libreport_g_verbose
+ if(
+ (libreport_g_verbose == 0 && level <= LOG_WARNING) ||
+ (libreport_g_verbose == 1 && level <= LOG_NOTICE) ||
+ (libreport_g_verbose == 2 && level <= LOG_INFO) ||
+ (libreport_g_verbose == 3)
+ )
+ return true;
+
+ return false;
+}
+
+
+static void log_handler(int level,
+ const char *format,
+ va_list p,
+ const char *strerr, /* perror messages */
+ int flags,
+ const char *file,
+ int line,
+ const char *func)
+{
+ if (!libreport_logmode || !should_log(level))
+ return;
+
+ /* This is ugly and costs +60 bytes compared to multiple
+ * fprintf's, but is guaranteed to do a single write.
+ * This is needed for e.g. when multiple children
+ * can produce log messages simultaneously. */
+
+ int prefix_len = libreport_msg_prefix[0] ? strlen(libreport_msg_prefix) + 2 : 0;
+ int strerr_len = strerr ? strlen(strerr) : 0;
+ int msgeol_len = strlen(libreport_msg_eol);
+ int used;
+
+ /* Try to format the message in a fixed buffer.
+ * This eliminates malloc.
+ * Main reason isn't the speed optimization, but to make
+ * short logging safe after fork in multithreaded libraries.
+ */
+ char buf[1024];
+ va_list p2;
+ va_copy(p2, p);
+ if (prefix_len < sizeof(buf))
+ used = vsnprintf(buf + prefix_len, sizeof(buf) - prefix_len, format, p2);
+ else
+ used = vsnprintf(buf, 0, format, p2);
+ va_end(p2);
+
+ char *msg = buf;
+
+ /* +3 is for ": " before strerr and for terminating NUL */
+ unsigned total_len = prefix_len + used + strerr_len + msgeol_len + 3;
+
+ if (total_len >= sizeof(buf))
+ {
+ msg = alloca(total_len);
+ used = vsnprintf(msg + prefix_len, total_len - prefix_len, format, p);
+ }
+
+ if (prefix_len) {
+ char *p;
+ used += prefix_len;
+ p = stpcpy(msg, libreport_msg_prefix);
+ p[0] = ':';
+ p[1] = ' ';
+ }
+ if (strerr) {
+ if (format[0]) {
+ msg[used++] = ':';
+ msg[used++] = ' ';
+ }
+ strcpy(&msg[used], strerr);
+ used += strerr_len;
+ }
+ strcpy(&msg[used], libreport_msg_eol);
+
+ if (flags & LOGMODE_STDIO) {
+ libreport_full_write(STDERR_FILENO, msg, used + msgeol_len);
+ }
+ msg[used] = '\0'; /* remove libreport_msg_eol (usually "\n") */
+ if (flags & LOGMODE_SYSLOG) {
+ syslog(level, "%s", msg + prefix_len);
+ }
+
+ if ((flags & LOGMODE_CUSTOM) && libreport_g_custom_logger) {
+ libreport_g_custom_logger(msg + prefix_len);
+ }
+
+ if (flags & LOGMODE_JOURNAL) {
+ sd_journal_send("MESSAGE=%s", msg + prefix_len,
+ "PRIORITY=%d", level,
+ "CODE_FILE=%s", file,
+ "CODE_LINE=%d", line,
+ "CODE_FUNC=%s", func,
+ "SYSLOG_FACILITY=1",
+ NULL);
+ }
+}
+
+void log_wrapper(int level,
+ const char *file,
+ int line,
+ const char *func,
+ bool process_perror,
+ bool use_custom_logger,
+ const char *format,
+ ...)
+{
+ va_list p;
+
+ va_start(p, format);
+ log_handler(level,
+ format,
+ p,
+ (process_perror && errno) ? strerror(errno) : NULL, /* Guard against ": Success" */
+ libreport_logmode | (use_custom_logger ? LOGMODE_CUSTOM : 0),
+ file,
+ line,
+ func);
+ va_end(p);
+}
+
+void log_and_die_wrapper(int level,
+ const char *file,
+ int line,
+ const char *func,
+ bool process_perror,
+ bool use_custom_logger,
+ const char *format,
+ ...)
+{
+ va_list p;
+
+ va_start(p, format);
+ log_handler(level,
+ format,
+ p,
+ (process_perror && errno) ? strerror(errno) : NULL, /* Guard against ": Success" */
+ libreport_logmode | (use_custom_logger ? LOGMODE_CUSTOM : 0),
+ file,
+ line,
+ func);
+ va_end(p);
+ libreport_xfunc_die();
+}
+
+
+void libreport_die_out_of_memory(void)
+{
+ error_msg_and_die("Out of memory, exiting");
+}
diff --git a/pool/shard000/C/0008613_test-prioq.c b/pool/shard000/C/0008613_test-prioq.c
new file mode 100644
index 0000000000000000000000000000000000000000..1e2e42cbca1713440533d8faf51393895db5bbfb
--- /dev/null
+++ b/pool/shard000/C/0008613_test-prioq.c
@@ -0,0 +1,172 @@
+/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
+
+/***
+ This file is part of systemd.
+
+ Copyright 2013 Lennart Poettering
+
+ systemd is free software; you can redistribute it and/or modify it
+ under the terms of the GNU Lesser General Public License as published by
+ the Free Software Foundation; either version 2.1 of the License, or
+ (at your option) any later version.
+
+ systemd is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public License
+ along with systemd; If not, see .
+***/
+
+#include
+
+#include "util.h"
+#include "set.h"
+#include "prioq.h"
+#include "siphash24.h"
+
+#define SET_SIZE 1024*4
+
+static int unsigned_compare(const void *a, const void *b) {
+ const unsigned *x = a, *y = b;
+
+ if (*x < *y)
+ return -1;
+
+ if (*x > *y)
+ return 1;
+
+ return 0;
+}
+
+static void test_unsigned(void) {
+ unsigned buffer[SET_SIZE], i;
+ Prioq *q;
+
+ srand(0);
+
+ q = prioq_new(trivial_compare_func);
+ assert_se(q);
+
+ for (i = 0; i < ELEMENTSOF(buffer); i++) {
+ unsigned u;
+
+ u = (unsigned) rand();
+ buffer[i] = u;
+ assert_se(prioq_put(q, UINT_TO_PTR(u), NULL) >= 0);
+ }
+
+ qsort(buffer, ELEMENTSOF(buffer), sizeof(buffer[0]), unsigned_compare);
+
+ for (i = 0; i < ELEMENTSOF(buffer); i++) {
+ unsigned u;
+
+ assert_se(prioq_size(q) == ELEMENTSOF(buffer) - i);
+
+ u = PTR_TO_UINT(prioq_pop(q));
+ assert_se(buffer[i] == u);
+ }
+
+ assert_se(prioq_isempty(q));
+ prioq_free(q);
+}
+
+struct test {
+ unsigned value;
+ unsigned idx;
+};
+
+static int test_compare(const void *a, const void *b) {
+ const struct test *x = a, *y = b;
+
+ if (x->value < y->value)
+ return -1;
+
+ if (x->value > y->value)
+ return 1;
+
+ return 0;
+}
+
+static void test_hash(const void *a, struct siphash *state) {
+ const struct test *x = a;
+
+ siphash24_compress(&x->value, sizeof(x->value), state);
+}
+
+static const struct hash_ops test_hash_ops = {
+ .hash = test_hash,
+ .compare = test_compare
+};
+
+static void test_struct(void) {
+ Prioq *q;
+ Set *s;
+ unsigned previous = 0, i;
+ int r;
+
+ srand(0);
+
+ q = prioq_new(test_compare);
+ assert_se(q);
+
+ s = set_new(&test_hash_ops);
+ assert_se(s);
+
+ for (i = 0; i < SET_SIZE; i++) {
+ struct test *t;
+
+ t = new0(struct test, 1);
+ assert_se(t);
+ t->value = (unsigned) rand();
+
+ r = prioq_put(q, t, &t->idx);
+ assert_se(r >= 0);
+
+ if (i % 4 == 0) {
+ r = set_consume(s, t);
+ assert_se(r >= 0);
+ }
+ }
+
+ for (;;) {
+ struct test *t;
+
+ t = set_steal_first(s);
+ if (!t)
+ break;
+
+ r = prioq_remove(q, t, &t->idx);
+ assert_se(r > 0);
+
+ free(t);
+ }
+
+ for (i = 0; i < SET_SIZE * 3 / 4; i++) {
+ struct test *t;
+
+ assert_se(prioq_size(q) == (SET_SIZE * 3 / 4) - i);
+
+ t = prioq_pop(q);
+ assert_se(t);
+
+ assert_se(previous <= t->value);
+ previous = t->value;
+ free(t);
+ }
+
+ assert_se(prioq_isempty(q));
+ prioq_free(q);
+
+ assert_se(set_isempty(s));
+ set_free(s);
+}
+
+int main(int argc, char* argv[]) {
+
+ test_unsigned();
+ test_struct();
+
+ return 0;
+}
diff --git a/pool/shard000/C/0008639_lpc17xx_clkpwr.c b/pool/shard000/C/0008639_lpc17xx_clkpwr.c
new file mode 100644
index 0000000000000000000000000000000000000000..944017ef086cd5b37eb52083dd2f4267863d4da5
--- /dev/null
+++ b/pool/shard000/C/0008639_lpc17xx_clkpwr.c
@@ -0,0 +1,327 @@
+/******************************************************************//**
+* @file lpc17xx_clkpwr.c
+* @brief Contains all functions support for Clock and Power Control
+* firmware library on LPC17xx
+* @version 1.0
+* @date 24. July. 2013
+* @author Dwijay.Edutech Learning Solutions
+**********************************************************************/
+
+/* Peripheral group ----------------------------------------------------------- */
+/** @addtogroup CLKPWR
+ * @{
+ */
+
+/* Includes ------------------------------------------------------------------- */
+#include "lpc17xx_clkpwr.h"
+
+
+/* Public Functions ----------------------------------------------------------- */
+/** @addtogroup CLKPWR_Public_Functions
+ * @{
+ */
+
+/*********************************************************************//**
+ * @brief Set value of each Peripheral Clock Selection
+ * @param[in] ClkType Peripheral Clock Selection of each type,
+ * should be one of the following:
+ * - CLKPWR_PCLKSEL_WDT : WDT
+ - CLKPWR_PCLKSEL_TIMER0 : Timer 0
+ - CLKPWR_PCLKSEL_TIMER1 : Timer 1
+ - CLKPWR_PCLKSEL_UART0 : UART 0
+ - CLKPWR_PCLKSEL_UART1 : UART 1
+ - CLKPWR_PCLKSEL_PWM1 : PWM 1
+ - CLKPWR_PCLKSEL_I2C0 : I2C 0
+ - CLKPWR_PCLKSEL_SPI : SPI
+ - CLKPWR_PCLKSEL_SSP1 : SSP 1
+ - CLKPWR_PCLKSEL_DAC : DAC
+ - CLKPWR_PCLKSEL_ADC : ADC
+ - CLKPWR_PCLKSEL_CAN1 : CAN 1
+ - CLKPWR_PCLKSEL_CAN2 : CAN 2
+ - CLKPWR_PCLKSEL_ACF : ACF
+ - CLKPWR_PCLKSEL_QEI : QEI
+ - CLKPWR_PCLKSEL_PCB : PCB
+ - CLKPWR_PCLKSEL_I2C1 : I2C 1
+ - CLKPWR_PCLKSEL_SSP0 : SSP 0
+ - CLKPWR_PCLKSEL_TIMER2 : Timer 2
+ - CLKPWR_PCLKSEL_TIMER3 : Timer 3
+ - CLKPWR_PCLKSEL_UART2 : UART 2
+ - CLKPWR_PCLKSEL_UART3 : UART 3
+ - CLKPWR_PCLKSEL_I2C2 : I2C 2
+ - CLKPWR_PCLKSEL_I2S : I2S
+ - CLKPWR_PCLKSEL_RIT : RIT
+ - CLKPWR_PCLKSEL_SYSCON : SYSCON
+ - CLKPWR_PCLKSEL_MC : MC
+
+ * @param[in] DivVal Value of divider, should be:
+ * - CLKPWR_PCLKSEL_CCLK_DIV_4 : PCLK_peripheral = CCLK/4
+ * - CLKPWR_PCLKSEL_CCLK_DIV_1 : PCLK_peripheral = CCLK/1
+ * - CLKPWR_PCLKSEL_CCLK_DIV_2 : PCLK_peripheral = CCLK/2
+ *
+ * @return none
+ **********************************************************************/
+void CLKPWR_SetPCLKDiv (uint32_t ClkType, uint32_t DivVal)
+{
+ uint32_t bitpos;
+
+ bitpos = (ClkType < 32) ? (ClkType) : (ClkType - 32);
+
+ /* PCLKSEL0 selected */
+ if (ClkType < 32)
+ {
+ /* Clear two bit at bit position */
+ LPC_SC->PCLKSEL0 &= (~(CLKPWR_PCLKSEL_BITMASK(bitpos)));
+
+ /* Set two selected bit */
+ LPC_SC->PCLKSEL0 |= (CLKPWR_PCLKSEL_SET(bitpos, DivVal));
+ }
+ /* PCLKSEL1 selected */
+ else
+ {
+ /* Clear two bit at bit position */
+ LPC_SC->PCLKSEL1 &= ~(CLKPWR_PCLKSEL_BITMASK(bitpos));
+
+ /* Set two selected bit */
+ LPC_SC->PCLKSEL1 |= (CLKPWR_PCLKSEL_SET(bitpos, DivVal));
+ }
+}
+
+
+/*********************************************************************//**
+ * @brief Get current value of each Peripheral Clock Selection
+ * @param[in] ClkType Peripheral Clock Selection of each type,
+ * should be one of the following:
+ * - CLKPWR_PCLKSEL_WDT : WDT
+ - CLKPWR_PCLKSEL_TIMER0 : Timer 0
+ - CLKPWR_PCLKSEL_TIMER1 : Timer 1
+ - CLKPWR_PCLKSEL_UART0 : UART 0
+ - CLKPWR_PCLKSEL_UART1 : UART 1
+ - CLKPWR_PCLKSEL_PWM1 : PWM 1
+ - CLKPWR_PCLKSEL_I2C0 : I2C 0
+ - CLKPWR_PCLKSEL_SPI : SPI
+ - CLKPWR_PCLKSEL_SSP1 : SSP 1
+ - CLKPWR_PCLKSEL_DAC : DAC
+ - CLKPWR_PCLKSEL_ADC : ADC
+ - CLKPWR_PCLKSEL_CAN1 : CAN 1
+ - CLKPWR_PCLKSEL_CAN2 : CAN 2
+ - CLKPWR_PCLKSEL_ACF : ACF
+ - CLKPWR_PCLKSEL_QEI : QEI
+ - CLKPWR_PCLKSEL_PCB : PCB
+ - CLKPWR_PCLKSEL_I2C1 : I2C 1
+ - CLKPWR_PCLKSEL_SSP0 : SSP 0
+ - CLKPWR_PCLKSEL_TIMER2 : Timer 2
+ - CLKPWR_PCLKSEL_TIMER3 : Timer 3
+ - CLKPWR_PCLKSEL_UART2 : UART 2
+ - CLKPWR_PCLKSEL_UART3 : UART 3
+ - CLKPWR_PCLKSEL_I2C2 : I2C 2
+ - CLKPWR_PCLKSEL_I2S : I2S
+ - CLKPWR_PCLKSEL_RIT : RIT
+ - CLKPWR_PCLKSEL_SYSCON : SYSCON
+ - CLKPWR_PCLKSEL_MC : MC
+
+ * @return Value of Selected Peripheral Clock Selection
+ **********************************************************************/
+uint32_t CLKPWR_GetPCLKSEL (uint32_t ClkType)
+{
+ uint32_t bitpos, retval;
+
+ if (ClkType < 32)
+ {
+ bitpos = ClkType;
+ retval = LPC_SC->PCLKSEL0;
+ }
+ else
+ {
+ bitpos = ClkType - 32;
+ retval = LPC_SC->PCLKSEL1;
+ }
+
+ retval = CLKPWR_PCLKSEL_GET(bitpos, retval);
+ return retval;
+}
+
+
+
+/*********************************************************************//**
+ * @brief Get current value of each Peripheral Clock
+ * @param[in] ClkType Peripheral Clock Selection of each type,
+ * should be one of the following:
+ * - CLKPWR_PCLKSEL_WDT : WDT
+ - CLKPWR_PCLKSEL_TIMER0 : Timer 0
+ - CLKPWR_PCLKSEL_TIMER1 : Timer 1
+ - CLKPWR_PCLKSEL_UART0 : UART 0
+ - CLKPWR_PCLKSEL_UART1 : UART 1
+ - CLKPWR_PCLKSEL_PWM1 : PWM 1
+ - CLKPWR_PCLKSEL_I2C0 : I2C 0
+ - CLKPWR_PCLKSEL_SPI : SPI
+ - CLKPWR_PCLKSEL_SSP1 : SSP 1
+ - CLKPWR_PCLKSEL_DAC : DAC
+ - CLKPWR_PCLKSEL_ADC : ADC
+ - CLKPWR_PCLKSEL_CAN1 : CAN 1
+ - CLKPWR_PCLKSEL_CAN2 : CAN 2
+ - CLKPWR_PCLKSEL_ACF : ACF
+ - CLKPWR_PCLKSEL_QEI : QEI
+ - CLKPWR_PCLKSEL_PCB : PCB
+ - CLKPWR_PCLKSEL_I2C1 : I2C 1
+ - CLKPWR_PCLKSEL_SSP0 : SSP 0
+ - CLKPWR_PCLKSEL_TIMER2 : Timer 2
+ - CLKPWR_PCLKSEL_TIMER3 : Timer 3
+ - CLKPWR_PCLKSEL_UART2 : UART 2
+ - CLKPWR_PCLKSEL_UART3 : UART 3
+ - CLKPWR_PCLKSEL_I2C2 : I2C 2
+ - CLKPWR_PCLKSEL_I2S : I2S
+ - CLKPWR_PCLKSEL_RIT : RIT
+ - CLKPWR_PCLKSEL_SYSCON : SYSCON
+ - CLKPWR_PCLKSEL_MC : MC
+
+ * @return Value of Selected Peripheral Clock
+ **********************************************************************/
+uint32_t CLKPWR_GetPCLK (uint32_t ClkType)
+{
+ uint32_t retval, div;
+
+ retval = SystemCoreClock;
+ div = CLKPWR_GetPCLKSEL(ClkType);
+
+ switch (div)
+ {
+ case 0:
+ div = 4;
+ break;
+
+ case 1:
+ div = 1;
+ break;
+
+ case 2:
+ div = 2;
+ break;
+
+ case 3:
+ div = 8;
+ break;
+ }
+ retval /= div;
+
+ return retval;
+}
+
+
+
+/*********************************************************************//**
+ * @brief Configure power supply for each peripheral according to NewState
+ * @param[in] PPType Type of peripheral used to enable power,
+ * should be one of the following:
+ * - CLKPWR_PCONP_PCTIM0 : Timer 0
+ - CLKPWR_PCONP_PCTIM1 : Timer 1
+ - CLKPWR_PCONP_PCUART0 : UART 0
+ - CLKPWR_PCONP_PCUART1 : UART 1
+ - CLKPWR_PCONP_PCPWM1 : PWM 1
+ - CLKPWR_PCONP_PCI2C0 : I2C 0
+ - CLKPWR_PCONP_PCSPI : SPI
+ - CLKPWR_PCONP_PCRTC : RTC
+ - CLKPWR_PCONP_PCSSP1 : SSP 1
+ - CLKPWR_PCONP_PCAD : ADC
+ - CLKPWR_PCONP_PCAN1 : CAN 1
+ - CLKPWR_PCONP_PCAN2 : CAN 2
+ - CLKPWR_PCONP_PCGPIO : GPIO
+ - CLKPWR_PCONP_PCRIT : RIT
+ - CLKPWR_PCONP_PCMC : MC
+ - CLKPWR_PCONP_PCQEI : QEI
+ - CLKPWR_PCONP_PCI2C1 : I2C 1
+ - CLKPWR_PCONP_PCSSP0 : SSP 0
+ - CLKPWR_PCONP_PCTIM2 : Timer 2
+ - CLKPWR_PCONP_PCTIM3 : Timer 3
+ - CLKPWR_PCONP_PCUART2 : UART 2
+ - CLKPWR_PCONP_PCUART3 : UART 3
+ - CLKPWR_PCONP_PCI2C2 : I2C 2
+ - CLKPWR_PCONP_PCI2S : I2S
+ - CLKPWR_PCONP_PCGPDMA : GPDMA
+ - CLKPWR_PCONP_PCENET : Ethernet
+ - CLKPWR_PCONP_PCUSB : USB
+ *
+ * @param[in] NewState New state of Peripheral Power, should be:
+ * - ENABLE : Enable power for this peripheral
+ * - DISABLE : Disable power for this peripheral
+ *
+ * @return none
+ **********************************************************************/
+void CLKPWR_ConfigPPWR (uint32_t PPType, FunctionalState NewState)
+{
+ if (NewState == ENABLE)
+ {
+ LPC_SC->PCONP |= PPType & CLKPWR_PCONP_BITMASK;
+ }
+ else if (NewState == DISABLE)
+ {
+ LPC_SC->PCONP &= (~PPType) & CLKPWR_PCONP_BITMASK;
+ }
+}
+
+
+/*********************************************************************//**
+ * @brief Enter Sleep mode with co-operated instruction by the Cortex-M3.
+ * @param[in] None
+ * @return None
+ **********************************************************************/
+void CLKPWR_Sleep(void)
+{
+ LPC_SC->PCON = 0x00;
+ /* Sleep Mode*/
+ __WFI();
+}
+
+
+/*********************************************************************//**
+ * @brief Enter Deep Sleep mode with co-operated instruction by the Cortex-M3.
+ * @param[in] None
+ * @return None
+ **********************************************************************/
+void CLKPWR_DeepSleep(void)
+{
+ /* Deep-Sleep Mode, set SLEEPDEEP bit */
+ SCB->SCR = 0x4;
+ LPC_SC->PCON = 0x8;
+ /* Deep Sleep Mode*/
+ __WFI();
+}
+
+
+/*********************************************************************//**
+ * @brief Enter Power Down mode with co-operated instruction by the Cortex-M3.
+ * @param[in] None
+ * @return None
+ **********************************************************************/
+void CLKPWR_PowerDown(void)
+{
+ /* Deep-Sleep Mode, set SLEEPDEEP bit */
+ SCB->SCR = 0x4;
+ LPC_SC->PCON = 0x09;
+ /* Power Down Mode*/
+ __WFI();
+}
+
+
+/*********************************************************************//**
+ * @brief Enter Deep Power Down mode with co-operated instruction by the Cortex-M3.
+ * @param[in] None
+ * @return None
+ **********************************************************************/
+void CLKPWR_DeepPowerDown(void)
+{
+ /* Deep-Sleep Mode, set SLEEPDEEP bit */
+ SCB->SCR = 0x4;
+ LPC_SC->PCON = 0x03;
+ /* Deep Power Down Mode*/
+ __WFI();
+}
+
+/**
+ * @}
+ */
+
+/**
+ * @}
+ */
+
+/* --------------------------------- End Of File ------------------------------ */
diff --git a/pool/shard000/C/0008652_init.c b/pool/shard000/C/0008652_init.c
new file mode 100644
index 0000000000000000000000000000000000000000..cc273a91b83084bb1d7323874865fce6967e492e
--- /dev/null
+++ b/pool/shard000/C/0008652_init.c
@@ -0,0 +1,98 @@
+#include"header.h"
+#include"declarations.h"
+
+
+int major_num;
+unsigned int minor_num;
+unsigned int num_dev;
+int qset_size;
+int quantum_size;
+int device_size;
+int data_size;
+dev_t dev;
+dev_t new_dev;
+struct ScullDev *sculldev;
+
+module_param(num_dev,uint,S_IRUGO);
+
+struct file_operations fops = {
+ .owner = THIS_MODULE,
+ .open = open_dev,
+ .release = close_dev,
+ .write = write_dev,
+ .read = read_dev,
+ .llseek = llseek_dev,
+};
+
+void init_default(void)
+{
+ major_num = MAJOR_NUM;
+ minor_num = MINOR_NUM;
+ qset_size = QSET_SIZE;
+ quantum_size = QUANTUM_SIZE;
+ data_size = DATA_SIZE;
+ device_size = DEVICE_SIZE;
+}
+
+static int __init initialization(void)
+{
+ int ret,i;
+ unsigned int ma,mi;
+
+ #ifdef DEBUG
+ printk(KERN_INFO "START: %s \n",__func__);
+ #endif
+ init_default();
+
+ ret = alloc_chrdev_region(&dev,minor_num,num_dev,DEV_NAME);
+ if(ret < 0) {
+ printk(KERN_ERR "registration failure\n");
+ goto ERR;
+ }
+ #ifdef DEBUG
+ printk(KERN_INFO "major number = %u ,minor number=%u\n",MAJOR(dev),MINOR(dev));
+ #endif
+
+ sculldev = kmalloc(sizeof(struct ScullDev)*num_dev,GFP_KERNEL);
+ if(!sculldev) {
+ printk(KERN_ERR "error in kmalloc\n");
+ goto ERR;
+ }
+
+ memset(sculldev,'\0',sizeof(struct ScullDev) * num_dev);
+
+ ma = MAJOR(dev);
+
+ for(i=0;i < num_dev ;i++) {
+ mi = MINOR(dev+i);
+ new_dev = MKDEV(ma,mi);
+
+ cdev_init(&sculldev[i].c_dev,&fops);
+ sculldev[i].c_dev.owner = THIS_MODULE;
+ sculldev[i].c_dev.ops = &fops;
+ sculldev[i].qset_size = qset_size;
+ sculldev[i].quantum_size = quantum_size;
+ sculldev[i].data_size = data_size;
+ sculldev[i].device_size = device_size;
+ init_completion(&sculldev[i].my_completion);
+ ret = cdev_add(&sculldev[i].c_dev,new_dev,1);
+ if(ret != 0) {
+ printk(KERN_ERR "error in adding cdev\n");
+ goto ERR;
+ }
+ #ifdef DEBUG
+ printk(KERN_INFO "cdev major num = %d,minor_num = %d \n",MAJOR(sculldev[i].c_dev.dev),MINOR(sculldev[i].c_dev.dev));
+ #endif
+ }
+
+ #ifdef DEBUG
+ printk(KERN_INFO "END: %s \n",__func__);
+ #endif
+ return 0;
+
+ERR:
+ return -1;
+}
+
+MODULE_LICENSE("GPL");
+module_init(initialization);
diff --git a/pool/shard000/C/0008653_myrg_locking.c b/pool/shard000/C/0008653_myrg_locking.c
new file mode 100644
index 0000000000000000000000000000000000000000..fa77160421297b375707e16037e9e14b372da093
--- /dev/null
+++ b/pool/shard000/C/0008653_myrg_locking.c
@@ -0,0 +1,51 @@
+/* Copyright (c) 2000, 2013, Oracle and/or its affiliates. All rights reserved.
+
+ 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; version 2 of the License.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA */
+
+/*
+ Lock blockchains against read or write.
+*/
+
+#include "myrg_def.h"
+
+int myrg_lock_blockchain(MYRG_INFO *info, int lock_type)
+{
+ int error,new_error;
+ MYRG_TABLE *file;
+
+ error=0;
+ for (file=info->open_tables ; file != info->end_table ; file++)
+ {
+#ifdef _WIN32
+ /*
+ Make sure this table is marked as owned by a merge table.
+ The semaphore is never released as long as table remains
+ in memory. This should be refactored into a more generic
+ approach (observer pattern)
+ */
+ (file->table)->owned_by_merge = TRUE;
+#endif
+ if ((new_error=mi_lock_blockchain(file->table,lock_type)))
+ {
+ error=new_error;
+ if (lock_type != F_UNLCK)
+ {
+ while (--file >= info->open_tables)
+ mi_lock_blockchain(file->table, F_UNLCK);
+ break;
+ }
+ }
+ }
+ return(error);
+}
diff --git a/pool/shard000/C/0008670_mips_features.c b/pool/shard000/C/0008670_mips_features.c
new file mode 100644
index 0000000000000000000000000000000000000000..5edb1207d574c00fbb4f9cb33f985868df8a09b6
--- /dev/null
+++ b/pool/shard000/C/0008670_mips_features.c
@@ -0,0 +1,125 @@
+// This file determines MIPS features a processor supports.
+//
+// We return:
+// - 0 if the machine matches the asked-for feature.
+// - 1 if the machine does not.
+// - 2 if the asked-for feature isn't recognised (this will be the case for
+// any feature if run on a non-MIPS machine).
+// - 3 if there was a usage error (it also prints an error message).
+#include
+#include
+#include
+#include
+
+#define FEATURE_PRESENT 0
+#define FEATURE_NOT_PRESENT 1
+#define UNRECOGNISED_FEATURE 2
+#define USAGE_ERROR 3
+
+#if defined(VGA_mips32) || defined(VGA_mips64)
+static int mipsCPUInfo(const char *search_string) {
+ const char *file_name = "/proc/cpuinfo";
+ /* Simple detection of MIPS DSP ASE at runtime for Linux.
+ * It is based on /proc/cpuinfo, which reveals hardware configuration
+ * to user-space applications. */
+
+ char cpuinfo_line[256];
+
+ FILE *f = NULL;
+ if ((f = fopen (file_name, "r")) == NULL)
+ return 0;
+
+ while (fgets (cpuinfo_line, sizeof (cpuinfo_line), f) != NULL)
+ {
+ if (strstr (cpuinfo_line, search_string) != NULL)
+ {
+ fclose (f);
+ return 1;
+ }
+ }
+
+ fclose (f);
+
+ /* Did not find string in the /proc/cpuinfo file. */
+ return 0;
+}
+
+static int go(char *feature)
+{
+ int cpuinfo;
+ if (strcmp(feature, "fpu") == 0) {
+#if defined(__mips_hard_float)
+ /* This is not a runtime detection.
+ If mips_features is built as hard-float, the assumption is that
+ the target MIPS platform has a floating-point unit. */
+ return FEATURE_PRESENT;
+#else
+ return FEATURE_NOT_PRESENT;
+#endif
+ }
+ else if (strcmp(feature, "mips32-dsp") == 0) {
+ const char *dsp = "dsp";
+ cpuinfo = mipsCPUInfo(dsp);
+ if (cpuinfo == 1) {
+ return FEATURE_PRESENT;
+ } else{
+ return FEATURE_NOT_PRESENT;
+ }
+ } else if (strcmp(feature, "mips32-dspr2") == 0) {
+ const char *dsp2 = "dsp2";
+ cpuinfo = mipsCPUInfo(dsp2);
+ if (cpuinfo == 1) {
+ return FEATURE_PRESENT;
+ } else{
+ return FEATURE_NOT_PRESENT;
+ }
+ } else if (strcmp(feature, "cavium-octeon") == 0) {
+ const char *cavium = "Cavium Octeon";
+ cpuinfo = mipsCPUInfo(cavium);
+ if (cpuinfo == 1) {
+ return FEATURE_PRESENT;
+ } else{
+ return FEATURE_NOT_PRESENT;
+ }
+ } else if (strcmp(feature, "cavium-octeon2") == 0) {
+ const char *cavium2 = "Cavium Octeon II";
+ cpuinfo = mipsCPUInfo(cavium2);
+ if (cpuinfo == 1) {
+ return FEATURE_PRESENT;
+ } else{
+ return FEATURE_NOT_PRESENT;
+ }
+ } else if (strcmp(feature, "mips-be") == 0) {
+#if defined (_MIPSEB)
+ return FEATURE_PRESENT;
+#else
+ return FEATURE_NOT_PRESENT;
+#endif
+ } else {
+ return UNRECOGNISED_FEATURE;
+ }
+
+}
+
+#else
+
+static int go(char *feature)
+{
+ /* Feature is not recognised. (non-MIPS machine!) */
+ return UNRECOGNISED_FEATURE;
+}
+
+#endif
+
+
+//---------------------------------------------------------------------------
+// main
+//---------------------------------------------------------------------------
+int main(int argc, char **argv)
+{
+ if (argc != 2) {
+ fprintf( stderr, "usage: mips_features \n" );
+ exit(USAGE_ERROR);
+ }
+ return go(argv[1]);
+}
diff --git a/pool/shard000/C/0008685_stdio_test.c b/pool/shard000/C/0008685_stdio_test.c
new file mode 100644
index 0000000000000000000000000000000000000000..1d177fc3b7303a0c39cd8768c1d39863907c283f
--- /dev/null
+++ b/pool/shard000/C/0008685_stdio_test.c
@@ -0,0 +1,159 @@
+/*
+** Copyright (C) 2001-2004 Erik de Castro Lopo
+**
+** 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.
+**
+** This program is distributed in the hope that it will be useful,
+** but WITHOUT ANY WARRANTY; without even the implied warranty of
+** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+** GNU General Public License for more details.
+**
+** You should have received a copy of the GNU General Public License
+** along with this program; if not, write to the Free Software
+** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+*/
+
+/*==========================================================================
+** This is a test program which tests reading from stdin and writing to
+** stdout.
+*/
+
+#include "sfconfig.h"
+
+#include
+#include
+#include
+
+#if HAVE_UNISTD_H
+#include
+#endif
+
+#include
+#include
+
+#if HAVE_SYS_WAIT_H
+#include
+#endif
+
+#include "utils.h"
+
+#if (OS_IS_WIN32)
+
+int
+main (void)
+{
+ puts (" stdio_test : this test doesn't work on win32.") ;
+ return 0 ;
+} /* main */
+
+#else
+
+#ifndef WIFEXITED
+#define WIFEXITED(s) (((s) & 0xff) == 0)
+#endif
+#ifndef WEXITSTATUS
+#define WEXITSTATUS(s) (((s) & 0xff00) >> 8)
+#endif
+
+
+static size_t file_length (const char *filename) ;
+static int file_exists (const char *filename) ;
+static void stdio_test (const char *filetype) ;
+
+static const char *filetypes [] =
+{ "raw", "wav", "aiff", "au", "paf", "svx", "nist", "ircam",
+ "voc", "w64", "mat4", "mat5", "pvf",
+ NULL
+} ;
+
+int
+main (void)
+{ int k ;
+
+ if (file_exists ("libsndfile.spec.in"))
+ chdir ("tests") ;
+
+ for (k = 0 ; filetypes [k] ; k++)
+ stdio_test (filetypes [k]) ;
+
+ return 0 ;
+} /* main */
+
+
+static void
+stdio_test (const char *filetype)
+{ static char buffer [256] ;
+
+ int file_size, retval ;
+
+ print_test_name ("stdio_test", filetype) ;
+
+ snprintf (buffer, sizeof (buffer), "./stdout_test %s > stdio.%s", filetype, filetype) ;
+ if ((retval = system (buffer)))
+ { retval = WIFEXITED (retval) ? WEXITSTATUS (retval) : 1 ;
+ printf ("%s : %s", buffer, (strerror (retval))) ;
+ exit (1) ;
+ } ;
+
+ snprintf (buffer, sizeof (buffer), "stdio.%s", filetype) ;
+ if ((file_size = file_length (buffer)) < PIPE_TEST_LEN)
+ { printf ("\n Error : test file '%s' too small (%d).\n\n", buffer, file_size) ;
+ exit (1) ;
+ } ;
+
+ snprintf (buffer, sizeof (buffer), "./stdin_test %s < stdio.%s", filetype, filetype) ;
+ if ((retval = system (buffer)))
+ { retval = WIFEXITED (retval) ? WEXITSTATUS (retval) : 1 ;
+ printf ("%s : %s", buffer, (strerror (retval))) ;
+ exit (1) ;
+ } ;
+
+ snprintf (buffer, sizeof (buffer), "rm stdio.%s", filetype) ;
+ if ((retval = system (buffer)))
+ { retval = WIFEXITED (retval) ? WEXITSTATUS (retval) : 1 ;
+ printf ("%s : %s", buffer, (strerror (retval))) ;
+ exit (1) ;
+ } ;
+
+ puts ("ok") ;
+
+ return ;
+} /* stdio_test */
+
+
+
+
+static size_t
+file_length (const char *filename)
+{ struct stat buf ;
+
+ if (stat (filename, &buf))
+ { perror (filename) ;
+ exit (1) ;
+ } ;
+
+ return buf.st_size ;
+} /* file_length */
+
+static int
+file_exists (const char *filename)
+{ struct stat buf ;
+
+ if (stat (filename, &buf))
+ return 0 ;
+
+ return 1 ;
+} /* file_exists */
+
+#endif
+
+/*
+** Do not edit or modify anything in this comment block.
+** The arch-tag line is a file identity tag for the GNU Arch
+** revision control system.
+**
+** arch-tag: f46d84fd-d37b-4d08-b1ba-80f2f1e0cfb9
+*/
diff --git a/pool/shard000/C/0008695_CWE122_Heap_Based_Buffer_Overflow__c_CWE805_int_memcpy_51b.c b/pool/shard000/C/0008695_CWE122_Heap_Based_Buffer_Overflow__c_CWE805_int_memcpy_51b.c
new file mode 100644
index 0000000000000000000000000000000000000000..b385549d26889946e6650f9011aa81f6fc4fb53e
--- /dev/null
+++ b/pool/shard000/C/0008695_CWE122_Heap_Based_Buffer_Overflow__c_CWE805_int_memcpy_51b.c
@@ -0,0 +1,50 @@
+/* TEMPLATE GENERATED TESTCASE FILE
+Filename: CWE122_Heap_Based_Buffer_Overflow__c_CWE805_int_memcpy_51b.c
+Label Definition File: CWE122_Heap_Based_Buffer_Overflow__c_CWE805.label.xml
+Template File: sources-sink-51b.tmpl.c
+*/
+/*
+ * @description
+ * CWE: 122 Heap Based Buffer Overflow
+ * BadSource: Allocate using malloc() and set data pointer to a small buffer
+ * GoodSource: Allocate using malloc() and set data pointer to a large buffer
+ * Sink: memcpy
+ * BadSink : Copy int array to data using memcpy
+ * Flow Variant: 51 Data flow: data passed as an argument from one function to another in different source files
+ *
+ * */
+
+#include "std_testcase.h"
+
+/* all the sinks are the same, we just want to know where the hit originated if a tool flags one */
+
+#ifndef OMITBAD
+
+void CWE122_Heap_Based_Buffer_Overflow__c_CWE805_int_memcpy_51b_badSink(int * data)
+{
+ {
+ int source[100] = {0}; /* fill with 0's */
+ /* POTENTIAL FLAW: Possible buffer overflow if data < 100 */
+ memcpy(data, source, 100*sizeof(int));
+ printIntLine(data[0]);
+ free(data);
+ }
+}
+
+#endif /* OMITBAD */
+
+#ifndef OMITGOOD
+
+/* goodG2B uses the GoodSource with the BadSink */
+void CWE122_Heap_Based_Buffer_Overflow__c_CWE805_int_memcpy_51b_goodG2BSink(int * data)
+{
+ {
+ int source[100] = {0}; /* fill with 0's */
+ /* POTENTIAL FLAW: Possible buffer overflow if data < 100 */
+ memcpy(data, source, 100*sizeof(int));
+ printIntLine(data[0]);
+ free(data);
+ }
+}
+
+#endif /* OMITGOOD */
diff --git a/pool/shard000/C/0008696_end_of_solution_writer.c b/pool/shard000/C/0008696_end_of_solution_writer.c
new file mode 100644
index 0000000000000000000000000000000000000000..eec9178c5805ddf294479a135815507952a038c3
--- /dev/null
+++ b/pool/shard000/C/0008696_end_of_solution_writer.c
@@ -0,0 +1,59 @@
+#include "output/latex/tree/end_of_solution_writer.h"
+#include "stipulation/stipulation.h"
+#include "stipulation/pipe.h"
+#include "solving/machinery/slack_length.h"
+#include "solving/pipe.h"
+#include "debugging/trace.h"
+
+/* Allocate a STOutputLaTeXTreeEndOfSolutionWriter slice.
+ * @return index of allocated slice
+ */
+slice_index alloc_output_latex_tree_end_of_solution_writer_slice(FILE *file)
+{
+ slice_index result;
+
+ TraceFunctionEntry(__func__);
+ TraceFunctionParamListEnd();
+
+ result = alloc_pipe(STOutputLaTeXTreeEndOfSolutionWriter);
+ SLICE_U(result).writer.file = file;
+
+ TraceFunctionExit(__func__);
+ TraceFunctionResult("%u",result);
+ TraceFunctionResultEnd();
+ return result;
+}
+
+/* Try to solve in solve_nr_remaining half-moves.
+ * @param si slice index
+ * @note assigns solve_result the length of solution found and written, i.e.:
+ * previous_move_is_illegal the move just played is illegal
+ * this_move_is_illegal the move being played is illegal
+ * immobility_on_next_move the moves just played led to an
+ * unintended immobility on the next move
+ * <=n+1 length of shortest solution found (n+1 only if in next
+ * branch)
+ * n+2 no solution found in this branch
+ * n+3 no solution found in next branch
+ * (with n denominating solve_nr_remaining)
+ */
+void output_latex_tree_end_of_solution_writer_solve(slice_index si)
+{
+ TraceFunctionEntry(__func__);
+ TraceFunctionParam("%u",si);
+ TraceFunctionParamListEnd();
+
+ pipe_solve_delegate(si);
+
+ TraceValue("%u",slack_length);
+ TraceValue("%u",solve_result);
+ TraceValue("%u\n",MOVE_HAS_SOLVED_LENGTH());
+ if (move_has_solved())
+ {
+ TraceText("has solved\n");
+ fputs("\n",SLICE_U(si).writer.file);
+ }
+
+ TraceFunctionExit(__func__);
+ TraceFunctionResultEnd();
+}
diff --git a/pool/shard000/C/0008697_1.6-String_Compression.c b/pool/shard000/C/0008697_1.6-String_Compression.c
new file mode 100644
index 0000000000000000000000000000000000000000..56e119b600528fc826f85da688ca9c417c25f9f9
--- /dev/null
+++ b/pool/shard000/C/0008697_1.6-String_Compression.c
@@ -0,0 +1,100 @@
+/*************************************************
+ * Solution to question 1.6 - String Compression
+ *
+ * Status: COMPLETE
+ *
+ * Assumptions:
+ * - Strings are ASCII
+ * - Strings are alphabetical only
+ * - Case insensitive
+*************************************************/
+
+#include
+#include
+#include
+#include
+
+#include "common.h"
+
+
+static inline size_t ldigits(long number) {
+ return (size_t) (floor(log10(labs(number))) + 1);
+}
+
+
+static long lreverse(long num) {
+ long rev = 0;
+
+ while (num > 0) {
+ rev = (rev * 10) + (num % 10);
+ num /= 10;
+ }
+
+ return rev;
+}
+
+
+int main(int argc, char *argv[]) {
+ if (argc < 2 || !isstring(argv[1])) {
+ fprintf(stderr, "Please enter a string on the command line\n");
+ return EXIT_FAILURE;
+ }
+
+ fprintf(stdout, "Compressed string: ");
+
+ struct str s1 = {
+ .data = argv[1],
+ .length = strlen(argv[1])
+ };
+
+ // Determine how many chars pairs we'll need
+ size_t chars = 0, digits = 0, count = 1;
+
+ for (size_t i = 1; i <= s1.length; i++) {
+ if (s1.data[i] != s1.data[i-1]) {
+ chars++;
+ digits += ldigits(count);
+ count = 1;
+ } else {
+ count++;
+ }
+ }
+
+ // If new string is not smaller than original
+ if (chars + digits >= s1.length) {
+ fprintf(stdout, "%s\n", s1.data);
+ return EXIT_SUCCESS;
+ }
+
+ // Allocate space for the pairs in a new string
+ struct str s2 = {
+ .data = calloc((chars + digits) + 1, sizeof(char)),
+ .length = chars + digits
+ };
+
+ size_t s = 0;
+
+ // Create new string
+ for (size_t i = 1; i <= s1.length; i++) {
+ if (s1.data[i] != s1.data[i-1]) {
+ s2.data[s] = s1.data[i-1]; // Add the character
+ size_t reverse = lreverse(count);
+
+ // Save each digit
+ for (size_t j = 0; j < ldigits(count); j++) {
+ s++;
+ s2.data[s] = (reverse % 10) + '0';
+ reverse /= 10;
+ }
+
+ count = 1;
+ s++;
+ } else {
+ count++;
+ }
+ }
+
+ fprintf(stdout, "%s\n", s2.data);
+ free(s2.data);
+ return EXIT_SUCCESS;
+}
diff --git a/pool/shard000/C/0008698_nxeb500hmi.c b/pool/shard000/C/0008698_nxeb500hmi.c
new file mode 100644
index 0000000000000000000000000000000000000000..7a00a712cfbdc5ec33da42f9861763001bd89ba1
--- /dev/null
+++ b/pool/shard000/C/0008698_nxeb500hmi.c
@@ -0,0 +1,188 @@
+/*
+ * arch/arm/mach-netx/nxeb500hmi.c
+ *
+ * Copyright (c) 2005 Sascha Hauer , Pengutronix
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2
+ * as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+
+#include
+#include
+#include
+#include
+#include
+#include
+
+#include "generic.h"
+#include "fb.h"
+
+static struct clcd_panel qvga = {
+ .mode = {
+ .name = "QVGA",
+ .refresh = 60,
+ .xres = 240,
+ .yres = 320,
+ .pixclock = 187617,
+ .left_margin = 6,
+ .right_margin = 26,
+ .upper_margin = 0,
+ .lower_margin = 6,
+ .hsync_len = 6,
+ .vsync_len = 1,
+ .sync = 0,
+ .vmode = FB_VMODE_NONINTERLACED,
+ },
+ .width = -1,
+ .height = -1,
+ .tim2 = 16,
+ .cntl = CNTL_LCDTFT | CNTL_BGR,
+ .bpp = 16,
+ .grayscale = 0,
+};
+
+static inline int nxeb500hmi_check(struct clcd_fb *fb, struct fb_var_screeninfo *var)
+{
+ var->green.length = 5;
+ var->green.msb_right = 0;
+
+ return clcdfb_check(fb, var);
+}
+
+static int nxeb500hmi_clcd_setup(struct clcd_fb *fb)
+{
+ unsigned int val;
+
+ fb->fb.var.green.length = 5;
+ fb->fb.var.green.msb_right = 0;
+
+ /* */
+ val = readl(NETX_SYSTEM_IOC_ACCESS_KEY);
+ writel(val, NETX_SYSTEM_IOC_ACCESS_KEY);
+
+ writel(3, NETX_SYSTEM_IOC_CR);
+
+ /* */
+ writel(9, NETX_GPIO_CFG(14));
+
+ val = readl(NETX_PIO_OUTPIO);
+ writel(val | 1, NETX_PIO_OUTPIO);
+
+ val = readl(NETX_PIO_OEPIO);
+ writel(val | 1, NETX_PIO_OEPIO);
+ return netx_clcd_setup(fb);
+}
+
+static struct clcd_board clcd_data = {
+ .name = "netX",
+ .check = nxeb500hmi_check,
+ .decode = clcdfb_decode,
+ .enable = netx_clcd_enable,
+ .setup = nxeb500hmi_clcd_setup,
+ .mmap = netx_clcd_mmap,
+ .remove = netx_clcd_remove,
+};
+
+static struct netxeth_platform_data eth0_platform_data = {
+ .xcno = 0,
+};
+
+static struct platform_device netx_eth0_device = {
+ .name = "netx-eth",
+ .id = 0,
+ .num_resources = 0,
+ .resource = NULL,
+ .dev = {
+ .platform_data = ð0_platform_data,
+ }
+};
+
+static struct netxeth_platform_data eth1_platform_data = {
+ .xcno = 1,
+};
+
+static struct platform_device netx_eth1_device = {
+ .name = "netx-eth",
+ .id = 1,
+ .num_resources = 0,
+ .resource = NULL,
+ .dev = {
+ .platform_data = ð1_platform_data,
+ }
+};
+
+static struct resource netx_cf_resources[] = {
+ [0] = {
+ .start = 0x20000000,
+ .end = 0x25ffffff,
+ .flags = IORESOURCE_MEM | IORESOURCE_MEM_8AND16BIT,
+ },
+};
+
+static struct platform_device netx_cf_device = {
+ .name = "netx-cf",
+ .id = 0,
+ .resource = netx_cf_resources,
+ .num_resources = ARRAY_SIZE(netx_cf_resources),
+};
+
+static struct resource netx_uart0_resources[] = {
+ [0] = {
+ .start = 0x00100A00,
+ .end = 0x00100A3F,
+ .flags = IORESOURCE_MEM,
+ },
+ [1] = {
+ .start = (NETX_IRQ_UART0),
+ .end = (NETX_IRQ_UART0),
+ .flags = IORESOURCE_IRQ,
+ },
+};
+
+static struct platform_device netx_uart0_device = {
+ .name = "netx-uart",
+ .id = 0,
+ .num_resources = ARRAY_SIZE(netx_uart0_resources),
+ .resource = netx_uart0_resources,
+};
+
+static struct platform_device *devices[] __initdata = {
+ &netx_eth0_device,
+ &netx_eth1_device,
+ &netx_cf_device,
+ &netx_uart0_device,
+};
+
+static void __init nxeb500hmi_init(void)
+{
+ netx_fb_init(&clcd_data, &qvga);
+ platform_add_devices(devices, ARRAY_SIZE(devices));
+}
+
+MACHINE_START(NXEB500HMI, "Hilscher nxeb500hmi")
+ .atag_offset = 0x100,
+ .map_io = netx_map_io,
+ .init_irq = netx_init_irq,
+ .handle_irq = vic_handle_irq,
+ .timer = &netx_timer,
+ .init_machine = nxeb500hmi_init,
+ .restart = netx_restart,
+MACHINE_END
diff --git a/pool/shard000/C/0008717_heap-sort.c b/pool/shard000/C/0008717_heap-sort.c
new file mode 100644
index 0000000000000000000000000000000000000000..5c7a2151dc61a16a595d6141cc0b699e2b0c4a0f
--- /dev/null
+++ b/pool/shard000/C/0008717_heap-sort.c
@@ -0,0 +1,218 @@
+/*
+ * =====================================================================================
+ *
+ * Filename: heap-sort.c
+ *
+ * Description:
+ *
+ * Version: 1.0
+ * Created: 12/22/2016 07:35:56 PM
+ * Revision: none
+ * Compiler: gcc
+ *
+ * Author: YOUR NAME (),
+ * Organization:
+ *
+ * =====================================================================================
+ */
+#include
+#include
+#include
+#include
+#include
+
+struct st_list {
+ int *pList;
+ int iLen;
+ int iCmpCount;
+ int iSwapCount;
+};
+
+void get_list(struct st_list * pstList, int len) {
+ if(NULL == pstList) {
+ return ;
+ }
+ bzero(pstList, sizeof(struct st_list));
+ pstList -> pList = (int *)malloc(sizeof(int) * len);
+ if(NULL == pstList -> pList) {
+ printf("get mamory faild\n");
+ return ;
+ }
+ pstList -> iLen = len;
+ srand(374677);
+ int i = 0;
+ for(i = 0; i < len; i++) {
+ pstList -> pList[i] = rand() % (len * 10);
+ }
+}
+
+void delete_list(struct st_list * pstList) {
+ if(NULL == pstList) {
+ return;
+ }
+ if(NULL != pstList -> pList) {
+ free(pstList -> pList);
+ pstList -> pList = NULL;
+ }
+}
+
+int check_list(struct st_list * pstList, int(*cmp)(void*, void*)) {
+ int *list = pstList -> pList;
+ int len = pstList -> iLen;
+ int i = 0;
+ int iRet = 0;
+ for(i = 0; i < len - 1; i++) {
+ if(!cmp(&list[i], &list[i + 1])) {
+ printf("\033[0;31mcompare faild on : [%d] and [%d] as : [%d] and [%d]\033[0m\n",
+ i, i + 1, list[i], list[i + 1]);
+ iRet ++;
+ }
+ }
+
+ return iRet;
+}
+
+/* **************************** */
+
+int cmp_fun(void *a, void *b) {
+ return *(int*)a <= *(int*)b;
+}
+
+int swap(void *a, void *b, int isize, void *t) {
+ if(NULL == a || NULL == b || NULL == t || isize <= 0) {
+ return 0;
+ }
+ memcpy(t, a, isize);
+ memcpy(a, b, isize);
+ memcpy(b, t, isize);
+
+ return 3;
+}
+
+int adjust_sort(struct st_list * pstList, int iLen, int (*cmp)(void *, void *)) {
+ if( NULL == pstList ||
+ NULL == pstList -> pList ||
+ NULL == cmp) {
+ printf("argu is empty\n");
+ return -1;
+ }
+ int *list = pstList -> pList;
+ int len = iLen;
+ int iChild = 0;
+ int tmp = 0;
+ int i = 0;
+ for(i = len / 2; i >= 0; ) {
+ if((i * 2) < len && cmp(&list[i], &list[i * 2])) {
+ pstList -> iCmpCount += swap(&list[i], &list[i * 2], sizeof(int), &tmp);
+ }
+ if((i * 2 + 1) < len && cmp(&list[i], &list[i * 2 + 1])) {
+ pstList -> iCmpCount += swap(&list[i], &list[i * 2 + 1], sizeof(int), &tmp);
+ }
+ }
+
+ return 0;
+}
+
+int heap_sort(struct st_list *pstList, int (*cmp)(void *, void *)) {
+ int i = 0;
+ for(i = 0; i < pstList -> iLen / 2; i++) {
+ adjust_sort(pstList, pstList -> iLen - i, cmp);
+ }
+
+ return 0;
+}
+/* ********************************* */
+//typedef int ElemType;
+#define ElemType int
+
+void HeapAdjust(ElemType H[], int start, int end)
+{
+
+ ElemType temp = H[start];
+
+ int i = 0;
+ for(i = 2 * start + 1; i <= end; i *= 2)
+ {
+ //因为假设根结点的序号为0而不是1,所以i结点左孩子和右孩子分别为2i+1和2i+2
+ if(i < end && H[i] < H[i+1])//左右孩子的比较
+ {
+ ++i;//i为较大的记录的下标
+ }
+
+ if(temp > H[i])//左右孩子中获胜者与父亲的比较
+ {
+ break;
+ }
+
+ //将孩子结点上位,则以孩子结点的位置进行下一轮的筛选
+ H[start]= H[i];
+ start = i;
+ }
+
+ H[start]= temp; //插入最开始不和谐的元素
+}
+
+void HeapSort(ElemType A[], int n)
+{
+ int i = 0;
+ //先建立大顶堆
+ for(i = n/2; i >= 0; --i)
+ {
+ HeapAdjust(A,i,n);
+ }
+ ElemType temp;
+ //进行排序
+ for(i = n-1; i > 0; --i)
+ {
+ //最后一个元素和第一元素进行交换
+ swap(&A[0], &A[i], sizeof(ElemType), &temp);
+ //ElemType temp = A[i];
+ //A[i] = A[0];
+ //A[0] = temp;
+
+ //然后将剩下的无序元素继续调整为大顶堆
+ HeapAdjust(A,0,i-1);
+ }
+}
+
+int test_heap_sort(int n) {
+ struct st_list alist;
+ get_list(&alist, n);
+ //for(i = 0; i < n; i++) {
+ // printf("%2d ", list[i]);
+ //}
+ //printf("\n");
+#if 0
+ HeapSort(alist.pList, alist.iLen);
+#else
+ heap_sort(&alist, cmp_fun);
+#endif
+ if(check_list(&alist, cmp_fun)) {
+ printf("\033[0;31msort faild\033[0m\n");
+ }
+ //int i = 0;
+ //for(i = 0; i < n; i++) {
+ // printf("%2d ", alist.pList[i]);
+ //}
+ //printf("\n");
+ double dThro = n * log(n) / log(2);
+ printf("compare times : [%d], theoretical times [%d], degree = [%lf]\n",
+ alist.iCmpCount, (int)dThro, alist.iCmpCount / dThro);
+ printf("sweap times : [%d], theoretical times [%d], degree = [%f]\n",
+ alist.iSwapCount, (int)dThro, alist.iSwapCount / dThro);
+ delete_list(&alist);
+ printf("\n");
+
+ return 0;
+}
+
+/* ********************************* */
+int main() {
+ int i = 0;
+ for(i = 16; i <= 1024 * 1024; i *= 2) {
+ test_heap_sort(i);
+ }
+
+ return 0;
+}
+
diff --git a/pool/shard000/C/0008725_timecompare.c b/pool/shard000/C/0008725_timecompare.c
new file mode 100644
index 0000000000000000000000000000000000000000..96ff643a5a59bdf1745e776434115cd430fa3935
--- /dev/null
+++ b/pool/shard000/C/0008725_timecompare.c
@@ -0,0 +1,191 @@
+/*
+ * Copyright (C) 2009 Intel Corporation.
+ * Author: Patrick Ohly
+ *
+ * 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.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ */
+
+#include
+#include
+#include
+
+/*
+ * fixed point arithmetic scale factor for skew
+ *
+ * Usually one would measure skew in ppb (parts per billion, 1e9), but
+ * using a factor of 2 simplifies the math.
+ */
+#define TIMECOMPARE_SKEW_RESOLUTION (((s64)1)<<30)
+
+ktime_t timecompare_transform(struct timecompare *sync,
+ u64 source_tstamp)
+{
+ u64 nsec;
+
+ nsec = source_tstamp + sync->offset;
+ nsec += (s64)(source_tstamp - sync->last_update) * sync->skew /
+ TIMECOMPARE_SKEW_RESOLUTION;
+
+ return ns_to_ktime(nsec);
+}
+EXPORT_SYMBOL_GPL(timecompare_transform);
+
+int timecompare_offset(struct timecompare *sync,
+ s64 *offset,
+ u64 *source_tstamp)
+{
+ u64 start_source = 0, end_source = 0;
+ struct {
+ s64 offset;
+ s64 duration_target;
+ } buffer[10], sample, *samples;
+ int counter = 0, i;
+ int used;
+ int index;
+ int num_samples = sync->num_samples;
+
+ if (num_samples > sizeof(buffer)/sizeof(buffer[0])) {
+ samples = kmalloc(sizeof(*samples) * num_samples, GFP_ATOMIC);
+ if (!samples) {
+ samples = buffer;
+ num_samples = sizeof(buffer)/sizeof(buffer[0]);
+ }
+ } else {
+ samples = buffer;
+ }
+
+ /* run until we have enough valid samples, but do not try forever */
+ i = 0;
+ counter = 0;
+ while (1) {
+ u64 ts;
+ ktime_t start, end;
+
+ start = sync->target();
+ ts = timecounter_read(sync->source);
+ end = sync->target();
+
+ if (!i)
+ start_source = ts;
+
+ /* ignore negative durations */
+ sample.duration_target = ktime_to_ns(ktime_sub(end, start));
+ if (sample.duration_target >= 0) {
+ /*
+ * assume symetric delay to and from source:
+ * average target time corresponds to measured
+ * source time
+ */
+ sample.offset =
+ ktime_to_ns(ktime_add(end, start)) / 2 -
+ ts;
+
+ /* simple insertion sort based on duration */
+ index = counter - 1;
+ while (index >= 0) {
+ if (samples[index].duration_target <
+ sample.duration_target)
+ break;
+ samples[index + 1] = samples[index];
+ index--;
+ }
+ samples[index + 1] = sample;
+ counter++;
+ }
+
+ i++;
+ if (counter >= num_samples || i >= 100000) {
+ end_source = ts;
+ break;
+ }
+ }
+
+ *source_tstamp = (end_source + start_source) / 2;
+
+ /* remove outliers by only using 75% of the samples */
+ used = counter * 3 / 4;
+ if (!used)
+ used = counter;
+ if (used) {
+ /* calculate average */
+ s64 off = 0;
+ for (index = 0; index < used; index++)
+ off += samples[index].offset;
+ *offset = div_s64(off, used);
+ }
+
+ if (samples && samples != buffer)
+ kfree(samples);
+
+ return used;
+}
+EXPORT_SYMBOL_GPL(timecompare_offset);
+
+void __timecompare_update(struct timecompare *sync,
+ u64 source_tstamp)
+{
+ s64 offset;
+ u64 average_time;
+
+ if (!timecompare_offset(sync, &offset, &average_time))
+ return;
+
+ if (!sync->last_update) {
+ sync->last_update = average_time;
+ sync->offset = offset;
+ sync->skew = 0;
+ } else {
+ s64 delta_nsec = average_time - sync->last_update;
+
+ /* avoid division by negative or small deltas */
+ if (delta_nsec >= 10000) {
+ s64 delta_offset_nsec = offset - sync->offset;
+ s64 skew; /* delta_offset_nsec *
+ TIMECOMPARE_SKEW_RESOLUTION /
+ delta_nsec */
+ u64 divisor;
+
+ /* div_s64() is limited to 32 bit divisor */
+ skew = delta_offset_nsec * TIMECOMPARE_SKEW_RESOLUTION;
+ divisor = delta_nsec;
+ while (unlikely(divisor >= ((s64)1) << 32)) {
+ /* divide both by 2; beware, right shift
+ of negative value has undefined
+ behavior and can only be used for
+ the positive divisor */
+ skew = div_s64(skew, 2);
+ divisor >>= 1;
+ }
+ skew = div_s64(skew, divisor);
+
+ /*
+ * Calculate new overall skew as 4/16 the
+ * old value and 12/16 the new one. This is
+ * a rather arbitrary tradeoff between
+ * only using the latest measurement (0/16 and
+ * 16/16) and even more weight on past measurements.
+ */
+#define TIMECOMPARE_NEW_SKEW_PER_16 12
+ sync->skew =
+ div_s64((16 - TIMECOMPARE_NEW_SKEW_PER_16) *
+ sync->skew +
+ TIMECOMPARE_NEW_SKEW_PER_16 * skew,
+ 16);
+ sync->last_update = average_time;
+ sync->offset = offset;
+ }
+ }
+}
+EXPORT_SYMBOL_GPL(__timecompare_update);
diff --git a/pool/shard000/C/0008729_dot.c b/pool/shard000/C/0008729_dot.c
new file mode 100644
index 0000000000000000000000000000000000000000..808da43ba3bc4c921275417c532fd43f68a26e59
--- /dev/null
+++ b/pool/shard000/C/0008729_dot.c
@@ -0,0 +1,245 @@
+/*
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+% %
+% %
+% %
+% DDDD OOO TTTTT %
+% D D O O T %
+% D D O O T %
+% D D O O T %
+% DDDD OOO T %
+% %
+% %
+% Read/Write Graphviz DOT Format %
+% %
+% Software Design %
+% Cristy %
+% July 1992 %
+% %
+% %
+% Copyright 1999-2015 ImageMagick Studio LLC, a non-profit organization %
+% dedicated to making software imaging solutions freely available. %
+% %
+% You may not use this file except in compliance with the License. You may %
+% obtain a copy of the License at %
+% %
+% http://www.imagemagick.org/script/license.php %
+% %
+% 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 declarations.
+*/
+#include "magick/studio.h"
+#include "magick/blob.h"
+#include "magick/blob-private.h"
+#include "magick/client.h"
+#include "magick/constitute.h"
+#include "magick/exception.h"
+#include "magick/exception-private.h"
+#include "magick/image.h"
+#include "magick/image-private.h"
+#include "magick/list.h"
+#include "magick/magick.h"
+#include "magick/memory_.h"
+#include "magick/monitor.h"
+#include "magick/monitor-private.h"
+#include "magick/option.h"
+#include "magick/pixel-accessor.h"
+#include "magick/quantum-private.h"
+#include "magick/resource_.h"
+#include "magick/static.h"
+#include "magick/string_.h"
+#include "magick/module.h"
+#include "magick/utility.h"
+#include "magick/xwindow-private.h"
+#if defined(MAGICKCORE_GVC_DELEGATE)
+#undef HAVE_CONFIG_H
+#include
+static GVC_t
+ *graphic_context;
+#endif
+
+#if defined(MAGICKCORE_GVC_DELEGATE)
+/*
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+% %
+% %
+% %
+% R e a d D O T I m a g e %
+% %
+% %
+% %
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+%
+% ReadDOTImage() reads a Graphviz image file and returns it. It allocates
+% the memory necessary for the new Image structure and returns a pointer to
+% the new image.
+%
+% The format of the ReadDOTImage method is:
+%
+% Image *ReadDOTImage(const ImageInfo *image_info,ExceptionInfo *exception)
+%
+% A description of each parameter follows:
+%
+% o image_info: the image info.
+%
+% o exception: return any errors or warnings in this structure.
+%
+*/
+static Image *ReadDOTImage(const ImageInfo *image_info,ExceptionInfo *exception)
+{
+ char
+ command[MaxTextExtent];
+
+ const char
+ *option;
+
+ graph_t
+ *graph;
+
+ Image
+ *image;
+
+ ImageInfo
+ *read_info;
+
+ MagickBooleanType
+ status;
+
+ /*
+ Open image file.
+ */
+ assert(image_info != (const ImageInfo *) NULL);
+ assert(image_info->signature == MagickSignature);
+ if (image_info->debug != MagickFalse)
+ (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
+ image_info->filename);
+ assert(exception != (ExceptionInfo *) NULL);
+ assert(exception->signature == MagickSignature);
+ image=AcquireImage(image_info);
+ status=OpenBlob(image_info,image,ReadBinaryBlobMode,exception);
+ if (status == MagickFalse)
+ return((Image *) NULL);
+ read_info=CloneImageInfo(image_info);
+ SetImageInfoBlob(read_info,(void *) NULL,0);
+ (void) CopyMagickString(read_info->magick,"SVG",MaxTextExtent);
+ (void) AcquireUniqueFilename(read_info->filename);
+ (void) FormatLocaleString(command,MaxTextExtent,"-Tsvg -o%s %s",
+ read_info->filename,image_info->filename);
+#if !defined(WITH_CGRAPH)
+ graph=agread(GetBlobFileHandle(image));
+#else
+ graph=agread(GetBlobFileHandle(image),(Agdisc_t *) NULL);
+#endif
+ if (graph == (graph_t *) NULL)
+ {
+ (void) RelinquishUniqueFileResource(read_info->filename);
+ return ((Image *) NULL);
+ }
+ option=GetImageOption(image_info,"dot:layout-engine");
+ if (option == (const char *) NULL)
+ gvLayout(graphic_context,graph,(char *) "dot");
+ else
+ gvLayout(graphic_context,graph,(char *) option);
+ gvRenderFilename(graphic_context,graph,(char *) "svg",read_info->filename);
+ gvFreeLayout(graphic_context,graph);
+ agclose(graph);
+ /*
+ Read SVG graph.
+ */
+ image=ReadImage(read_info,exception);
+ (void) RelinquishUniqueFileResource(read_info->filename);
+ read_info=DestroyImageInfo(read_info);
+ if (image == (Image *) NULL)
+ return((Image *) NULL);
+ return(GetFirstImageInList(image));
+}
+#endif
+
+/*
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+% %
+% %
+% %
+% R e g i s t e r D O T I m a g e %
+% %
+% %
+% %
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+%
+% RegisterDOTImage() adds attributes for the Display Postscript image
+% format to the list of supported formats. The attributes include the image
+% format tag, a method to read and/or write the format, whether the format
+% supports the saving of more than one frame to the same file or blob,
+% whether the format supports native in-memory I/O, and a brief
+% description of the format.
+%
+% The format of the RegisterDOTImage method is:
+%
+% size_t RegisterDOTImage(void)
+%
+*/
+ModuleExport size_t RegisterDOTImage(void)
+{
+ MagickInfo
+ *entry;
+
+ entry=SetMagickInfo("DOT");
+#if defined(MAGICKCORE_GVC_DELEGATE)
+ entry->decoder=(DecodeImageHandler *) ReadDOTImage;
+#endif
+ entry->blob_support=MagickFalse;
+ entry->description=ConstantString("Graphviz");
+ entry->module=ConstantString("DOT");
+ (void) RegisterMagickInfo(entry);
+ entry=SetMagickInfo("GV");
+#if defined(MAGICKCORE_GVC_DELEGATE)
+ entry->decoder=(DecodeImageHandler *) ReadDOTImage;
+#endif
+ entry->blob_support=MagickFalse;
+ entry->description=ConstantString("Graphviz");
+ entry->module=ConstantString("DOT");
+ (void) RegisterMagickInfo(entry);
+#if defined(MAGICKCORE_GVC_DELEGATE)
+ graphic_context=gvContext();
+#endif
+ return(MagickImageCoderSignature);
+}
+
+/*
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+% %
+% %
+% %
+% U n r e g i s t e r D O T I m a g e %
+% %
+% %
+% %
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+%
+% UnregisterDOTImage() removes format registrations made by the
+% DOT module from the list of supported formats.
+%
+% The format of the UnregisterDOTImage method is:
+%
+% UnregisterDOTImage(void)
+%
+*/
+ModuleExport void UnregisterDOTImage(void)
+{
+ (void) UnregisterMagickInfo("GV");
+ (void) UnregisterMagickInfo("DOT");
+#if defined(MAGICKCORE_GVC_DELEGATE)
+ gvFreeContext(graphic_context);
+#endif
+}
diff --git a/pool/shard000/C/0008746_CWE122_Heap_Based_Buffer_Overflow__c_CWE805_int64_t_loop_66b.c b/pool/shard000/C/0008746_CWE122_Heap_Based_Buffer_Overflow__c_CWE805_int64_t_loop_66b.c
new file mode 100644
index 0000000000000000000000000000000000000000..b6027fc41c0b48ab66e4e90a6a258a94c4db273a
--- /dev/null
+++ b/pool/shard000/C/0008746_CWE122_Heap_Based_Buffer_Overflow__c_CWE805_int64_t_loop_66b.c
@@ -0,0 +1,63 @@
+/* TEMPLATE GENERATED TESTCASE FILE
+Filename: CWE122_Heap_Based_Buffer_Overflow__c_CWE805_int64_t_loop_66b.c
+Label Definition File: CWE122_Heap_Based_Buffer_Overflow__c_CWE805.label.xml
+Template File: sources-sink-66b.tmpl.c
+*/
+/*
+ * @description
+ * CWE: 122 Heap Based Buffer Overflow
+ * BadSource: Allocate using malloc() and set data pointer to a small buffer
+ * GoodSource: Allocate using malloc() and set data pointer to a large buffer
+ * Sinks: loop
+ * BadSink : Copy int64_t array to data using a loop
+ * Flow Variant: 66 Data flow: data passed in an array from one function to another in different source files
+ *
+ * */
+
+#include "std_testcase.h"
+
+#ifndef OMITBAD
+
+void CWE122_Heap_Based_Buffer_Overflow__c_CWE805_int64_t_loop_66b_badSink(int64_t * dataArray[])
+{
+ /* copy data out of dataArray */
+ int64_t * data = dataArray[2];
+ {
+ int64_t source[100] = {0}; /* fill with 0's */
+ {
+ size_t i;
+ /* POTENTIAL FLAW: Possible buffer overflow if data < 100 */
+ for (i = 0; i < 100; i++)
+ {
+ data[i] = source[i];
+ }
+ printLongLongLine(data[0]);
+ free(data);
+ }
+ }
+}
+
+#endif /* OMITBAD */
+
+#ifndef OMITGOOD
+
+/* goodG2B uses the GoodSource with the BadSink */
+void CWE122_Heap_Based_Buffer_Overflow__c_CWE805_int64_t_loop_66b_goodG2BSink(int64_t * dataArray[])
+{
+ int64_t * data = dataArray[2];
+ {
+ int64_t source[100] = {0}; /* fill with 0's */
+ {
+ size_t i;
+ /* POTENTIAL FLAW: Possible buffer overflow if data < 100 */
+ for (i = 0; i < 100; i++)
+ {
+ data[i] = source[i];
+ }
+ printLongLongLine(data[0]);
+ free(data);
+ }
+ }
+}
+
+#endif /* OMITGOOD */
diff --git a/pool/shard000/C/0008767_test.c b/pool/shard000/C/0008767_test.c
new file mode 100644
index 0000000000000000000000000000000000000000..13a82d6290cd9bcc9da2780aa52665c6c9a6c74f
--- /dev/null
+++ b/pool/shard000/C/0008767_test.c
@@ -0,0 +1,215 @@
+//
+// $Id: test.c 1682 2009-02-05 01:07:09Z shodan $
+//
+
+//
+// Copyright (c) 2008, Andrew Aksyonoff. All rights reserved.
+//
+// This program is free software; you can redistribute it and/or modify
+// it under the terms of the GNU Library General Public License. You should
+// have received a copy of the LGPL license along with this program; if you
+// did not, you can find it at http://www.gnu.org/
+//
+
+#include
+#include
+#include
+
+#if _WIN32
+#include
+#endif
+
+#include "sphinxclient.h"
+
+void die ( const char * template, ... )
+{
+ va_list ap;
+ va_start ( ap, template );
+ printf ( "FATAL: " );
+ vprintf ( template, ap );
+ printf ( "\n" );
+ va_end ( ap );
+ exit ( 1 );
+}
+
+
+void net_init ()
+{
+#if _WIN32
+ // init WSA on Windows
+ WSADATA wsa_data;
+ int wsa_startup_err;
+
+ wsa_startup_err = WSAStartup ( WINSOCK_VERSION, &wsa_data );
+ if ( wsa_startup_err )
+ die ( "failed to initialize WinSock2: error %d", wsa_startup_err );
+#endif
+}
+
+
+void test_query ( sphinx_client * client, sphinx_bool test_extras )
+{
+ sphinx_result * res;
+ const char *query, *index;
+ int i, j, k;
+ unsigned int * mva;
+ const char * field_names[2];
+ int field_weights[2];
+
+ sphinx_uint64_t override_docid = 4;
+ unsigned int override_value = 456;
+
+ query = "test";
+ index = "test1";
+
+ field_names[0] = "title";
+ field_names[1] = "content";
+ field_weights[0] = 100;
+ field_weights[1] = 1;
+ sphinx_set_field_weights ( client, 2, field_names, field_weights );
+ field_weights[0] = 1;
+ field_weights[1] = 1;
+
+ if ( test_extras )
+ {
+ sphinx_add_override ( client, "group_id", &override_docid, 1, &override_value );
+ sphinx_set_select ( client, "*, group_id*1000+@id*10 AS q" );
+ }
+
+ res = sphinx_query ( client, query, index, NULL );
+ if ( !res )
+ die ( "query failed: %s", sphinx_error(client) );
+
+ printf ( "Query '%s' retrieved %d of %d matches in %d.%03d sec.\n",
+ query, res->total, res->total_found, res->time_msec/1000, res->time_msec%1000 );
+ printf ( "Query stats:\n" );
+ for ( i=0; inum_words; i++ )
+ printf ( "\t'%s' found %d times in %d documents\n",
+ res->words[i].word, res->words[i].hits, res->words[i].docs );
+
+ printf ( "\nMatches:\n" );
+ for ( i=0; inum_matches; i++ )
+ {
+ printf ( "%d. doc_id=%d, weight=%d", 1+i,
+ (int)sphinx_get_id ( res, i ), sphinx_get_weight ( res, i ) );
+
+ for ( j=0; jnum_attrs; j++ )
+ {
+ printf ( ", %s=", res->attr_names[j] );
+ switch ( res->attr_types[j] )
+ {
+ case SPH_ATTR_MULTI | SPH_ATTR_INTEGER:
+ mva = sphinx_get_mva ( res, i, j );
+ printf ( "(" );
+ for ( k=0; k<(int)mva[0]; k++ )
+ printf ( k ? ",%u" : "%u", mva[1+k] );
+ printf ( ")" );
+ break;
+
+ case SPH_ATTR_FLOAT: printf ( "%f", sphinx_get_float ( res, i, j ) ); break;
+ default: printf ( "%u", (unsigned int)sphinx_get_int ( res, i, j ) ); break;
+ }
+ }
+
+ printf ( "\n" );
+ }
+ printf ( "\n" );
+}
+
+
+void test_excerpt ( sphinx_client * client )
+{
+ const char * docs[] =
+ {
+ "this is my test text to be highlighted, and for the sake of the testing we need to pump its length somewhat",
+ "another test text to be highlighted, below limit",
+ "test number three, without phrase match",
+ "final test, not only without phrase match, but also above limit and with swapped phrase text test as well"
+ };
+ const int ndocs = sizeof(docs)/sizeof(docs[0]);
+ const char * words = "test text";
+ const char * index = "test1";
+ sphinx_excerpt_options opts;
+ char ** res;
+ int i, j;
+
+ sphinx_init_excerpt_options ( &opts );
+ opts.limit = 60;
+ opts.around = 3;
+
+ for ( j=0; j<2; j++ )
+ {
+ opts.exact_phrase = j;
+ printf ( "exact_phrase=%d\n", j );
+
+ res = sphinx_build_excerpts ( client, ndocs, docs, index, words, &opts );
+ if ( !res )
+ die ( "query failed: %s", sphinx_error(client) );
+
+ for ( i=0; i
+ *
+ * Based on aesni-intel_glue.c by:
+ * Copyright (C) 2008, Intel Corp.
+ * Author: Huang Ying
+ *
+ * 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.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
+ * USA
+ *
+ */
+
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+
+int ablk_set_key(struct crypto_ablkcipher *tfm, const u8 *key,
+ unsigned int key_len)
+{
+ struct async_helper_ctx *ctx = crypto_ablkcipher_ctx(tfm);
+ struct crypto_ablkcipher *child = &ctx->cryptd_tfm->base;
+ int err;
+
+ crypto_ablkcipher_clear_flags(child, CRYPTO_TFM_REQ_MASK);
+ crypto_ablkcipher_set_flags(child, crypto_ablkcipher_get_flags(tfm)
+ & CRYPTO_TFM_REQ_MASK);
+ err = crypto_ablkcipher_setkey(child, key, key_len);
+ crypto_ablkcipher_set_flags(tfm, crypto_ablkcipher_get_flags(child)
+ & CRYPTO_TFM_RES_MASK);
+ return err;
+}
+EXPORT_SYMBOL_GPL(ablk_set_key);
+
+int __ablk_encrypt(struct ablkcipher_request *req)
+{
+ struct crypto_ablkcipher *tfm = crypto_ablkcipher_reqtfm(req);
+ struct async_helper_ctx *ctx = crypto_ablkcipher_ctx(tfm);
+ struct blkcipher_desc desc;
+
+ desc.tfm = cryptd_ablkcipher_child(ctx->cryptd_tfm);
+ desc.info = req->info;
+ desc.flags = 0;
+
+ return crypto_blkcipher_crt(desc.tfm)->encrypt(
+ &desc, req->dst, req->src, req->nbytes);
+}
+EXPORT_SYMBOL_GPL(__ablk_encrypt);
+
+int ablk_encrypt(struct ablkcipher_request *req)
+{
+ struct crypto_ablkcipher *tfm = crypto_ablkcipher_reqtfm(req);
+ struct async_helper_ctx *ctx = crypto_ablkcipher_ctx(tfm);
+
+ if (!may_use_simd()) {
+ struct ablkcipher_request *cryptd_req =
+ ablkcipher_request_ctx(req);
+
+ memcpy(cryptd_req, req, sizeof(*req));
+ ablkcipher_request_set_tfm(cryptd_req, &ctx->cryptd_tfm->base);
+
+ return crypto_ablkcipher_encrypt(cryptd_req);
+ } else {
+ return __ablk_encrypt(req);
+ }
+}
+EXPORT_SYMBOL_GPL(ablk_encrypt);
+
+int ablk_decrypt(struct ablkcipher_request *req)
+{
+ struct crypto_ablkcipher *tfm = crypto_ablkcipher_reqtfm(req);
+ struct async_helper_ctx *ctx = crypto_ablkcipher_ctx(tfm);
+
+ if (!may_use_simd()) {
+ struct ablkcipher_request *cryptd_req =
+ ablkcipher_request_ctx(req);
+
+ memcpy(cryptd_req, req, sizeof(*req));
+ ablkcipher_request_set_tfm(cryptd_req, &ctx->cryptd_tfm->base);
+
+ return crypto_ablkcipher_decrypt(cryptd_req);
+ } else {
+ struct blkcipher_desc desc;
+
+ desc.tfm = cryptd_ablkcipher_child(ctx->cryptd_tfm);
+ desc.info = req->info;
+ desc.flags = 0;
+
+ return crypto_blkcipher_crt(desc.tfm)->decrypt(
+ &desc, req->dst, req->src, req->nbytes);
+ }
+}
+EXPORT_SYMBOL_GPL(ablk_decrypt);
+
+void ablk_exit(struct crypto_tfm *tfm)
+{
+ struct async_helper_ctx *ctx = crypto_tfm_ctx(tfm);
+
+ cryptd_free_ablkcipher(ctx->cryptd_tfm);
+}
+EXPORT_SYMBOL_GPL(ablk_exit);
+
+int ablk_init_common(struct crypto_tfm *tfm, const char *drv_name)
+{
+ struct async_helper_ctx *ctx = crypto_tfm_ctx(tfm);
+ struct cryptd_ablkcipher *cryptd_tfm;
+
+ cryptd_tfm = cryptd_alloc_ablkcipher(drv_name, 0, 0);
+ if (IS_ERR(cryptd_tfm))
+ return PTR_ERR(cryptd_tfm);
+
+ ctx->cryptd_tfm = cryptd_tfm;
+ tfm->crt_ablkcipher.reqsize = sizeof(struct ablkcipher_request) +
+ crypto_ablkcipher_reqsize(&cryptd_tfm->base);
+
+ return 0;
+}
+EXPORT_SYMBOL_GPL(ablk_init_common);
+
+int ablk_init(struct crypto_tfm *tfm)
+{
+ char drv_name[CRYPTO_MAX_ALG_NAME];
+
+ snprintf(drv_name, sizeof(drv_name), "__driver-%s",
+ crypto_tfm_alg_driver_name(tfm));
+
+ return ablk_init_common(tfm, drv_name);
+}
+EXPORT_SYMBOL_GPL(ablk_init);
+
+MODULE_LICENSE("GPL");
diff --git a/pool/shard000/C/0008799_aotrigger.c b/pool/shard000/C/0008799_aotrigger.c
new file mode 100644
index 0000000000000000000000000000000000000000..b568fc5c9e3fd3c91238ce17e48d588398a33736
--- /dev/null
+++ b/pool/shard000/C/0008799_aotrigger.c
@@ -0,0 +1,94 @@
+/*
+gcc -DNIDAQ_MAJOR=254 -o aotrigger aotrigger.c -lm
+*/
+
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include "nidaq.h"
+
+
+#define MAXPOINTS 600
+#define MAXBUFFERS 40
+#define UPDATERATE 100000
+#define PERIOD 200
+
+
+void AO_add_channel( int fd, int channel, int bipolar,
+ int reglitch, int extref, int groundref )
+{
+ unsigned int u = 0;
+
+ if ( bipolar )
+ u |= 0x0001;
+
+ if ( reglitch )
+ u |= 0x0002;
+
+ if ( extref )
+ u |= 0x0004;
+
+ if ( groundref )
+ u |= 0x0008;
+
+ channel &= 0x1;
+ u |= channel << 8;
+
+ fprintf( stderr, "added channel %d\n", channel );
+
+ ioctl( fd, NIDAQAOADDCHANNEL, u );
+}
+
+
+void init_sine( signed short buf[], int n )
+{
+ int k;
+
+ for ( k=0; k= n) {
+ int orig_len = strlen(dest);
+ int n2=0;
+
+ n2 = n-1;
+ buf = strncat(dest, src, n2);
+ dest[orig_len+n-1] = '\0';
+ }
+ else {
+ buf = strncat(dest, src, n);
+ }
+
+
+ return buf;
+}
+
+char *sz_strncpy(char *dest, const char *src, size_t n)
+{
+ char *buf=NULL;
+
+ if (n < 0) {
+ warn("n is %d. setting it 0", (int)n);
+ n = 0;
+ }
+
+ buf = strncpy(dest, src, n);
+ dest[n-1] = '\0';
+
+ return buf;
+}
+
+int sz_snprintf(char *str, size_t size, const char *format, ...)
+{
+ int rv=0;
+ va_list args;
+
+ if (size < 0) {
+ warn("size is %d. setting it 0", (int)size);
+ size = 0;
+ }
+
+ va_start(args, format);
+ rv = vsnprintf(str, size, format, args);
+ va_end(args);
+
+ str[size-1] = '\0';
+
+ return rv;
+}
diff --git a/pool/shard000/C/0008812_bigdict.c b/pool/shard000/C/0008812_bigdict.c
new file mode 100644
index 0000000000000000000000000000000000000000..fb0892586908601d34c74b32e13f587e1ac5e5dc
--- /dev/null
+++ b/pool/shard000/C/0008812_bigdict.c
@@ -0,0 +1,128 @@
+/*
+ * Copyright (c) Yann Collet, Facebook, Inc.
+ * All rights reserved.
+ *
+ * This source code is licensed under both the BSD-style license (found in the
+ * LICENSE file in the root directory of this source tree) and the GPLv2 (found
+ * in the COPYING file in the root directory of this source tree).
+ * You may select, at your option, one of the above-listed licenses.
+ */
+
+#include
+#include
+#include
+#include
+#include
+#include "datagen.h"
+#include "mem.h"
+#define ZSTD_STATIC_LINKING_ONLY
+#include "zstd.h"
+
+static int
+compress(ZSTD_CCtx* cctx, ZSTD_DCtx* dctx,
+ void* dst, size_t dstCapacity,
+ void const* src, size_t srcSize,
+ void* roundtrip, ZSTD_EndDirective end)
+{
+ ZSTD_inBuffer in = {src, srcSize, 0};
+ ZSTD_outBuffer out = {dst, dstCapacity, 0};
+ int ended = 0;
+
+ while (!ended && (in.pos < in.size || out.pos > 0)) {
+ size_t rc;
+ out.pos = 0;
+ rc = ZSTD_compressStream2(cctx, &out, &in, end);
+ if (ZSTD_isError(rc))
+ return 1;
+ if (end == ZSTD_e_end && rc == 0)
+ ended = 1;
+ {
+ ZSTD_inBuffer rtIn = {dst, out.pos, 0};
+ ZSTD_outBuffer rtOut = {roundtrip, srcSize, 0};
+ rc = 1;
+ while (rtIn.pos < rtIn.size || rtOut.pos > 0) {
+ rtOut.pos = 0;
+ rc = ZSTD_decompressStream(dctx, &rtOut, &rtIn);
+ if (ZSTD_isError(rc)) {
+ fprintf(stderr, "Decompression error: %s\n", ZSTD_getErrorName(rc));
+ return 1;
+ }
+ if (rc == 0)
+ break;
+ }
+ if (ended && rc != 0) {
+ fprintf(stderr, "Frame not finished!\n");
+ return 1;
+ }
+ }
+ }
+
+ return 0;
+}
+
+int main(int argc, const char** argv)
+{
+ ZSTD_CCtx* cctx = ZSTD_createCCtx();
+ ZSTD_DCtx* dctx = ZSTD_createDCtx();
+ const size_t dataSize = (size_t)1 << 30;
+ const size_t outSize = ZSTD_compressBound(dataSize);
+ const size_t bufferSize = (size_t)1 << 31;
+ char* buffer = (char*)malloc(bufferSize);
+ void* out = malloc(outSize);
+ void* roundtrip = malloc(dataSize);
+ (void)argc;
+ (void)argv;
+
+ if (!buffer || !out || !roundtrip || !cctx || !dctx) {
+ fprintf(stderr, "Allocation failure\n");
+ return 1;
+ }
+
+ if (ZSTD_isError(ZSTD_CCtx_setParameter(cctx, ZSTD_c_windowLog, 31)))
+ return 1;
+ if (ZSTD_isError(ZSTD_CCtx_setParameter(cctx, ZSTD_c_nbWorkers, 1)))
+ return 1;
+ if (ZSTD_isError(ZSTD_CCtx_setParameter(cctx, ZSTD_c_overlapLog, 9)))
+ return 1;
+ if (ZSTD_isError(ZSTD_CCtx_setParameter(cctx, ZSTD_c_checksumFlag, 1)))
+ return 1;
+ if (ZSTD_isError(ZSTD_CCtx_setParameter(cctx, ZSTD_c_strategy, ZSTD_btopt)))
+ return 1;
+ if (ZSTD_isError(ZSTD_CCtx_setParameter(cctx, ZSTD_c_targetLength, 7)))
+ return 1;
+ if (ZSTD_isError(ZSTD_CCtx_setParameter(cctx, ZSTD_c_minMatch, 7)))
+ return 1;
+ if (ZSTD_isError(ZSTD_CCtx_setParameter(cctx, ZSTD_c_searchLog, 1)))
+ return 1;
+ if (ZSTD_isError(ZSTD_CCtx_setParameter(cctx, ZSTD_c_hashLog, 10)))
+ return 1;
+ if (ZSTD_isError(ZSTD_CCtx_setParameter(cctx, ZSTD_c_chainLog, 10)))
+ return 1;
+
+ if (ZSTD_isError(ZSTD_DCtx_setParameter(dctx, ZSTD_d_windowLogMax, 31)))
+ return 1;
+
+ RDG_genBuffer(buffer, bufferSize, 1.0, 0.0, 0xbeefcafe);
+
+ /* Compress 30 GB */
+ {
+ int i;
+ for (i = 0; i < 10; ++i) {
+ fprintf(stderr, "Compressing 1 GB\n");
+ if (compress(cctx, dctx, out, outSize, buffer, dataSize, roundtrip, ZSTD_e_continue))
+ return 1;
+ }
+ }
+ fprintf(stderr, "Compressing 1 GB\n");
+ if (compress(cctx, dctx, out, outSize, buffer, dataSize, roundtrip, ZSTD_e_end))
+ return 1;
+
+ fprintf(stderr, "Success!\n");
+
+ free(roundtrip);
+ free(out);
+ free(buffer);
+ ZSTD_freeDCtx(dctx);
+ ZSTD_freeCCtx(cctx);
+ return 0;
+}
diff --git a/pool/shard000/C/0008813_xsiget.c b/pool/shard000/C/0008813_xsiget.c
new file mode 100644
index 0000000000000000000000000000000000000000..94cccee6c31ae3a9a6451625e2cd7f901d1617be
--- /dev/null
+++ b/pool/shard000/C/0008813_xsiget.c
@@ -0,0 +1,60 @@
+#include "../apue.h"
+
+#define USE_EXCL
+#define USE_FTOK
+
+#include
+#include
+#include
+
+int main (int argc, char *argv[])
+{
+ if (argc < 3)
+ {
+ printf ("Usage: xsiget type projid\n");
+ return -1;
+ }
+
+ char const* type = argv[1];
+ int id = atoi (argv[2]);
+
+ key_t key = IPC_PRIVATE;
+#ifdef USE_FTOK
+ key = ftok ("./xsiget.c", id);
+#endif
+
+ int flag = IPC_CREAT;
+#ifdef USE_EXCL
+ flag |= IPC_EXCL;
+#endif
+
+ if (strcasecmp (type, "msg") == 0)
+ {
+ int ret = msgget (key, flag);
+ if (ret < 0)
+ err_sys ("msgget failed");
+
+ printf ("create msgqueue %d with key 0x%08x ok\n", ret, key);
+ }
+ else if (strcasecmp (type, "sem") == 0)
+ {
+ int ret = semget (key, 1, flag);
+ if (ret < 0)
+ err_sys ("semget failed");
+
+ printf ("create semphore %d with key 0x%08x ok\n", ret, key);
+ }
+ else if (strcasecmp (type, "shm") == 0)
+ {
+ int ret = shmget (key, 1024, flag);
+ if (ret < 0)
+ err_sys ("shmget failed");
+
+ printf ("create share memory %d with key 0x%08x ok\n", ret, key);
+ }
+ else
+ printf ("unknown type %s\n", type);
+
+ //sleep (60);
+ return 0;
+}
diff --git a/pool/shard000/C/0008818_device.c b/pool/shard000/C/0008818_device.c
new file mode 100644
index 0000000000000000000000000000000000000000..ec04477dcdc432a0b8b59011b6ae07c3035f2457
--- /dev/null
+++ b/pool/shard000/C/0008818_device.c
@@ -0,0 +1,157 @@
+
+
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+
+#include
+#include
+
+#include
+
+#define GPIO3_INTNUM 3
+#define UART_INTNUM 4
+#define GMAC_INTNUM 5
+
+static const signed char gpio3_irq_mappings[] = {
+ S6_INTC_GPIO(3),
+ -1
+};
+
+static const signed char uart_irq_mappings[] = {
+ S6_INTC_UART(0),
+ S6_INTC_UART(1),
+ -1,
+};
+
+static const signed char gmac_irq_mappings[] = {
+ S6_INTC_GMAC_STAT,
+ S6_INTC_GMAC_ERR,
+ S6_INTC_DMA_HOSTTERMCNT(0),
+ S6_INTC_DMA_HOSTTERMCNT(1),
+ -1
+};
+
+const signed char *platform_irq_mappings[NR_IRQS] = {
+ [GPIO3_INTNUM] = gpio3_irq_mappings,
+ [UART_INTNUM] = uart_irq_mappings,
+ [GMAC_INTNUM] = gmac_irq_mappings,
+};
+
+static struct plat_serial8250_port serial_platform_data[] = {
+ {
+ .membase = (void *)S6_REG_UART + 0x0000,
+ .mapbase = S6_REG_UART + 0x0000,
+ .irq = UART_INTNUM,
+ .uartclk = S6_SCLK,
+ .regshift = 2,
+ .iotype = SERIAL_IO_MEM,
+ .flags = ASYNC_BOOT_AUTOCONF | ASYNC_SKIP_TEST,
+ },
+ {
+ .membase = (void *)S6_REG_UART + 0x1000,
+ .mapbase = S6_REG_UART + 0x1000,
+ .irq = UART_INTNUM,
+ .uartclk = S6_SCLK,
+ .regshift = 2,
+ .iotype = SERIAL_IO_MEM,
+ .flags = ASYNC_BOOT_AUTOCONF | ASYNC_SKIP_TEST,
+ },
+ { },
+};
+
+static struct resource s6_gmac_resource[] = {
+ {
+ .name = "mem",
+ .start = (resource_size_t)S6_REG_GMAC,
+ .end = (resource_size_t)S6_REG_GMAC + 0x10000 - 1,
+ .flags = IORESOURCE_MEM,
+ },
+ {
+ .name = "dma",
+ .start = (resource_size_t)
+ DMA_CHNL(S6_REG_HIFDMA, S6_HIFDMA_GMACTX),
+ .end = (resource_size_t)
+ DMA_CHNL(S6_REG_HIFDMA, S6_HIFDMA_GMACTX) + 0x100 - 1,
+ .flags = IORESOURCE_DMA,
+ },
+ {
+ .name = "dma",
+ .start = (resource_size_t)
+ DMA_CHNL(S6_REG_HIFDMA, S6_HIFDMA_GMACRX),
+ .end = (resource_size_t)
+ DMA_CHNL(S6_REG_HIFDMA, S6_HIFDMA_GMACRX) + 0x100 - 1,
+ .flags = IORESOURCE_DMA,
+ },
+ {
+ .name = "io",
+ .start = (resource_size_t)S6_MEM_GMAC,
+ .end = (resource_size_t)S6_MEM_GMAC + 0x2000000 - 1,
+ .flags = IORESOURCE_IO,
+ },
+ {
+ .name = "irq",
+ .start = (resource_size_t)GMAC_INTNUM,
+ .flags = IORESOURCE_IRQ,
+ },
+ {
+ .name = "irq",
+ .start = (resource_size_t)PHY_POLL,
+ .flags = IORESOURCE_IRQ,
+ },
+};
+
+static int __init prepare_phy_irq(int pin)
+{
+ int irq;
+ if (gpio_request(pin, "s6gmac_phy") < 0)
+ goto fail;
+ if (gpio_direction_input(pin) < 0)
+ goto free;
+ irq = gpio_to_irq(pin);
+ if (irq < 0)
+ goto free;
+ if (set_irq_type(irq, IRQ_TYPE_LEVEL_LOW) < 0)
+ goto free;
+ return irq;
+free:
+ gpio_free(pin);
+fail:
+ return PHY_POLL;
+}
+
+static struct platform_device platform_devices[] = {
+ {
+ .name = "serial8250",
+ .id = PLAT8250_DEV_PLATFORM,
+ .dev = {
+ .platform_data = serial_platform_data,
+ },
+ },
+ {
+ .name = "s6gmac",
+ .id = 0,
+ .resource = s6_gmac_resource,
+ .num_resources = ARRAY_SIZE(s6_gmac_resource),
+ },
+ {
+ I2C_BOARD_INFO("m41t62", S6I2C_ADDR_M41T62),
+ },
+};
+
+static int __init device_init(void)
+{
+ int i;
+
+ s6_gmac_resource[5].start = prepare_phy_irq(GPIO_PHY_IRQ);
+
+ for (i = 0; i < ARRAY_SIZE(platform_devices); i++)
+ platform_device_register(&platform_devices[i]);
+ return 0;
+}
+arch_initcall_sync(device_init);
diff --git a/pool/shard000/C/0008825_autotools-notebook-tab.c b/pool/shard000/C/0008825_autotools-notebook-tab.c
new file mode 100644
index 0000000000000000000000000000000000000000..978502ae3ad6fb2ad6c37c5b0bfdcfdd744f3b46
--- /dev/null
+++ b/pool/shard000/C/0008825_autotools-notebook-tab.c
@@ -0,0 +1,133 @@
+/*
+ * Copyright (C) 2010 - Jeff Johnston
+ *
+ * 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, or (at your option)
+ * any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ */
+
+#include "autotools-notebook-tab.h"
+#include
+
+static void autotools_notebook_tab_class_init (AutotoolsNotebookTabClass *klass);
+static void autotools_notebook_tab_init (AutotoolsNotebookTab *notebook_tab);
+static void autotools_notebook_tab_finalize (AutotoolsNotebookTab *notebook_tab);
+
+static void close_action (AutotoolsNotebookTab *notebook_tab);
+
+#define AUTOTOOLS_NOTEBOOK_TAB_GET_PRIVATE(obj) \
+ (G_TYPE_INSTANCE_GET_PRIVATE ((obj), AUTOTOOLS_NOTEBOOK_TAB_TYPE, AutotoolsNotebookTabPrivate))
+
+typedef struct _AutotoolsNotebookTabPrivate AutotoolsNotebookTabPrivate;
+
+struct _AutotoolsNotebookTabPrivate
+{
+ GtkWidget *notebook_page;
+ GtkWidget *notebook;
+};
+
+enum
+{
+ CLOSE,
+ LAST_SIGNAL
+};
+
+static guint autotools_notebook_tab_signals[LAST_SIGNAL] = { 0 };
+
+G_DEFINE_TYPE (AutotoolsNotebookTab, autotools_notebook_tab, GTK_TYPE_HBOX)
+
+static void
+autotools_notebook_tab_class_init (AutotoolsNotebookTabClass *klass)
+{
+ GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
+
+ autotools_notebook_tab_signals[CLOSE] =
+ g_signal_new ("close",
+ G_TYPE_FROM_CLASS (klass),
+ G_SIGNAL_RUN_LAST | G_SIGNAL_NO_RECURSE | G_SIGNAL_NO_HOOKS,
+ G_STRUCT_OFFSET (AutotoolsNotebookTabClass, close),
+ NULL, NULL,
+ g_cclosure_marshal_VOID__VOID, G_TYPE_NONE, 0);
+
+ gobject_class->finalize = (GObjectFinalizeFunc) autotools_notebook_tab_finalize;
+
+ g_type_class_add_private (klass, sizeof (AutotoolsNotebookTabPrivate));
+}
+
+static void
+autotools_notebook_tab_init (AutotoolsNotebookTab *notebook_tab)
+{
+ gtk_box_set_homogeneous (GTK_BOX (notebook_tab), FALSE);
+ gtk_box_set_spacing (GTK_BOX (notebook_tab), 0);
+}
+
+static void
+autotools_notebook_tab_finalize (AutotoolsNotebookTab *notebook_tab)
+{
+ G_OBJECT_CLASS (autotools_notebook_tab_parent_class)->finalize ( G_OBJECT (notebook_tab));
+}
+
+GtkWidget*
+autotools_notebook_tab_new (GtkWidget *notebook,
+ const gchar *label)
+{
+ AutotoolsNotebookTabPrivate *priv;
+ GtkWidget *notebook_tab;
+ GtkWidget *text;
+ GtkWidget *button;
+ GtkWidget *image;
+
+ notebook_tab = g_object_new (autotools_notebook_tab_get_type (), NULL);
+ priv = AUTOTOOLS_NOTEBOOK_TAB_GET_PRIVATE (notebook_tab);
+ priv->notebook = notebook;
+
+ text = gtk_label_new (label);
+
+ button = gtk_button_new ();
+
+ gtk_button_set_relief (GTK_BUTTON (button), GTK_RELIEF_NONE);
+ gtk_button_set_focus_on_click (GTK_BUTTON (button), FALSE);
+ image = gtk_image_new_from_stock (GTK_STOCK_CLOSE, GTK_ICON_SIZE_MENU);
+ gtk_container_add (GTK_CONTAINER (button), image);
+ codeslayer_utils_style_close_button (button);
+
+ g_signal_connect_swapped (G_OBJECT (button), "clicked",
+ G_CALLBACK (close_action), notebook_tab);
+
+ gtk_box_pack_start (GTK_BOX (notebook_tab), text, TRUE, TRUE, 1);
+
+ gtk_box_pack_start (GTK_BOX (notebook_tab), button, FALSE, FALSE, 1);
+
+ return notebook_tab;
+}
+
+static void
+close_action (AutotoolsNotebookTab *notebook_tab)
+{
+ g_signal_emit_by_name ((gpointer) notebook_tab, "close");
+}
+
+GtkWidget*
+autotools_notebook_tab_get_notebook_page (AutotoolsNotebookTab *notebook_tab)
+{
+ return AUTOTOOLS_NOTEBOOK_TAB_GET_PRIVATE (notebook_tab)->notebook_page;
+}
+
+void
+autotools_notebook_tab_set_notebook_page (AutotoolsNotebookTab *notebook_tab,
+ GtkWidget *notebook_page)
+{
+ AutotoolsNotebookTabPrivate *priv;
+ priv = AUTOTOOLS_NOTEBOOK_TAB_GET_PRIVATE (notebook_tab);
+ priv->notebook_page = notebook_page;
+}
diff --git a/pool/shard000/C/0008837_discard.c b/pool/shard000/C/0008837_discard.c
new file mode 100644
index 0000000000000000000000000000000000000000..8cf2fd1b5269add6a65db7a55e284971a9b03596
--- /dev/null
+++ b/pool/shard000/C/0008837_discard.c
@@ -0,0 +1,163 @@
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+
+/*
+ * Map handling: We have flexible paging. Each map table consists of a set of pages
+ * with the last page repeated to fill any holes.
+ */
+
+extern uint8_t internal32k;
+
+void pagemap_init(void)
+{
+ int i;
+
+ /* kernel uses 4 5 6 7 0 1 2 3F */
+ for (i = 0x3e; i > 7; i--)
+ pagemap_add(i);
+ pagemap_add(3); /* was used while loading, replaced by 3F */
+
+#ifdef SWAPDEV
+ for (i = 0; i < MAX_SWAPS; i++)
+ swapmap_init(i);
+#endif
+}
+
+uint8_t platform_param(char *p)
+{
+ return 0;
+}
+
+static const char *sysname[] = {"Dragon", "COCO", "COCO3", "Unknown"};
+
+struct cart_rom_id {
+ uint16_t hash;
+ uint8_t id;
+ const char *name;
+};
+
+static const char empty[] = "(empty)";
+
+struct cart_rom_id carts[] = {
+ { 0x72B0, CART_DRAGONDOS, "DragonDOS" },
+ { 0x9063, CART_DELTADOS, "DeltaDOS" },
+ { 0xB400, 0, empty },
+ { 0xC248, CART_RSDOS, "RS-DOS" },
+ /* This one is an oddity - we need to do more to know what it drives
+ The great thing is we can extract the MMIO addresses from it */
+ { 0xB61B, CART_HDBDOS, "HDBDOS" },
+ { 0xCF55, CART_HDBDOS, "HDBDOS" },
+ { 0xE1BA, CART_ORCH90, "Orchestra-90 CC" },
+ { 0x933E, CART_SDBOOT, "SDBOOT" },
+ { 0x0000, 0, "No ROM" }
+};
+
+struct hdb_rom_id {
+ char key[2];
+ uint8_t id;
+ const char *name;
+};
+
+static struct hdb_rom_id hdb[] = {
+ { "ID", CART_IDE, "IDE-CHS" },
+ { "LB", CART_IDE, "IDE-LBA" },
+ { "TC", CART_TC3, "TC^3" },
+ { "KE", CART_KENTON, "KENTON" },
+ { "LR", CART_LRTECH, "LRTECH" },
+ { "HD", CART_HDII, "HD-II" },
+ { "4-", CART_4N1, "4-N-1" },
+ { "DW", CART_DRIVEWIRE, "Drivewire" },
+ { "BE", CART_BECKER, "Becker" },
+ { "J&", CART_JMCP, "J&M CP" },
+ {}
+};
+
+/* Find a cartridge or it's slot */
+int cart_find(int id)
+{
+ int i;
+ for (i = 0; i < id; i++) {
+ if (carttype[i] == id)
+ return i;
+ }
+ return -1;
+}
+
+static struct cart_rom_id *cart_lookup(uint16_t hash)
+{
+ struct cart_rom_id *cart = carts;
+ do {
+ if (cart->hash == hash)
+ return cart;
+ } while(cart++->hash);
+ return NULL;
+}
+
+static inline int keycmp(uint16_t *k1, uint16_t *k2)
+{
+ return (*k1 == *k2);
+}
+
+static struct hdb_rom_id *hdb_lookup(uint16_t key)
+{
+ struct hdb_rom_id *id = hdb;
+ do {
+ if (keycmp(&key, (uint16_t *)id->key))
+ return id;
+ } while(id++->id);
+ return NULL;
+}
+
+void map_init(void)
+{
+ uint8_t i;
+ uint8_t bslot = 0;
+ uint16_t hash;
+ struct cart_rom_id *rom;
+
+ kprintf("%s system.\n", sysname[system_id]);
+ if (mpi_present()) {
+ kputs("MPI cartridge detected.\n");
+ cartslots = 4;
+ bootslot = mpi_set_slot(0);
+ bslot = bootslot & 3;
+ }
+ for (i = 0; i < cartslots; i++) {
+ mpi_set_slot((i << 4) | i);
+ hash = cart_hash();
+ rom = cart_lookup(hash);
+ if (rom) {
+ kprintf("%d:%c%s",
+ i, i == bslot ? '*':' ',
+ rom->name);
+ carttype[i] = rom->id;
+ }
+ else
+ kprintf("%d:%cUnknown(%x)",
+ i, i == bslot ? '*':' ', hash);
+
+ /* The analysis needs to be in asm as we need to page in
+ the ROM to peer at it */
+ if (rom->id == CART_HDBDOS) {
+ uint16_t t = cart_analyze_hdb();
+ struct hdb_rom_id *hdb = hdb_lookup(t);
+ if (hdb) {
+ kprintf(" %s ID %d",
+ hdb->name, hdb_id);
+ if (hdb->id == CART_IDE)
+ kprintf(" MMIO %x", hdb_port);
+ carttype[i] = hdb->id;
+ cartaddr[i] = hdb_port;
+ } else
+ kprintf("??%x\n", t);
+ }
+ kputchar('\n');
+ }
+ mpi_set_slot(bootslot);
+}
diff --git a/pool/shard000/C/0008848_demo.c b/pool/shard000/C/0008848_demo.c
new file mode 100644
index 0000000000000000000000000000000000000000..cc396ea57ee2f4033270532eac487a84dcc9fedd
--- /dev/null
+++ b/pool/shard000/C/0008848_demo.c
@@ -0,0 +1,106 @@
+ /*
+ Õâ·ÝdemoÓÃÓÚÑÝʾ»·Ðλº³åÇø
+ */
+#include
+#include "rtdevice.h" //for rt_ringbuffer
+#ifdef RT_USING_FINSH
+#include
+#include
+#endif
+
+
+
+static rt_sem_t sem = RT_NULL;
+
+static rt_uint8_t working_buffer[256];
+struct rt_ringbuffer rb;
+
+/* Ö¸ÏòÏ߳̿ØÖÆ¿éµÄÖ¸Õë */
+static rt_thread_t tid1 = RT_NULL;
+static rt_thread_t tid2 = RT_NULL;
+
+/* Ïß³Ì1Èë¿Ú */
+static void thread1_entry(void* parameter)
+{
+ rt_bool_t result=RT_FALSE;
+ rt_uint8_t data_buffer[33];
+ rt_uint32_t i = 1;
+
+ while(1)
+ {
+ rt_sem_take (sem,RT_WAITING_FOREVER);
+ rt_kprintf("th1 take sem\n");
+ result = rt_ringbuffer_get(&rb,&data_buffer[0],33);
+ rt_kprintf("th1 release sem\n");
+ rt_sem_release(sem);
+ //if(RT_TRUE==result)
+ if(RT_FALSE!=result)
+ {
+ rt_kprintf(" th1 read data buffer: %s\n",data_buffer);
+ }
+ rt_thread_delay(5);
+ }
+
+}
+
+/* Ïß³Ì2Èë¿Ú£¬Ïß³Ì2µÄÓÅÏȼ¶±ÈÏß³Ì1µÍ£¬Ó¦¸ÃÏß³Ì1ÏÈ»ñµÃÖ´ÐС£*/
+static void thread2_entry(void *parameter)
+{
+ rt_bool_t result=RT_FALSE;
+ rt_uint32_t index,setchar,i = 1;
+ rt_uint8_t data_buffer[33];
+
+ setchar = 0x21;
+ while(1)
+ {
+ for (index = 0; index < 32; index++)
+ {
+ data_buffer[index] = setchar;
+ if (++setchar == 0x7f)
+ {
+ setchar = 0x21;
+ }
+ }
+ data_buffer[32] = '\0';
+
+ rt_sem_take(sem,RT_WAITING_FOREVER);
+ rt_kprintf("th2 take sem\n");
+ result = rt_ringbuffer_put(&rb,&data_buffer[0],33);
+ // if(RT_TRUE==result)
+ if(RT_FALSE!=result)
+ {
+ rt_kprintf("th2 write buffer success!\n");
+ }
+ rt_kprintf("th2 realease sem\n");
+ rt_sem_release(sem);
+
+ rt_thread_delay(10);
+ }
+}
+
+int demo_init(void)
+{
+ rt_ringbuffer_init(&rb,working_buffer,256);
+
+ sem = rt_sem_create("sem",1,RT_IPC_FLAG_FIFO);
+ if (sem == RT_NULL)
+ {
+ return 0;
+ }
+
+ /* ´´½¨Ïß³Ì1 */
+ tid1 = rt_thread_create("t1",
+ thread1_entry, RT_NULL, /* Ïß³ÌÈë¿ÚÊÇthread1_entry, Èë¿Ú²ÎÊýÊÇRT_NULL */
+ 512, 8, 10);
+ if (tid1 != RT_NULL)
+ rt_thread_startup(tid1);
+
+ /* ´´½¨Ïß³Ì2 */
+ tid2 = rt_thread_create("t2",
+ thread2_entry, RT_NULL, /* Ïß³ÌÈë¿ÚÊÇthread2_entry, Èë¿Ú²ÎÊýÊÇRT_NULL */
+ 512, 7, 10);
+ if (tid2 != RT_NULL)
+ rt_thread_startup(tid2);
+
+ return 0;
+}
diff --git a/pool/shard000/C/0008854_mountpoints.c b/pool/shard000/C/0008854_mountpoints.c
new file mode 100644
index 0000000000000000000000000000000000000000..f1d35dd13a2f2da61f34d2b860f6054d8e6f7d9b
--- /dev/null
+++ b/pool/shard000/C/0008854_mountpoints.c
@@ -0,0 +1,121 @@
+#include
+#include
+#include
+#include
+#include
+
+#include "zdtmtst.h"
+
+const char *test_doc = "Check that mountpoints (in mount namespace) are supported";
+const char *test_author = "Pavel Emelianov ";
+
+#define MPTS_ROOT "/zdtm_mpts/"
+
+static char buf[1024];
+
+static int test_fn(int argc, char **argv)
+{
+ FILE *f;
+ int fd, tmpfs_fd;
+ unsigned fs_cnt, fs_cnt_last = 0;
+
+again:
+ fs_cnt = 0;
+ f = fopen("/proc/self/mountinfo", "r");
+ if (!f) {
+ fail("Can't open mountinfo");
+ return -1;
+ }
+
+ while (fgets(buf, sizeof(buf), f) != NULL) {
+ char *mp = buf, *end;
+
+ mp = strchr(mp, ' ') + 1;
+ mp = strchr(mp, ' ') + 1;
+ mp = strchr(mp, ' ') + 1;
+ mp = strchr(mp, ' ') + 1;
+ end = strchr(mp, ' ');
+ *end = '\0';
+
+ if (!strcmp(mp, "/"))
+ continue;
+ if (!strcmp(mp, "/proc"))
+ continue;
+
+ umount(mp);
+ fs_cnt++;
+ }
+
+ fclose(f);
+
+ if (fs_cnt == 0)
+ goto done;
+
+ if (fs_cnt != fs_cnt_last) {
+ fs_cnt_last = fs_cnt;
+ goto again;
+ }
+
+ fail("Can't umount all the filesystems");
+ return -1;
+
+done:
+ rmdir(MPTS_ROOT);
+ if (mkdir(MPTS_ROOT, 0600) < 0) {
+ fail("Can't make zdtm_sys");
+ return 1;
+ }
+
+ if (mount("none", MPTS_ROOT, "sysfs", 0, "") < 0) {
+ fail("Can't mount sysfs");
+ return 1;
+ }
+
+ if (mount("none", MPTS_ROOT"/dev", "tmpfs", 0, "") < 0) {
+ fail("Can't mount tmpfs");
+ return 1;
+ }
+ tmpfs_fd = open(MPTS_ROOT"/dev/test", O_WRONLY | O_CREAT);
+ if (write(tmpfs_fd, "hello", 5) <= 0) {
+ err("write() failed");
+ return 1;
+ }
+
+ if (mount("none", MPTS_ROOT"/kernel", "proc", 0, "") < 0) {
+ fail("Can't mount proc");
+ return 1;
+ }
+ if (mount("none", MPTS_ROOT"/kernel/sys/fs/binfmt_misc",
+ "binfmt_misc", 0, "") < 0) {
+ fail("Can't mount proc");
+ return 1;
+ }
+
+ mknod("/dev/null", 0777 | S_IFCHR, makedev(1, 3));
+
+ setup_outfile();
+
+ fd = open(MPTS_ROOT"/kernel/meminfo", O_RDONLY);
+ if (fd == -1)
+ return 1;
+
+ test_daemon();
+ test_waitsig();
+
+ /* this checks both -- sys and proc presence */
+ if (access(MPTS_ROOT"/kernel/meminfo", F_OK)) {
+ fail("No proc after restore");
+ return 1;
+ }
+
+ pass();
+ return 0;
+}
+
+#define CLONE_NEWNS 0x00020000
+
+int main(int argc, char **argv)
+{
+ test_init_ns(argc, argv, CLONE_NEWNS, test_fn);
+ return 0;
+}
diff --git a/pool/shard000/C/0008864_itob.c b/pool/shard000/C/0008864_itob.c
new file mode 100644
index 0000000000000000000000000000000000000000..0dc6a378db219a98362b734445d8395e60fd09c7
--- /dev/null
+++ b/pool/shard000/C/0008864_itob.c
@@ -0,0 +1,130 @@
+/*
+ * itob: converts an integer to a variable base character string representation
+ *
+ * "Portions of this work are derived from The Standard C Library, copyright (c) 1992
+ * by P.J. Plauger, published by Prentice-Hall, and are used with permission."
+ */
+
+// Includes
+
+#include
+#include
+#include
+#include
+
+// Definitions
+
+#define MAXSTRING 256
+
+/*
+ * reverse(): reverse string 's' in place
+ */
+
+static void reverse(char s[]) {
+
+ size_t i;
+ size_t j;
+
+ for (i = 0, j = strlen(s) - 1; i < j; i++, j--) {
+ int c;
+ c = s[i];
+ s[i] = s[j];
+ s[j] = c;
+ }
+
+}
+
+/*
+ * iotb(): converts integer 'n' into a base 'b' string 's[]'
+ */
+
+static void itob(int n, char s[], int b) {
+
+ size_t i = 0;
+ int sign = n; // Save the sign and make it positive if its negative
+
+ // generate digits in reverse order
+ do {
+ int d = abs(n % b); // gets the next digit
+ s[i++] = (d <= 9) ? (char)d + '0' : (char)d + 'A' - 10; // save it as a char--letters if num > 9
+ } while ((n /= b) != 0); // and deletes it from the number
+
+ // set the sign of the string (again in reverse)
+ if (sign < 0)
+ s[i++] = '-';
+
+ // termerate the string
+ s[i] = '\0';
+
+ // and reverse the string back
+ reverse(s);
+}
+
+/* Main */
+
+int main(void) {
+ int n;
+ int b;
+ char s[MAXSTRING] = "";
+
+ n = -255;
+ b = 10;
+ itob(n, s, b);
+ printf("Number %d converted to a string in base %d is: \"%s\"\n", n, b, s);
+ b = 2;
+ itob(n, s, b);
+ printf("Number %d converted to a string in base %d is: \"%s\"\n", n, b, s);
+ b = 8;
+ itob(n, s, b);
+ printf("Number %d converted to a string in base %d is: \"%s\"\n", n, b, s);
+ b = 16;
+ itob(n, s, b);
+ printf("Number %d converted to a string in base %d is: \"%s\"\n", n, b, s);
+ (void)putchar('\n');
+
+ n = 255;
+ b = 10;
+ itob(n, s, b);
+ printf("Number %d converted to a string in base %d is: \"%s\"\n", n, b, s);
+ b = 2;
+ itob(n, s, b);
+ printf("Number %d converted to a string in base %d is: \"%s\"\n", n, b, s);
+ b = 8;
+ itob(n, s, b);
+ printf("Number %d converted to a string in base %d is: \"%s\"\n", n, b, s);
+ b = 16;
+ itob(n, s, b);
+ printf("Number %d converted to a string in base %d is: \"%s\"\n", n, b, s);
+ (void)putchar('\n');
+
+ n = 1043;
+ b = 10;
+ itob(n, s, b);
+ printf("Number %d converted to a string in base %d is: \"%s\"\n", n, b, s);
+ b = 2;
+ itob(n, s, b);
+ printf("Number %d converted to a string in base %d is: \"%s\"\n", n, b, s);
+ b = 8;
+ itob(n, s, b);
+ printf("Number %d converted to a string in base %d is: \"%s\"\n", n, b, s);
+ b = 16;
+ itob(n, s, b);
+ printf("Number %d converted to a string in base %d is: \"%s\"\n", n, b, s);
+ (void)putchar('\n');
+
+ n = INT_MIN;
+ b = 10;
+ itob(n, s, b);
+ printf("Number %d converted to a string in base %d is: \"%s\"\n", n, b, s);
+ b = 2;
+ itob(n, s, b);
+ printf("Number %d converted to a string in base %d is: \"%s\"\n", n, b, s);
+ b = 8;
+ itob(n, s, b);
+ printf("Number %d converted to a string in base %d is: \"%s\"\n", n, b, s);
+ b = 16;
+ itob(n, s, b);
+ printf("Number %d converted to a string in base %d is: \"%s\"\n", n, b, s);
+
+ return 0;
+}
diff --git a/pool/shard000/C/0008887_graphtest.c b/pool/shard000/C/0008887_graphtest.c
new file mode 100644
index 0000000000000000000000000000000000000000..aeee91187d83209d3da6e47bc936b17b62d206b0
--- /dev/null
+++ b/pool/shard000/C/0008887_graphtest.c
@@ -0,0 +1,61 @@
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+
+uint32_t bytes_in = 666;
+uint32_t bytes_out = 666;
+
+void graphtest_write(void)
+{
+ struct graph *graph;
+
+ graph = graph_new("traffic", 400, 160, GRAPH_TYPE_LINE);
+
+/* graph_colorize(graph, GRAPH_COLOR_DARK);
+
+ graph_source_add(graph, GRAPH_MEASURE_DIFFTIME,
+ GRAPH_SOURCE_UINT, &bytes_in, "in");
+
+ graph_source_add(graph, GRAPH_MEASURE_DIFFTIME,
+ GRAPH_SOURCE_UINT, &bytes_out, "out");
+
+ graph_drain_add(graph, GRAPH_DATA_HOURLY);
+ graph_drain_add(graph, GRAPH_DATA_DAILY);
+ graph_drain_add(graph, GRAPH_DATA_WEEKLY);
+ graph_drain_add(graph, GRAPH_DATA_MONTHLY);
+
+ graph_drain_render(graph, GRAPH_DATA_HOURLY);
+ graph_drain_save(graph, GRAPH_DATA_HOURLY);
+ */
+ graph_delete(graph);
+}
+
+int main()
+{
+ log_init(STDOUT_FILENO, LOG_ALL, L_status);
+ io_init_except(STDOUT_FILENO, STDOUT_FILENO, STDOUT_FILENO);
+ mem_init();
+ dlink_init();
+ gif_init();
+ image_init();
+ timer_init();
+ graph_init();
+
+ graphtest_write();
+
+ graph_shutdown();
+ timer_shutdown();
+ image_shutdown();
+ gif_shutdown();
+ dlink_shutdown();
+ mem_shutdown();
+ log_shutdown();
+ io_shutdown();
+
+ return 0;
+}
+
diff --git a/pool/shard000/C/0008890_dvk_ebi.c b/pool/shard000/C/0008890_dvk_ebi.c
new file mode 100644
index 0000000000000000000000000000000000000000..1d37f358cf7e76ca250a9d3be1390d789d75ef56
--- /dev/null
+++ b/pool/shard000/C/0008890_dvk_ebi.c
@@ -0,0 +1,237 @@
+/**************************************************************************//**
+ * @file
+ * @brief EBI implementation of Board Control interface
+ * This implementation works for devices w/o LCD display on the
+ * MCU module, specifically the EFM32_G2xx_DK development board
+ * @author Energy Micro AS
+ * @version 1.6.0
+ ******************************************************************************
+ * @section License
+ * (C) Copyright 2010 Energy Micro AS, http://www.energymicro.com
+ ******************************************************************************
+ *
+ * This source code is the property of Energy Micro AS. The source and compiled
+ * code may only be used on Energy Micro "EFM32" microcontrollers.
+ *
+ * This copyright notice may not be removed from the source code nor changed.
+ *
+ * DISCLAIMER OF WARRANTY/LIMITATION OF REMEDIES: Energy Micro AS has no
+ * obligation to support this Software. Energy Micro AS is providing the
+ * Software "AS IS", with no express or implied warranties of any kind,
+ * including, but not limited to, any implied warranties of merchantability
+ * or fitness for any particular purpose or warranties against infringement
+ * of any proprietary rights of a third party.
+ *
+ * Energy Micro AS will not be liable for any consequential, incidental, or
+ * special damages, or any other relief, or for any claim by any third party,
+ * arising from your use of this Software.
+ *
+ *****************************************************************************/
+#include "efm32.h"
+#include "efm32_ebi.h"
+#include "efm32_cmu.h"
+#include "efm32_gpio.h"
+#include "dvk.h"
+#include "dvk_bcregisters.h"
+
+
+/**************************************************************************//**
+ * @brief Configure EBI (external bus interface) for Board Control register
+ * access
+ *****************************************************************************/
+void DVK_EBI_configure(void)
+{
+ EBI_Init_TypeDef ebiConfig = EBI_INIT_DEFAULT;
+
+ /* Run time check if we have EBI on-chip capability on this device */
+ switch ((DEVINFO->PART & _DEVINFO_PART_DEVICE_NUMBER_MASK) >>
+ _DEVINFO_PART_DEVICE_NUMBER_SHIFT)
+ {
+ /* Only device types EFM32G 280/290/880 and 890 have EBI capability */
+ case 280:
+ case 290:
+ case 880:
+ case 890:
+ break;
+ default:
+ /* This device do not have EBI capability - use SPI to interface DVK */
+ /* With high probability your project has been configured for an */
+ /* incorrect part number. */
+ while (1) ;
+ }
+
+ /* Enable clocks */
+ CMU_ClockEnable(cmuClock_EBI, true);
+ CMU_ClockEnable(cmuClock_GPIO, true);
+
+ /* Configure bus connect PC bit 12 active low */
+ GPIO_PinModeSet(gpioPortC, 12, gpioModePushPull, 0);
+
+ /* Configure GPIO pins as push pull */
+ /* EBI AD9..15 */
+ GPIO_PinModeSet(gpioPortA, 0, gpioModePushPull, 0);
+ GPIO_PinModeSet(gpioPortA, 1, gpioModePushPull, 0);
+ GPIO_PinModeSet(gpioPortA, 2, gpioModePushPull, 0);
+ GPIO_PinModeSet(gpioPortA, 3, gpioModePushPull, 0);
+ GPIO_PinModeSet(gpioPortA, 4, gpioModePushPull, 0);
+ GPIO_PinModeSet(gpioPortA, 5, gpioModePushPull, 0);
+ GPIO_PinModeSet(gpioPortA, 6, gpioModePushPull, 0);
+
+ /* EBI AD8 */
+ GPIO_PinModeSet(gpioPortA, 15, gpioModePushPull, 0);
+
+ /* EBI CS0-CS3 */
+ GPIO_PinModeSet(gpioPortD, 9, gpioModePushPull, 0);
+ GPIO_PinModeSet(gpioPortD, 10, gpioModePushPull, 0);
+ GPIO_PinModeSet(gpioPortD, 11, gpioModePushPull, 0);
+ GPIO_PinModeSet(gpioPortD, 12, gpioModePushPull, 0);
+
+ /* EBI AD0..7 */
+ GPIO_PinModeSet(gpioPortE, 8, gpioModePushPull, 0);
+ GPIO_PinModeSet(gpioPortE, 9, gpioModePushPull, 0);
+ GPIO_PinModeSet(gpioPortE, 10, gpioModePushPull, 0);
+ GPIO_PinModeSet(gpioPortE, 11, gpioModePushPull, 0);
+ GPIO_PinModeSet(gpioPortE, 12, gpioModePushPull, 0);
+ GPIO_PinModeSet(gpioPortE, 13, gpioModePushPull, 0);
+ GPIO_PinModeSet(gpioPortE, 14, gpioModePushPull, 0);
+ GPIO_PinModeSet(gpioPortE, 15, gpioModePushPull, 0);
+
+ /* EBI ARDY/ALEN/Wen/Ren */
+ GPIO_PinModeSet(gpioPortF, 2, gpioModePushPull, 0);
+ GPIO_PinModeSet(gpioPortF, 3, gpioModePushPull, 0);
+ GPIO_PinModeSet(gpioPortF, 4, gpioModePushPull, 0);
+ GPIO_PinModeSet(gpioPortF, 5, gpioModePushPull, 0);
+
+ /* Configure EBI controller, changing default values */
+ ebiConfig.mode = ebiModeD16A16ALE;
+ /* Enable bank 0 address map 0x80000000, FPGA Flash */
+ /* Enable bank 1 address map 0x84000000, FPGA SRAM */
+ /* Enable bank 2 address map 0x88000000, FPGA TFT Display (SSD2119) */
+ /* Enable bank 3 address map 0x8c000000, FPGA Board Control Registers */
+ ebiConfig.banks = EBI_BANK0|EBI_BANK1|EBI_BANK2|EBI_BANK3;
+ ebiConfig.csLines = EBI_CS0|EBI_CS1|EBI_CS2|EBI_CS3;
+
+ /* Address Setup and hold time */
+ ebiConfig.addrHoldCycles = 3;
+ ebiConfig.addrSetupCycles = 3;
+
+ /* Read cycle times */
+ ebiConfig.readStrobeCycles = 7;
+ ebiConfig.readHoldCycles = 3;
+ ebiConfig.readSetupCycles = 3;
+
+ /* Write cycle times */
+ ebiConfig.writeStrobeCycles = 7;
+ ebiConfig.writeHoldCycles = 3;
+ ebiConfig.writeSetupCycles = 3;
+
+ /* Polarity values are default */
+
+ /* Configure EBI */
+ EBI_Init(&ebiConfig);
+}
+
+
+/**************************************************************************//**
+ * @brief Initialize EBI
+ * access
+ *****************************************************************************/
+void DVK_EBI_init(void)
+{
+ uint16_t ebiMagic;
+ int ctr;
+
+ /* Disable all GPIO pins and register */
+ DVK_EBI_disable();
+ /* Configure EBI */
+ DVK_EBI_configure();
+ /* Verify that EBI access is working, if not kit is in SPI mode and needs to
+ * be configured for EBI access */
+ ebiMagic = DVK_EBI_readRegister(BC_MAGIC);
+ if (ebiMagic != BC_MAGIC_VALUE)
+ {
+ /* Disable EBI */
+ DVK_EBI_disable();
+ /* Enable SPI interface */
+ DVK_SPI_init();
+ /* Set EBI mode - after this SPI access will no longer be available */
+ DVK_SPI_writeRegister(BC_CFG, BC_CFG_EBI);
+ /* Disable SPI */
+ DVK_SPI_disable();
+ /* Now setup EBI again */
+ DVK_EBI_configure();
+ /* Wait until ready */
+ ctr = 0;
+ do
+ {
+ /* Check if FPGA responds */
+ ebiMagic = DVK_EBI_readRegister(BC_MAGIC);
+ ctr++;
+ DVK_EBI_writeRegister(BC_LED, ctr);
+ } while (ebiMagic != BC_MAGIC_VALUE);
+ }
+}
+
+/**************************************************************************//**
+ * @brief Disable EBI interface, free all GPIO pins
+ *****************************************************************************/
+void DVK_EBI_disable(void)
+{
+ /* Disable EBI controller */
+ EBI_Disable();
+
+ /* Disable EBI clock in CMU */
+ CMU_ClockEnable(cmuClock_EBI, false);
+
+ /* Disable EBI _BC_BUS_CONNECT */
+ GPIO_PinModeSet(gpioPortC, 12, gpioModeDisabled, 0);
+
+ /* Configure GPIO pins as disabled */
+ GPIO_PinModeSet(gpioPortA, 0, gpioModeDisabled, 0);
+ GPIO_PinModeSet(gpioPortA, 1, gpioModeDisabled, 0);
+ GPIO_PinModeSet(gpioPortA, 2, gpioModeDisabled, 0);
+ GPIO_PinModeSet(gpioPortA, 3, gpioModeDisabled, 0);
+ GPIO_PinModeSet(gpioPortA, 4, gpioModeDisabled, 0);
+ GPIO_PinModeSet(gpioPortA, 5, gpioModeDisabled, 0);
+ GPIO_PinModeSet(gpioPortA, 6, gpioModeDisabled, 0);
+
+ GPIO_PinModeSet(gpioPortA, 15, gpioModeDisabled, 0);
+
+ GPIO_PinModeSet(gpioPortD, 9, gpioModeDisabled, 0);
+ GPIO_PinModeSet(gpioPortD, 10, gpioModeDisabled, 0);
+ GPIO_PinModeSet(gpioPortD, 11, gpioModeDisabled, 0);
+ GPIO_PinModeSet(gpioPortD, 12, gpioModeDisabled, 0);
+
+ GPIO_PinModeSet(gpioPortE, 8, gpioModeDisabled, 0);
+ GPIO_PinModeSet(gpioPortE, 9, gpioModeDisabled, 0);
+ GPIO_PinModeSet(gpioPortE, 10, gpioModeDisabled, 0);
+ GPIO_PinModeSet(gpioPortE, 11, gpioModeDisabled, 0);
+ GPIO_PinModeSet(gpioPortE, 12, gpioModeDisabled, 0);
+ GPIO_PinModeSet(gpioPortE, 13, gpioModeDisabled, 0);
+ GPIO_PinModeSet(gpioPortE, 14, gpioModeDisabled, 0);
+ GPIO_PinModeSet(gpioPortE, 15, gpioModeDisabled, 0);
+
+ GPIO_PinModeSet(gpioPortF, 2, gpioModeDisabled, 0);
+ GPIO_PinModeSet(gpioPortF, 3, gpioModeDisabled, 0);
+ GPIO_PinModeSet(gpioPortF, 4, gpioModeDisabled, 0);
+ GPIO_PinModeSet(gpioPortF, 5, gpioModeDisabled, 0);
+}
+
+/**************************************************************************//**
+ * @brief Write data into 16-bit board control register
+ * @param addr Address to board control register
+ * @param data Data to write into register
+ *****************************************************************************/
+void DVK_EBI_writeRegister(volatile uint16_t *addr, uint16_t data)
+{
+ *addr = data;
+}
+
+/**************************************************************************//**
+ * @brief Write data into 16-bit board control register
+ * @param addr Register to read from
+ *****************************************************************************/
+uint16_t DVK_EBI_readRegister(volatile uint16_t *addr)
+{
+ return *addr;
+}
diff --git a/pool/shard000/C/0008902_comtest.c b/pool/shard000/C/0008902_comtest.c
new file mode 100644
index 0000000000000000000000000000000000000000..ec58dcffc1158bcdc4f309a9286c09400ffa5530
--- /dev/null
+++ b/pool/shard000/C/0008902_comtest.c
@@ -0,0 +1,312 @@
+/*
+ FreeRTOS V7.4.0 - Copyright (C) 2013 Real Time Engineers Ltd.
+
+ FEATURES AND PORTS ARE ADDED TO FREERTOS ALL THE TIME. PLEASE VISIT
+ http://www.FreeRTOS.org TO ENSURE YOU ARE USING THE LATEST VERSION.
+
+ ***************************************************************************
+ * *
+ * FreeRTOS tutorial books are available in pdf and paperback. *
+ * Complete, revised, and edited pdf reference manuals are also *
+ * available. *
+ * *
+ * Purchasing FreeRTOS documentation will not only help you, by *
+ * ensuring you get running as quickly as possible and with an *
+ * in-depth knowledge of how to use FreeRTOS, it will also help *
+ * the FreeRTOS project to continue with its mission of providing *
+ * professional grade, cross platform, de facto standard solutions *
+ * for microcontrollers - completely free of charge! *
+ * *
+ * >>> See http://www.FreeRTOS.org/Documentation for details. <<< *
+ * *
+ * Thank you for using FreeRTOS, and thank you for your support! *
+ * *
+ ***************************************************************************
+
+
+ This file is part of the FreeRTOS distribution.
+
+ FreeRTOS is free software; you can redistribute it and/or modify it under
+ the terms of the GNU General Public License (version 2) as published by the
+ Free Software Foundation AND MODIFIED BY the FreeRTOS exception.
+
+ >>>>>>NOTE<<<<<< The modification to the GPL is included to allow you to
+ distribute a combined work that includes FreeRTOS without being obliged to
+ provide the source code for proprietary components outside of the FreeRTOS
+ kernel.
+
+ FreeRTOS is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+ FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
+ details. You should have received a copy of the GNU General Public License
+ and the FreeRTOS license exception along with FreeRTOS; if not itcan be
+ viewed here: http://www.freertos.org/a00114.html and also obtained by
+ writing to Real Time Engineers Ltd., contact details for whom are available
+ on the FreeRTOS WEB site.
+
+ 1 tab == 4 spaces!
+
+ ***************************************************************************
+ * *
+ * Having a problem? Start by reading the FAQ "My application does *
+ * not run, what could be wrong?" *
+ * *
+ * http://www.FreeRTOS.org/FAQHelp.html *
+ * *
+ ***************************************************************************
+
+
+ http://www.FreeRTOS.org - Documentation, books, training, latest versions,
+ license and Real Time Engineers Ltd. contact details.
+
+ http://www.FreeRTOS.org/plus - A selection of FreeRTOS ecosystem products,
+ including FreeRTOS+Trace - an indispensable productivity tool, and our new
+ fully thread aware and reentrant UDP/IP stack.
+
+ http://www.OpenRTOS.com - Real Time Engineers ltd license FreeRTOS to High
+ Integrity Systems, who sell the code with commercial support,
+ indemnification and middleware, under the OpenRTOS brand.
+
+ http://www.SafeRTOS.com - High Integrity Systems also provide a safety
+ engineered and independently SIL3 certified version for use in safety and
+ mission critical applications that require provable dependability.
+*/
+
+
+/*
+ * This version of comtest. c is for use on systems that have limited stack
+ * space and no display facilities. The complete version can be found in
+ * the Demo/Common/Full directory.
+ *
+ * Creates two tasks that operate on an interrupt driven serial port. A
+ * loopback connector should be used so that everything that is transmitted is
+ * also received. The serial port does not use any flow control. On a
+ * standard 9way 'D' connector pins two and three should be connected together.
+ *
+ * The first task posts a sequence of characters to the Tx queue, toggling an
+ * LED on each successful post. At the end of the sequence it sleeps for a
+ * pseudo-random period before resending the same sequence.
+ *
+ * The UART Tx end interrupt is enabled whenever data is available in the Tx
+ * queue. The Tx end ISR removes a single character from the Tx queue and
+ * passes it to the UART for transmission.
+ *
+ * The second task blocks on the Rx queue waiting for a character to become
+ * available. When the UART Rx end interrupt receives a character it places
+ * it in the Rx queue, waking the second task. The second task checks that the
+ * characters removed from the Rx queue form the same sequence as those posted
+ * to the Tx queue, and toggles an LED for each correct character.
+ *
+ * The receiving task is spawned with a higher priority than the transmitting
+ * task. The receiver will therefore wake every time a character is
+ * transmitted so neither the Tx or Rx queue should ever hold more than a few
+ * characters.
+ *
+ */
+
+/* Scheduler include files. */
+#include
+#include "FreeRTOS.h"
+#include "task.h"
+
+/* Demo program include files. */
+#include "serial.h"
+#include "comtest.h"
+#include "partest.h"
+
+#define comSTACK_SIZE configMINIMAL_STACK_SIZE
+#define comTX_LED_OFFSET ( 0 )
+#define comRX_LED_OFFSET ( 1 )
+#define comTOTAL_PERMISSIBLE_ERRORS ( 2 )
+
+/* The Tx task will transmit the sequence of characters at a pseudo random
+interval. This is the maximum and minimum block time between sends. */
+#define comTX_MAX_BLOCK_TIME ( ( portTickType ) 0x96 )
+#define comTX_MIN_BLOCK_TIME ( ( portTickType ) 0x32 )
+#define comOFFSET_TIME ( ( portTickType ) 3 )
+
+/* We should find that each character can be queued for Tx immediately and we
+don't have to block to send. */
+#define comNO_BLOCK ( ( portTickType ) 0 )
+
+/* The Rx task will block on the Rx queue for a long period. */
+#define comRX_BLOCK_TIME ( ( portTickType ) 0xffff )
+
+/* The sequence transmitted is from comFIRST_BYTE to and including comLAST_BYTE. */
+#define comFIRST_BYTE ( 'A' )
+#define comLAST_BYTE ( 'X' )
+
+#define comBUFFER_LEN ( ( unsigned portBASE_TYPE ) ( comLAST_BYTE - comFIRST_BYTE ) + ( unsigned portBASE_TYPE ) 1 )
+#define comINITIAL_RX_COUNT_VALUE ( 0 )
+
+/* Handle to the com port used by both tasks. */
+static xComPortHandle xPort = NULL;
+
+/* The transmit task as described at the top of the file. */
+static portTASK_FUNCTION_PROTO( vComTxTask, pvParameters );
+
+/* The receive task as described at the top of the file. */
+static portTASK_FUNCTION_PROTO( vComRxTask, pvParameters );
+
+/* The LED that should be toggled by the Rx and Tx tasks. The Rx task will
+toggle LED ( uxBaseLED + comRX_LED_OFFSET). The Tx task will toggle LED
+( uxBaseLED + comTX_LED_OFFSET ). */
+static unsigned portBASE_TYPE uxBaseLED = 0;
+
+/* Check variable used to ensure no error have occurred. The Rx task will
+increment this variable after every successfully received sequence. If at any
+time the sequence is incorrect the the variable will stop being incremented. */
+static volatile unsigned portBASE_TYPE uxRxLoops = comINITIAL_RX_COUNT_VALUE;
+
+/*-----------------------------------------------------------*/
+
+void vAltStartComTestTasks( unsigned portBASE_TYPE uxPriority, unsigned long ulBaudRate, unsigned portBASE_TYPE uxLED )
+{
+ /* Initialise the com port then spawn the Rx and Tx tasks. */
+ uxBaseLED = uxLED;
+ xSerialPortInitMinimal( ulBaudRate, comBUFFER_LEN );
+
+ /* The Tx task is spawned with a lower priority than the Rx task. */
+ xTaskCreate( vComTxTask, ( signed char * ) "COMTx", comSTACK_SIZE, NULL, uxPriority - 1, ( xTaskHandle * ) NULL );
+ xTaskCreate( vComRxTask, ( signed char * ) "COMRx", comSTACK_SIZE, NULL, uxPriority, ( xTaskHandle * ) NULL );
+}
+/*-----------------------------------------------------------*/
+
+static portTASK_FUNCTION( vComTxTask, pvParameters )
+{
+signed char cByteToSend;
+portTickType xTimeToWait;
+
+ /* Just to stop compiler warnings. */
+ ( void ) pvParameters;
+
+ for( ;; )
+ {
+ /* Simply transmit a sequence of characters from comFIRST_BYTE to
+ comLAST_BYTE. */
+ for( cByteToSend = comFIRST_BYTE; cByteToSend <= comLAST_BYTE; cByteToSend++ )
+ {
+ if( xSerialPutChar( xPort, cByteToSend, comNO_BLOCK ) == pdPASS )
+ {
+ vParTestToggleLED( uxBaseLED + comTX_LED_OFFSET );
+ }
+ }
+
+ /* Turn the LED off while we are not doing anything. */
+ vParTestSetLED( uxBaseLED + comTX_LED_OFFSET, pdFALSE );
+
+ /* We have posted all the characters in the string - wait before
+ re-sending. Wait a pseudo-random time as this will provide a better
+ test. */
+ xTimeToWait = xTaskGetTickCount() + comOFFSET_TIME;
+
+ /* Make sure we don't wait too long... */
+ xTimeToWait %= comTX_MAX_BLOCK_TIME;
+
+ /* ...but we do want to wait. */
+ if( xTimeToWait < comTX_MIN_BLOCK_TIME )
+ {
+ xTimeToWait = comTX_MIN_BLOCK_TIME;
+ }
+
+ vTaskDelay( xTimeToWait );
+ }
+} /*lint !e715 !e818 pvParameters is required for a task function even if it is not referenced. */
+/*-----------------------------------------------------------*/
+
+static portTASK_FUNCTION( vComRxTask, pvParameters )
+{
+signed char cExpectedByte, cByteRxed;
+portBASE_TYPE xResyncRequired = pdFALSE, xErrorOccurred = pdFALSE;
+
+ /* Just to stop compiler warnings. */
+ ( void ) pvParameters;
+
+ for( ;; )
+ {
+ /* We expect to receive the characters from comFIRST_BYTE to
+ comLAST_BYTE in an incrementing order. Loop to receive each byte. */
+ for( cExpectedByte = comFIRST_BYTE; cExpectedByte <= comLAST_BYTE; cExpectedByte++ )
+ {
+ /* Block on the queue that contains received bytes until a byte is
+ available. */
+ if( xSerialGetChar( xPort, &cByteRxed, comRX_BLOCK_TIME ) )
+ {
+ /* Was this the byte we were expecting? If so, toggle the LED,
+ otherwise we are out on sync and should break out of the loop
+ until the expected character sequence is about to restart. */
+ if( cByteRxed == cExpectedByte )
+ {
+ vParTestToggleLED( uxBaseLED + comRX_LED_OFFSET );
+ }
+ else
+ {
+ xResyncRequired = pdTRUE;
+ break; /*lint !e960 Non-switch break allowed. */
+ }
+ }
+ }
+
+ /* Turn the LED off while we are not doing anything. */
+ vParTestSetLED( uxBaseLED + comRX_LED_OFFSET, pdFALSE );
+
+ /* Did we break out of the loop because the characters were received in
+ an unexpected order? If so wait here until the character sequence is
+ about to restart. */
+ if( xResyncRequired == pdTRUE )
+ {
+ while( cByteRxed != comLAST_BYTE )
+ {
+ /* Block until the next char is available. */
+ xSerialGetChar( xPort, &cByteRxed, comRX_BLOCK_TIME );
+ }
+
+ /* Note that an error occurred which caused us to have to resync.
+ We use this to stop incrementing the loop counter so
+ sAreComTestTasksStillRunning() will return false - indicating an
+ error. */
+ xErrorOccurred++;
+
+ /* We have now resynced with the Tx task and can continue. */
+ xResyncRequired = pdFALSE;
+ }
+ else
+ {
+ if( xErrorOccurred < comTOTAL_PERMISSIBLE_ERRORS )
+ {
+ /* Increment the count of successful loops. As error
+ occurring (i.e. an unexpected character being received) will
+ prevent this counter being incremented for the rest of the
+ execution. Don't worry about mutual exclusion on this
+ variable - it doesn't really matter as we just want it
+ to change. */
+ uxRxLoops++;
+ }
+ }
+ }
+} /*lint !e715 !e818 pvParameters is required for a task function even if it is not referenced. */
+/*-----------------------------------------------------------*/
+
+portBASE_TYPE xAreComTestTasksStillRunning( void )
+{
+portBASE_TYPE xReturn;
+
+ /* If the count of successful reception loops has not changed than at
+ some time an error occurred (i.e. a character was received out of sequence)
+ and we will return false. */
+ if( uxRxLoops == comINITIAL_RX_COUNT_VALUE )
+ {
+ xReturn = pdFALSE;
+ }
+ else
+ {
+ xReturn = pdTRUE;
+ }
+
+ /* Reset the count of successful Rx loops. When this function is called
+ again we expect this to have been incremented. */
+ uxRxLoops = comINITIAL_RX_COUNT_VALUE;
+
+ return xReturn;
+}
+
diff --git a/pool/shard000/C/0008912_unix_misc.c b/pool/shard000/C/0008912_unix_misc.c
new file mode 100644
index 0000000000000000000000000000000000000000..5e5186ab998c163b9dcbf0c07ea3f83fddbf9fd9
--- /dev/null
+++ b/pool/shard000/C/0008912_unix_misc.c
@@ -0,0 +1,50 @@
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include "process.h"
+#include "io.h"
+#include "prog.h"
+#include "ntcomm.h"
+
+#define unixfd(hc) FileHandle_fromCommHandle(ComGetHandle(hc))
+
+/* Record locking code */
+
+int lock(int fd, long offset, long len)
+{
+ struct flock lck;
+
+ lck.l_type = F_WRLCK; /* setting a write lock */
+ lck.l_whence = SEEK_SET; /* offset l_start from beginning of file */
+ lck.l_start = (off_t)offset;
+ lck.l_len = len;
+
+ return fcntl(fd, F_SETLK, &lck);
+}
+
+int unlock(int fd, long offset, long len)
+{
+ struct flock lck;
+
+ lck.l_type = F_UNLCK; /* setting not locked */
+ lck.l_whence = SEEK_SET; /* offset l_start from beginning of file */
+ lck.l_start = (off_t)offset;
+ lck.l_len = len;
+
+ return fcntl(fd, F_SETLK, &lck);
+}
+
+void NoMem() __attribute__((weak));
+void NoMem()
+{
+ fprintf(stderr, "Out of memory!\n");
+ _exit(1);
+}
diff --git a/pool/shard000/C/0008917_PiCode.c b/pool/shard000/C/0008917_PiCode.c
new file mode 100644
index 0000000000000000000000000000000000000000..84b5fa57844aab1c876c56b6495f6c2465ceecd2
--- /dev/null
+++ b/pool/shard000/C/0008917_PiCode.c
@@ -0,0 +1,96 @@
+/*
+ * PiCode.c
+ *
+ * Created on: May 25, 2016
+ * Author: Barrett
+ * Uses the Monte Carlo method of pi calculation and pthreads
+ * to accurately and consistently approximate pi, getting more
+ * accurate as the number of threads increase
+ */
+#include
+#include
+#include
+#include
+
+//GLOBAL VARIABLE
+int threadcount = 100000;//number of threads created 250000
+
+//STRUCTURES
+struct randoms{//used to pass the two random numbers
+ double rand1;
+ double rand2;
+};
+
+void *piseries(void *arg){
+ //*NOTE* DON'T SEED RANDOM NUMBERS (srand()) IN THE THREAD FUNCTION,
+ //you must seed the random function once in the main method so its only seeded once as a constant
+ //addornot has dynamically allocated data
+ int *addornot = malloc(sizeof(*addornot));//add or not is returned as 0 or 1, a boolean for C
+
+ struct randoms *nums = (struct randoms*)arg;
+ //gets random numbers created in main()
+ double x = nums->rand1;
+ double y = nums->rand2;
+ //THE MATH, REFER TO MONTE CARLO PI CALCULATION
+ double answ = (x*x)+(y*y);
+ //DEBUGGINGprintf("\n\n------------\n| %f...%f |\n------------\n\n", x, y);
+ *addornot = 0;//initially false
+ if (answ < 1){
+ *addornot = 1;//TRUE
+ pthread_exit(addornot);//return addornot to pthread_join()
+ }
+ else{//FALSE
+ pthread_exit(addornot);//return addornot to pthread_join
+ }
+ return NULL;
+}
+
+int main(){
+ void *incircle;//recieve the addornot variable when pthread_exit() is called
+ int pointsinside = 0;//if addornot is true(1) add one
+ double pi;//store actual finished value of pi
+ struct randoms randm;//random numbers for pthreads
+
+ //INITIALIZING THE THREADS
+ pthread_t threads[threadcount];//array of threads with custom size of global variabel threadcount
+ srand(3645783);//seed the rand function ONLY DO ONCE AND NOT IN ANY THREADS, THE NUMBERS WILL BECOME NOT RANDOM IF YOU DO AND IT WILL SKEW RESULTS
+
+ for (int i = 0; i < threadcount; i++){//create random numbers, threads and joins the threads while printing out status of the process
+ //assign random numbers to structure, DIVIDE BY RAND_MAX NOT ESTIMATED MAX OR ELSE RESULTS WILL BE SKEWED
+ randm.rand1 = (double)rand()/RAND_MAX;
+ randm.rand2 = (double)rand()/RAND_MAX;
+ //create and join threads
+ pthread_create(&threads[i], NULL, piseries, (void *)&randm);
+ pthread_join(threads[i], &incircle);
+ if(*(int*)incircle == 1){//incircle is returned by pthread_exit in the piseries function
+ pointsinside++;
+ //DEBUGGINGprintf("YES");
+ //DEBUGGINGfflush(stdout);
+ }
+ //printing benchmark points
+ if((double)i/threadcount == .25){
+ printf(" 25%% ");
+ fflush(stdout);
+ }
+ else if((double)i/threadcount == .5){
+ printf(" 50%% ");
+ fflush(stdout);
+ }
+ else if((double)i/threadcount == .75){
+ printf(" 75%% ");
+ fflush(stdout);
+ }
+ }//end for
+ //MATH, SEE MONTE CARLO PI CALCULATION
+ pi = 4 * ((double)pointsinside/threadcount);//4*(number of points inside/total number of threads)
+ printf("\n\nPi is estimated to: %f\n\n%d", pi, pointsinside);
+ fflush(stdout);
+}
+
+
+
+
+
+
+
+
diff --git a/pool/shard000/C/0008927_channel_layout.c b/pool/shard000/C/0008927_channel_layout.c
new file mode 100644
index 0000000000000000000000000000000000000000..79e398e41a719f476261e013d2968193b2a54727
--- /dev/null
+++ b/pool/shard000/C/0008927_channel_layout.c
@@ -0,0 +1,231 @@
+/*
+ * Copyright (c) 2006 Michael Niedermayer
+ *
+ * This file is part of Libav.
+ *
+ * Libav is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * Libav is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with Libav; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+/**
+ * @file
+ * audio channel layout utility functions
+ */
+
+#include "avstring.h"
+#include "avutil.h"
+#include "channel_layout.h"
+#include "common.h"
+
+static const char * const channel_names[] = {
+ [0] = "FL", /* front left */
+ [1] = "FR", /* front right */
+ [2] = "FC", /* front center */
+ [3] = "LFE", /* low frequency */
+ [4] = "BL", /* back left */
+ [5] = "BR", /* back right */
+ [6] = "FLC", /* front left-of-center */
+ [7] = "FRC", /* front right-of-center */
+ [8] = "BC", /* back-center */
+ [9] = "SL", /* side left */
+ [10] = "SR", /* side right */
+ [11] = "TC", /* top center */
+ [12] = "TFL", /* top front left */
+ [13] = "TFC", /* top front center */
+ [14] = "TFR", /* top front right */
+ [15] = "TBL", /* top back left */
+ [16] = "TBC", /* top back center */
+ [17] = "TBR", /* top back right */
+ [29] = "DL", /* downmix left */
+ [30] = "DR", /* downmix right */
+ [31] = "WL", /* wide left */
+ [32] = "WR", /* wide right */
+ [33] = "SDL", /* surround direct left */
+ [34] = "SDR", /* surround direct right */
+ [35] = "LFE2", /* low frequency 2 */
+};
+
+static const char *get_channel_name(int channel_id)
+{
+ if (channel_id < 0 || channel_id >= FF_ARRAY_ELEMS(channel_names))
+ return NULL;
+ return channel_names[channel_id];
+}
+
+static const struct {
+ const char *name;
+ int nb_channels;
+ uint64_t layout;
+} channel_layout_map[] = {
+ { "mono", 1, AV_CH_LAYOUT_MONO },
+ { "stereo", 2, AV_CH_LAYOUT_STEREO },
+ { "stereo", 2, AV_CH_LAYOUT_STEREO_DOWNMIX },
+ { "2.1", 3, AV_CH_LAYOUT_2POINT1 },
+ { "3.0", 3, AV_CH_LAYOUT_SURROUND },
+ { "3.0(back)", 3, AV_CH_LAYOUT_2_1 },
+ { "3.1", 4, AV_CH_LAYOUT_3POINT1 },
+ { "4.0", 4, AV_CH_LAYOUT_4POINT0 },
+ { "quad", 4, AV_CH_LAYOUT_QUAD },
+ { "quad(side)", 4, AV_CH_LAYOUT_2_2 },
+ { "4.1", 5, AV_CH_LAYOUT_4POINT1 },
+ { "5.0", 5, AV_CH_LAYOUT_5POINT0 },
+ { "5.0", 5, AV_CH_LAYOUT_5POINT0_BACK },
+ { "5.1", 6, AV_CH_LAYOUT_5POINT1 },
+ { "5.1", 6, AV_CH_LAYOUT_5POINT1_BACK },
+ { "6.0", 6, AV_CH_LAYOUT_6POINT0 },
+ { "6.0(front)", 6, AV_CH_LAYOUT_6POINT0_FRONT },
+ { "hexagonal", 6, AV_CH_LAYOUT_HEXAGONAL },
+ { "6.1", 7, AV_CH_LAYOUT_6POINT1 },
+ { "6.1", 7, AV_CH_LAYOUT_6POINT1_BACK },
+ { "6.1(front)", 7, AV_CH_LAYOUT_6POINT1_FRONT },
+ { "7.0", 7, AV_CH_LAYOUT_7POINT0 },
+ { "7.0(front)", 7, AV_CH_LAYOUT_7POINT0_FRONT },
+ { "7.1", 8, AV_CH_LAYOUT_7POINT1 },
+ { "7.1(wide)", 8, AV_CH_LAYOUT_7POINT1_WIDE },
+ { "7.1(wide)", 8, AV_CH_LAYOUT_7POINT1_WIDE_BACK },
+ { "octagonal", 8, AV_CH_LAYOUT_OCTAGONAL },
+ { "downmix", 2, AV_CH_LAYOUT_STEREO_DOWNMIX, },
+ { 0 }
+};
+
+static uint64_t get_channel_layout_single(const char *name, int name_len)
+{
+ int i;
+ char *end;
+ int64_t layout;
+
+ for (i = 0; i < FF_ARRAY_ELEMS(channel_layout_map) - 1; i++) {
+ if (strlen(channel_layout_map[i].name) == name_len &&
+ !memcmp(channel_layout_map[i].name, name, name_len))
+ return channel_layout_map[i].layout;
+ }
+ for (i = 0; i < FF_ARRAY_ELEMS(channel_names); i++)
+ if (channel_names[i] &&
+ strlen(channel_names[i]) == name_len &&
+ !memcmp(channel_names[i], name, name_len))
+ return (int64_t)1 << i;
+ i = strtol(name, &end, 10);
+ if (end - name == name_len ||
+ (end + 1 - name == name_len && *end == 'c'))
+ return av_get_default_channel_layout(i);
+ layout = strtoll(name, &end, 0);
+ if (end - name == name_len)
+ return FFMAX(layout, 0);
+ return 0;
+}
+
+uint64_t av_get_channel_layout(const char *name)
+{
+ const char *n, *e;
+ const char *name_end = name + strlen(name);
+ int64_t layout = 0, layout_single;
+
+ for (n = name; n < name_end; n = e + 1) {
+ for (e = n; e < name_end && *e != '+' && *e != '|'; e++);
+ layout_single = get_channel_layout_single(n, e - n);
+ if (!layout_single)
+ return 0;
+ layout |= layout_single;
+ }
+ return layout;
+}
+
+void av_get_channel_layout_string(char *buf, int buf_size,
+ int nb_channels, uint64_t channel_layout)
+{
+ int i;
+
+ if (nb_channels <= 0)
+ nb_channels = av_get_channel_layout_nb_channels(channel_layout);
+
+ for (i = 0; channel_layout_map[i].name; i++)
+ if (nb_channels == channel_layout_map[i].nb_channels &&
+ channel_layout == channel_layout_map[i].layout) {
+ av_strlcpy(buf, channel_layout_map[i].name, buf_size);
+ return;
+ }
+
+ snprintf(buf, buf_size, "%d channels", nb_channels);
+ if (channel_layout) {
+ int i, ch;
+ av_strlcat(buf, " (", buf_size);
+ for (i = 0, ch = 0; i < 64; i++) {
+ if ((channel_layout & (UINT64_C(1) << i))) {
+ const char *name = get_channel_name(i);
+ if (name) {
+ if (ch > 0)
+ av_strlcat(buf, "|", buf_size);
+ av_strlcat(buf, name, buf_size);
+ }
+ ch++;
+ }
+ }
+ av_strlcat(buf, ")", buf_size);
+ }
+}
+
+int av_get_channel_layout_nb_channels(uint64_t channel_layout)
+{
+ return av_popcount64(channel_layout);
+}
+
+uint64_t av_get_default_channel_layout(int nb_channels)
+{
+ switch(nb_channels) {
+ case 1: return AV_CH_LAYOUT_MONO;
+ case 2: return AV_CH_LAYOUT_STEREO;
+ case 3: return AV_CH_LAYOUT_SURROUND;
+ case 4: return AV_CH_LAYOUT_QUAD;
+ case 5: return AV_CH_LAYOUT_5POINT0;
+ case 6: return AV_CH_LAYOUT_5POINT1;
+ case 7: return AV_CH_LAYOUT_6POINT1;
+ case 8: return AV_CH_LAYOUT_7POINT1;
+ default: return 0;
+ }
+}
+
+int av_get_channel_layout_channel_index(uint64_t channel_layout,
+ uint64_t channel)
+{
+ if (!(channel_layout & channel) ||
+ av_get_channel_layout_nb_channels(channel) != 1)
+ return AVERROR(EINVAL);
+ channel_layout &= channel - 1;
+ return av_get_channel_layout_nb_channels(channel_layout);
+}
+
+const char *av_get_channel_name(uint64_t channel)
+{
+ int i;
+ if (av_get_channel_layout_nb_channels(channel) != 1)
+ return NULL;
+ for (i = 0; i < 64; i++)
+ if ((1ULL<
+#include
+#include
+#include
+
+
+#define _COMPONENT ACPI_EXECUTER
+ ACPI_MODULE_NAME ("exoparg3")
+
+
+/*!
+ * Naming convention for AML interpreter execution routines.
+ *
+ * The routines that begin execution of AML opcodes are named with a common
+ * convention based upon the number of arguments, the number of target operands,
+ * and whether or not a value is returned:
+ *
+ * AcpiExOpcode_xA_yT_zR
+ *
+ * Where:
+ *
+ * xA - ARGUMENTS: The number of arguments (input operands) that are
+ * required for this opcode type (1 through 6 args).
+ * yT - TARGETS: The number of targets (output operands) that are required
+ * for this opcode type (0, 1, or 2 targets).
+ * zR - RETURN VALUE: Indicates whether this opcode type returns a value
+ * as the function return (0 or 1).
+ *
+ * The AcpiExOpcode* functions are called via the Dispatcher component with
+ * fully resolved operands.
+!*/
+
+
+/*******************************************************************************
+ *
+ * FUNCTION: acpi_ex_opcode_3A_0T_0R
+ *
+ * PARAMETERS: walk_state - Current walk state
+ *
+ * RETURN: Status
+ *
+ * DESCRIPTION: Execute Triadic operator (3 operands)
+ *
+ ******************************************************************************/
+
+acpi_status
+acpi_ex_opcode_3A_0T_0R (
+ struct acpi_walk_state *walk_state)
+{
+ union acpi_operand_object **operand = &walk_state->operands[0];
+ struct acpi_signal_fatal_info *fatal;
+ acpi_status status = AE_OK;
+
+
+ ACPI_FUNCTION_TRACE_STR ("ex_opcode_3A_0T_0R",
+ acpi_ps_get_opcode_name (walk_state->opcode));
+
+
+ switch (walk_state->opcode) {
+ case AML_FATAL_OP: /* Fatal (fatal_type fatal_code fatal_arg) */
+
+ ACPI_DEBUG_PRINT ((ACPI_DB_INFO,
+ "fatal_op: Type %X Code %X Arg %X <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<\n",
+ (u32) operand[0]->integer.value,
+ (u32) operand[1]->integer.value,
+ (u32) operand[2]->integer.value));
+
+ fatal = ACPI_MEM_ALLOCATE (sizeof (struct acpi_signal_fatal_info));
+ if (fatal) {
+ fatal->type = (u32) operand[0]->integer.value;
+ fatal->code = (u32) operand[1]->integer.value;
+ fatal->argument = (u32) operand[2]->integer.value;
+ }
+
+ /* Always signal the OS! */
+
+ status = acpi_os_signal (ACPI_SIGNAL_FATAL, fatal);
+
+ /* Might return while OS is shutting down, just continue */
+
+ ACPI_MEM_FREE (fatal);
+ break;
+
+
+ default:
+
+ ACPI_REPORT_ERROR (("acpi_ex_opcode_3A_0T_0R: Unknown opcode %X\n",
+ walk_state->opcode));
+ status = AE_AML_BAD_OPCODE;
+ goto cleanup;
+ }
+
+
+cleanup:
+
+ return_ACPI_STATUS (status);
+}
+
+
+/*******************************************************************************
+ *
+ * FUNCTION: acpi_ex_opcode_3A_1T_1R
+ *
+ * PARAMETERS: walk_state - Current walk state
+ *
+ * RETURN: Status
+ *
+ * DESCRIPTION: Execute Triadic operator (3 operands)
+ *
+ ******************************************************************************/
+
+acpi_status
+acpi_ex_opcode_3A_1T_1R (
+ struct acpi_walk_state *walk_state)
+{
+ union acpi_operand_object **operand = &walk_state->operands[0];
+ union acpi_operand_object *return_desc = NULL;
+ char *buffer;
+ acpi_status status = AE_OK;
+ acpi_integer index;
+ acpi_size length;
+
+
+ ACPI_FUNCTION_TRACE_STR ("ex_opcode_3A_1T_1R",
+ acpi_ps_get_opcode_name (walk_state->opcode));
+
+
+ switch (walk_state->opcode) {
+ case AML_MID_OP: /* Mid (Source[0], Index[1], Length[2], Result[3]) */
+
+ /*
+ * Create the return object. The Source operand is guaranteed to be
+ * either a String or a Buffer, so just use its type.
+ */
+ return_desc = acpi_ut_create_internal_object (
+ ACPI_GET_OBJECT_TYPE (operand[0]));
+ if (!return_desc) {
+ status = AE_NO_MEMORY;
+ goto cleanup;
+ }
+
+ /* Get the Integer values from the objects */
+
+ index = operand[1]->integer.value;
+ length = (acpi_size) operand[2]->integer.value;
+
+ /*
+ * If the index is beyond the length of the String/Buffer, or if the
+ * requested length is zero, return a zero-length String/Buffer
+ */
+ if ((index < operand[0]->string.length) &&
+ (length > 0)) {
+ /* Truncate request if larger than the actual String/Buffer */
+
+ if ((index + length) >
+ operand[0]->string.length) {
+ length = (acpi_size) operand[0]->string.length -
+ (acpi_size) index;
+ }
+
+ /* Allocate a new buffer for the String/Buffer */
+
+ buffer = ACPI_MEM_CALLOCATE ((acpi_size) length + 1);
+ if (!buffer) {
+ status = AE_NO_MEMORY;
+ goto cleanup;
+ }
+
+ /* Copy the portion requested */
+
+ ACPI_MEMCPY (buffer, operand[0]->string.pointer + index,
+ length);
+
+ /* Set the length of the new String/Buffer */
+
+ return_desc->string.pointer = buffer;
+ return_desc->string.length = (u32) length;
+ }
+
+ /* Mark buffer initialized */
+
+ return_desc->buffer.flags |= AOPOBJ_DATA_VALID;
+ break;
+
+
+ default:
+
+ ACPI_REPORT_ERROR (("acpi_ex_opcode_3A_0T_0R: Unknown opcode %X\n",
+ walk_state->opcode));
+ status = AE_AML_BAD_OPCODE;
+ goto cleanup;
+ }
+
+ /* Store the result in the target */
+
+ status = acpi_ex_store (return_desc, operand[3], walk_state);
+
+cleanup:
+
+ /* Delete return object on error */
+
+ if (ACPI_FAILURE (status)) {
+ acpi_ut_remove_reference (return_desc);
+ }
+
+ /* Set the return object and exit */
+
+ if (!walk_state->result_obj) {
+ walk_state->result_obj = return_desc;
+ }
+ return_ACPI_STATUS (status);
+}
+
+
diff --git a/pool/shard000/C/0008930_q2.c b/pool/shard000/C/0008930_q2.c
new file mode 100644
index 0000000000000000000000000000000000000000..35e2839bdd7d5d7c2f114a8fab84f854a11680e0
--- /dev/null
+++ b/pool/shard000/C/0008930_q2.c
@@ -0,0 +1,54 @@
+/* { dg-do run } */
+
+#include
+
+#include "init2.h"
+#include "dump.h"
+
+#ifdef __cplusplus
+extern "C"
+#endif
+void abort (void);
+
+int main (void)
+{
+ struct R1 A1 = My_R1;
+ struct R1 B1 = My_R1;
+
+ struct R2 A2 = My_R2;
+ struct R2 B2 = My_R2;
+
+ put ("A1 :");
+ dump (&A1, sizeof (struct R1));
+ new_line ();
+ /* { dg-output "A1 : e2 59 d1 48 b4 aa d9 bb.*\n" } */
+
+ put ("B1 :");
+ dump (&B1, sizeof (struct R1));
+ new_line ();
+ /* { dg-output "B1 : e2 59 d1 48 b4 aa d9 bb.*\n" } */
+
+ put ("A2 :");
+ dump (&A2, sizeof (struct R2));
+ new_line ();
+ /* { dg-output "A2 : 84 8d 15 9e 15 5b 35 df.*\n" } */
+
+ put ("B2 :");
+ dump (&B2, sizeof (struct R2));
+ new_line ();
+ /* { dg-output "B2 : 84 8d 15 9e 15 5b 35 df.*\n" } */
+
+ if (A1.S1 != B1.S1) abort ();
+
+ if (A1.S1 != 2) abort ();
+
+ if (A2.S1 != B2.S1) abort ();
+
+ if (A2.S1 != 2) abort ();
+
+ if (A1.I != B1.I || A1.A1 != B1.A1) abort ();
+
+ if (A2.I != B2.I || A2.A1 != B2.A1) abort ();
+
+ return 0;
+}
diff --git a/pool/shard000/C/0008968_mirandr.c b/pool/shard000/C/0008968_mirandr.c
new file mode 100644
index 0000000000000000000000000000000000000000..81bf7f7f0c4ff8951b6d9943a2df43797340db29
--- /dev/null
+++ b/pool/shard000/C/0008968_mirandr.c
@@ -0,0 +1,98 @@
+/*
+ * $XFree86: xc/programs/Xserver/randr/mirandr.c,v 1.7 2002/10/14 18:01:42 keithp Exp $
+ *
+ * Copyright © 2000, Compaq Computer Corporation,
+ * Copyright © 2002, Hewlett Packard, Inc.
+ *
+ * Permission to use, copy, modify, distribute, and sell this software and its
+ * documentation for any purpose is hereby granted without fee, provided that
+ * the above copyright notice appear in all copies and that both that
+ * copyright notice and this permission notice appear in supporting
+ * documentation, and that the name of Compaq or HP not be used in advertising
+ * or publicity pertaining to distribution of the software without specific,
+ * written prior permission. HP makes no representations about the
+ * suitability of this software for any purpose. It is provided "as is"
+ * without express or implied warranty.
+ *
+ * HP DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL HP
+ * BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
+ * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
+ * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ *
+ * Author: Jim Gettys, HP Labs, Hewlett-Packard, Inc.
+ */
+
+
+#include "scrnintstr.h"
+#include "mi.h"
+#include "randr.h"
+#include "randrstr.h"
+#include
+
+/*
+ * This function assumes that only a single depth can be
+ * displayed at a time, but that all visuals of that depth
+ * can be displayed simultaneously. It further assumes that
+ * only a single size is available. Hardware providing
+ * additional capabilties should use different code.
+ * XXX what to do here....
+ */
+
+Bool
+miRRGetInfo (ScreenPtr pScreen, Rotation *rotations)
+{
+ int i;
+ Bool setConfig = FALSE;
+
+ *rotations = RR_Rotate_0;
+ for (i = 0; i < pScreen->numDepths; i++)
+ {
+ if (pScreen->allowedDepths[i].numVids)
+ {
+ RRScreenSizePtr pSize;
+
+ pSize = RRRegisterSize (pScreen,
+ pScreen->width,
+ pScreen->height,
+ pScreen->mmWidth,
+ pScreen->mmHeight);
+ if (!pSize)
+ return FALSE;
+ if (!setConfig)
+ {
+ RRSetCurrentConfig (pScreen, RR_Rotate_0, 0, pSize);
+ setConfig = TRUE;
+ }
+ }
+ }
+ return TRUE;
+}
+
+/*
+ * Any hardware that can actually change anything will need something
+ * different here
+ */
+Bool
+miRRSetConfig (ScreenPtr pScreen,
+ Rotation rotation,
+ int rate,
+ RRScreenSizePtr pSize)
+{
+ return TRUE;
+}
+
+
+Bool
+miRandRInit (ScreenPtr pScreen)
+{
+ rrScrPrivPtr rp;
+
+ if (!RRScreenInit (pScreen))
+ return FALSE;
+ rp = rrGetScrPriv(pScreen);
+ rp->rrGetInfo = miRRGetInfo;
+ rp->rrSetConfig = miRRSetConfig;
+ return TRUE;
+}
diff --git a/pool/shard000/C/0008975_findsuper.c b/pool/shard000/C/0008975_findsuper.c
new file mode 100644
index 0000000000000000000000000000000000000000..6b5e16fc1cdd1c775dd95440fd0c8bb34ab33d49
--- /dev/null
+++ b/pool/shard000/C/0008975_findsuper.c
@@ -0,0 +1,265 @@
+/*
+ * findsuper --- quick hacked up program to find ext2 superblocks.
+ *
+ * This is a hack, and really shouldn't be installed anywhere. If you
+ * need a program which does this sort of functionality, please try
+ * using gpart program.
+ *
+ * Portions Copyright 1998-2000, Theodore Ts'o.
+ *
+ * Well, here's my linux version of findsuper.
+ * I'm sure you coulda done it faster. :)
+ * IMHO there isn't as much interesting data to print in the
+ * linux superblock as there is in the SunOS superblock--disk geometry is
+ * not there...and linux seems to update the dates in all the superblocks.
+ * SunOS doesn't ever touch the backup superblocks after the fs is created,
+ * as far as I can tell, so the date is more interesting IMHO and certainly
+ * marks which superblocks are backup ones.
+ *
+ * I wanted to add msdos support, but I couldn't make heads or tails
+ * of the kernel include files to find anything I could look for in msdos.
+ *
+ * Reading every block of a Sun partition is fairly quick. Doing the
+ * same under linux (slower hardware I suppose) just isn't the same.
+ * It might be more useful to default to reading the first (second?) block
+ * on each cyl; however, if the disk geometry is wrong, this is useless.
+ * But ya could still get the cyl size to print the numbers as cyls instead
+ * of blocks...
+ *
+ * run this as (for example)
+ * findsuper /dev/hda
+ * findsuper /dev/hda 437760 1024 (my disk has cyls of 855*512)
+ *
+ * I suppose the next step is to figgure out a way to determine if
+ * the block found is the first superblock somehow, and if so, build
+ * a partition table from the superblocks found... but this is still
+ * useful as is.
+ *
+ * Steve
+ * ssd@nevets.oau.org
+ * ssd@mae.engr.ucf.edu
+ *
+ * Additional notes by Andreas Dilger :
+ * - fixed to support > 2G devices by using lseek64
+ * - add reliability checking for the superblock to avoid random garbage
+ * - add adaptive progress meter
+ *
+ * It _should_ also handle signals and tell you the ending block, so
+ * that you can resume at a later time, but it doesn't yet...
+ *
+ * Note that gpart does not appear to find all superblocks that aren't aligned
+ * with the start of a possible partition, so it is not useful in systems
+ * with LVM or similar setups which don't use fat partition alignment.
+ *
+ * %Begin-Header%
+ * This file may be redistributed under the terms of the GNU Public
+ * License.
+ * %End-Header%
+ */
+
+/*
+ * Documentation addendum added by Andreas dwguest@win.tue.nl/aeb@cwi.nl
+ *
+ * The program findsuper is a utility that scans a disk and finds
+ * copies of ext2 superblocks (by checking for the ext2 signature).
+ *
+ * For each superblock found, it prints the offset in bytes, the
+ * offset in 1024-byte blocks, the size of the ext2 partition in fs
+ * blocks, the filesystem blocksize (in bytes), the block group number
+ * (always 0 for older ext2 systems), and a timestamp (s_mtime).
+ *
+ * This program can be used to retrieve partitions that have been
+ * lost. The superblock for block group 0 is found 1 block (2
+ * sectors) after the partition start.
+ *
+ * For new systems that have a block group number in the superblock it
+ * is immediately clear which superblock is the first of a partition.
+ * For old systems where no group numbers are given, the first
+ * superblock can be recognised by the timestamp: all superblock
+ * copies have the creation time in s_mtime, except the first, which
+ * has the last time e2fsck or tune2fs wrote to the filesystem.
+ *
+ */
+
+#define _FILE_OFFSET_BITS 64
+
+#include "config.h"
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+
+#include "ext2fs/ext2_fs.h"
+#include "ext2fs/ext2fs.h"
+#include "nls-enable.h"
+
+#undef DEBUG
+
+#ifdef DEBUG
+#define WHY(fmt, arg...) { printf("\r%Ld: " fmt, sk, ##arg) ; continue; }
+#else
+#define WHY(fmt, arg...) { continue; }
+#endif
+
+static void usage(void)
+{
+ fprintf(stderr,
+ _("Usage: findsuper device [skipbytes [startkb]]\n"));
+ exit(1);
+}
+
+
+int main(int argc, char *argv[])
+{
+ int skiprate=512; /* one sector */
+ loff_t sk=0, skl=0;
+ int fd;
+ char *s;
+ time_t tm, last = time(0);
+ loff_t interval = 1024 * 1024;
+ int c, print_jnl_copies = 0;
+ const char * device_name;
+ struct ext2_super_block ext2;
+ /* interesting fields: EXT2_SUPER_MAGIC
+ * s_blocks_count s_log_block_size s_mtime s_magic s_lastcheck */
+
+#ifdef ENABLE_NLS
+ setlocale(LC_MESSAGES, "");
+ setlocale(LC_CTYPE, "");
+ bindtextdomain(NLS_CAT_NAME, LOCALEDIR);
+ textdomain(NLS_CAT_NAME);
+ set_com_err_gettext(gettext);
+#endif
+
+ while ((c = getopt (argc, argv, "j")) != EOF) {
+ switch (c) {
+ case 'j':
+ print_jnl_copies++;
+ break;
+ default:
+ usage();
+ }
+ }
+
+ if (optind == argc)
+ usage();
+
+ device_name = argv[optind++];
+
+ if (optind < argc) {
+ skiprate = strtol(argv[optind], &s, 0);
+ if (s == argv[optind]) {
+ fprintf(stderr,_("skipbytes should be a number, not %s\n"), s);
+ exit(1);
+ }
+ optind++;
+ }
+ if (skiprate & 0x1ff) {
+ fprintf(stderr,
+ _("skipbytes must be a multiple of the sector size\n"));
+ exit(2);
+ }
+ if (optind < argc) {
+ sk = skl = strtoll(argv[optind], &s, 0) << 10;
+ if (s == argv[optind]) {
+ fprintf(stderr,
+ _("startkb should be a number, not %s\n"), s);
+ exit(1);
+ }
+ optind++;
+ }
+ if (sk < 0) {
+ fprintf(stderr, _("startkb should be positive, not %Lu\n"), sk);
+ exit(1);
+ }
+
+ fd = open(device_name, O_RDONLY);
+ if (fd < 0) {
+ perror(device_name);
+ exit(1);
+ }
+
+ /* Now, go looking for the superblock! */
+ printf(_("starting at %Lu, with %u byte increments\n"), sk, skiprate);
+ if (print_jnl_copies)
+ printf(_("[*] probably superblock written in the ext3 "
+ "journal superblock,\n\tso start/end/grp wrong\n"));
+ printf(_("byte_offset byte_start byte_end fs_blocks blksz grp last_mount_time sb_uuid label\n"));
+ for (; lseek64(fd, sk, SEEK_SET) != -1 &&
+ read(fd, &ext2, 512) == 512; sk += skiprate) {
+ static unsigned char last_uuid[16] = "blah";
+ unsigned long long bsize, grpsize;
+ int jnl_copy, sb_offset;
+
+ if (sk && !(sk & (interval - 1))) {
+ time_t now, diff;
+
+ now = time(0);
+ diff = now - last;
+
+ if (diff > 0) {
+ s = ctime(&now);
+ s[24] = 0;
+ printf("\r%11Lu: %8LukB/s @ %s", sk,
+ (((sk - skl)) / diff) >> 10, s);
+ fflush(stdout);
+ }
+ if (diff < 5)
+ interval <<= 1;
+ else if (diff > 20)
+ interval >>= 1;
+ last = now;
+ skl = sk;
+ }
+ if (ext2.s_magic != EXT2_SUPER_MAGIC)
+ continue;
+ if (ext2.s_log_block_size > 6)
+ WHY("log block size > 6 (%u)\n", ext2.s_log_block_size);
+ if (ext2fs_r_blocks_count(&ext2) > ext2fs_blocks_count(&ext2))
+ WHY("r_blocks_count > blocks_count (%u > %u)\n",
+ ext2fs_r_blocks_count(&ext2),
+ ext2fs_blocks_count(&ext2));
+ if (ext2fs_free_blocks_count(&ext2) > ext2fs_blocks_count(&ext2))
+ WHY("free_blocks_count > blocks_count\n (%u > %u)\n",
+ ext2fs_free_blocks_count(&ext2),
+ ext2fs_blocks_count(&ext2));
+ if (ext2.s_free_inodes_count > ext2.s_inodes_count)
+ WHY("free_inodes_count > inodes_count (%u > %u)\n",
+ ext2.s_free_inodes_count, ext2.s_inodes_count);
+
+ tm = ext2.s_mtime;
+ s = ctime(&tm);
+ s[24] = 0;
+ bsize = 1 << (ext2.s_log_block_size + 10);
+ grpsize = bsize * ext2.s_blocks_per_group;
+ if (memcmp(ext2.s_uuid, last_uuid, sizeof(last_uuid)) == 0 &&
+ ext2.s_rev_level > 0 && ext2.s_block_group_nr == 0) {
+ jnl_copy = 1;
+ } else {
+ jnl_copy = 0;
+ memcpy(last_uuid, ext2.s_uuid, sizeof(last_uuid));
+ }
+ if (ext2.s_block_group_nr == 0 || bsize == 1024)
+ sb_offset = 1024;
+ else
+ sb_offset = 0;
+ if (jnl_copy && !print_jnl_copies)
+ continue;
+ printf("\r%11Lu %11Lu%s %11Lu%s %9u %5Lu %4u%s %s %02x%02x%02x%02x %s\n",
+ sk, sk - ext2.s_block_group_nr * grpsize - sb_offset,
+ jnl_copy ? "*":" ",
+ sk + ext2fs_blocks_count(&ext2) * bsize -
+ ext2.s_block_group_nr * grpsize - sb_offset,
+ jnl_copy ? "*" : " ", ext2fs_blocks_count(&ext2), bsize,
+ ext2.s_block_group_nr, jnl_copy ? "*" : " ", s,
+ ext2.s_uuid[0], ext2.s_uuid[1],
+ ext2.s_uuid[2], ext2.s_uuid[3], ext2.s_volume_name);
+ }
+ printf(_("\n%11Lu: finished with errno %d\n"), sk, errno);
+ close(fd);
+
+ return errno;
+}
diff --git a/pool/shard000/C/0008989_nuse-vif-rawsock.c b/pool/shard000/C/0008989_nuse-vif-rawsock.c
new file mode 100644
index 0000000000000000000000000000000000000000..99f708e48da3ed8ba581fe500d052e6c291a5bf6
--- /dev/null
+++ b/pool/shard000/C/0008989_nuse-vif-rawsock.c
@@ -0,0 +1,110 @@
+/*
+ * raw socket based virtual network interface feature for NUSE
+ * Copyright (c) 2015 Hajime Tazaki
+ *
+ * Author: Hajime Tazaki
+ */
+
+#include
+#include
+#include
+#include
+#include
+#include
+#define _GNU_SOURCE /* Get RTLD_NEXT */
+#include
+#include
+#include
+#include
+#include
+#include "nuse-hostcalls.h"
+#include "nuse-vif.h"
+#include "nuse.h"
+#include "nuse-libc.h"
+
+void
+nuse_vif_raw_read(struct nuse_vif *vif, struct SimDevice *dev)
+{
+ int sock = vif->sock;
+ char buf[8192];
+ ssize_t size;
+
+ while (1) {
+ size = host_read(sock, buf, sizeof(buf));
+ if (size < 0) {
+ printf("read error errno=%d\n", errno);
+ host_close(sock);
+ return;
+ } else if (size == 0) {
+ printf("read error: closed. errno=%d\n", errno);
+ host_close(sock);
+ return;
+ }
+
+ nuse_dev_rx(dev, buf, size);
+ }
+
+ printf("%s: should not reach", __func__);
+}
+
+void
+nuse_vif_raw_write(struct nuse_vif *vif, struct SimDevice *dev,
+ unsigned char *data, int len)
+{
+ int sock = vif->sock;
+ int ret = host_write(sock, data, len);
+
+ if (ret == -1)
+ perror("write");
+}
+
+void *
+nuse_vif_raw_create(const char *ifname)
+{
+ int err;
+ int sock = host_socket(PF_PACKET, SOCK_RAW, htons(ETH_P_ALL));
+ struct sockaddr_ll ll;
+ struct nuse_vif *vif;
+
+ if (sock < 0)
+ perror("socket");
+
+ memset(&ll, 0, sizeof(ll));
+
+ ll.sll_family = AF_PACKET;
+ ll.sll_ifindex = if_nametoindex(ifname);
+ ll.sll_protocol = htons(ETH_P_ALL);
+ err = host_bind(sock, (struct sockaddr *)&ll, sizeof(ll));
+ if (err)
+ perror("bind");
+
+ vif = malloc(sizeof(struct nuse_vif));
+ vif->sock = sock;
+ vif->type = NUSE_VIF_RAWSOCK; /* FIXME */
+ return vif;
+}
+
+void
+nuse_vif_raw_delete(struct nuse_vif *vif)
+{
+ int sock = vif->sock;
+ free(vif);
+ host_close(sock);
+}
+
+static struct nuse_vif_impl nuse_vif_rawsock = {
+ .read = nuse_vif_raw_read,
+ .write = nuse_vif_raw_write,
+ .create = nuse_vif_raw_create,
+ .delete = nuse_vif_raw_delete,
+};
+
+extern struct nuse_vif_impl *nuse_vif[NUSE_VIF_MAX];
+
+int __attribute__((constructor))
+nuse_vif_rawsock_init(void)
+{
+ nuse_vif[NUSE_VIF_RAWSOCK] = &nuse_vif_rawsock;
+ return 0;
+}
+__define_initcall(nuse_vif_rawsock_init, 1);
diff --git a/pool/shard000/C/0008994_main.c b/pool/shard000/C/0008994_main.c
new file mode 100644
index 0000000000000000000000000000000000000000..46f9e4c114dad45b03bc7c7a37a66f06fc60df87
--- /dev/null
+++ b/pool/shard000/C/0008994_main.c
@@ -0,0 +1,233 @@
+/*
+ * Copyright (c) 1983-2013 Trevor Wishart and Composers Desktop Project Ltd
+ * http://www.trevorwishart.co.uk
+ * http://www.composersdesktop.com
+ *
+ This file is part of the CDP System.
+
+ The CDP System is free software; you can redistribute it
+ and/or modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The CDP System is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the CDP System; if not, write to the Free Software
+ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA
+ *
+ */
+
+
+
+#include
+#include
+#include
+#include
+#include