Blame fuzz/mem.h

Packit Service 4684c1
/*
Packit Service 4684c1
 * Copyright (C) 2017 Nikos Mavrogiannopoulos
Packit Service 4684c1
 *
Packit Service 4684c1
 * Permission is hereby granted, free of charge, to any person obtaining a
Packit Service 4684c1
 * copy of this software and associated documentation files (the "Software"),
Packit Service 4684c1
 * to deal in the Software without restriction, including without limitation
Packit Service 4684c1
 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
Packit Service 4684c1
 * and/or sell copies of the Software, and to permit persons to whom the
Packit Service 4684c1
 * Software is furnished to do so, subject to the following conditions:
Packit Service 4684c1
 *
Packit Service 4684c1
 * The above copyright notice and this permission notice shall be included in
Packit Service 4684c1
 * all copies or substantial portions of the Software.
Packit Service 4684c1
 *
Packit Service 4684c1
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
Packit Service 4684c1
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
Packit Service 4684c1
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
Packit Service 4684c1
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
Packit Service 4684c1
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
Packit Service 4684c1
 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
Packit Service 4684c1
 * DEALINGS IN THE SOFTWARE.
Packit Service 4684c1
 *
Packit Service 4684c1
 */
Packit Service 4684c1
Packit Service 4684c1
#ifndef MEM_H
Packit Service 4684c1
# define MEM_H
Packit Service 4684c1
Packit Service 4684c1
typedef struct mem_st {
Packit Service 4684c1
	const uint8_t *data;
Packit Service 4684c1
	size_t size;
Packit Service 4684c1
} mem_st;
Packit Service 4684c1
Packit Service 4684c1
#define MIN(x,y) ((x)<(y)?(x):(y))
Packit Service 4684c1
static ssize_t
Packit Service 4684c1
mem_push(gnutls_transport_ptr_t tr, const void *data, size_t len)
Packit Service 4684c1
{
Packit Service 4684c1
	return len;
Packit Service 4684c1
}
Packit Service 4684c1
Packit Service 4684c1
static ssize_t mem_pull(gnutls_transport_ptr_t tr, void *data, size_t len)
Packit Service 4684c1
{
Packit Service 4684c1
	struct mem_st *p = (struct mem_st *)tr;
Packit Service 4684c1
Packit Service 4684c1
	if (p->size == 0) {
Packit Service 4684c1
		return 0;
Packit Service 4684c1
	}
Packit Service 4684c1
Packit Service 4684c1
	len = MIN(len, p->size);
Packit Service 4684c1
	memcpy(data, p->data, len);
Packit Service 4684c1
Packit Service 4684c1
	p->size -= len;
Packit Service 4684c1
	p->data += len;
Packit Service 4684c1
Packit Service 4684c1
	return len;
Packit Service 4684c1
}
Packit Service 4684c1
Packit Service 4684c1
static
Packit Service 4684c1
int mem_pull_timeout(gnutls_transport_ptr_t tr, unsigned int ms)
Packit Service 4684c1
{
Packit Service 4684c1
	struct mem_st *p = (struct mem_st *)tr;
Packit Service 4684c1
Packit Service 4684c1
	if (p->size > 0)
Packit Service 4684c1
		return 1;	/* available data */
Packit Service 4684c1
	else
Packit Service 4684c1
		return 0;	/* timeout */
Packit Service 4684c1
}
Packit Service 4684c1
Packit Service 4684c1
#endif