<commit_before>/*= -*- c-basic-offset: 4; indent-tabs-mode: nil; -*-
 *
 * librsync -- the library for network deltas
 * $Id: buf.c,v 1.22 2003/12/16 00:10:55 abo Exp $
 * 
 * Copyright (C) 2000, 2001 by <NAME> <<EMAIL>>
 * 
 * This program 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 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
 * 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, write to the Free Software
 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 */

                              /*
                               | Pick a window, Jimmy, you're leaving.
                               |   -- <NAME>, regularly
                               */


/*
 * buf.c -- Buffers that map between stdio file streams and librsync
 * streams.  As the stream consumes input and produces output, it is
 * refilled from appropriate input and output FILEs.  A dynamically
 * allocated buffer of configurable size is used as an intermediary.
 *
 * TODO: Perhaps be more efficient by filling the buffer on every call
 * even if not yet completely empty.  Check that it's really our
 * buffer, and shuffle remaining data down to the front.
 *
 * TODO: Perhaps expose a routine for shuffling the buffers.
 */

#include "include.h"

/* use fseeko instead of fseek for long file support if we have it */
#ifdef HAVE_FSEEKO
#define fseek fseeko
#endif

/*
 * Allocate and zero-fill an instance of TYPE.
 */
#define rs_alloc_struct(type)                           \
        ((type *) rs_alloc_struct0(sizeof(type), #type))

void *
rs_alloc_struct0(size_t size, char const *name)
{
    void           *p;

    if (!(p = malloc(size))) {
        logp("couldn't allocate instance of %s", name);
    }
    else memset(p, 0, size);
    return p;
}

void *
rs_alloc(size_t size, char const *name)
{
    void           *p;

    if (!(p = malloc(size))) {
        logp("couldn't allocate instance of %s", name);
    }

    return p;
}

rs_filebuf_t *rs_filebuf_new(struct asfd *asfd,
	BFILE *bfd, FILE *fp, gzFile zp, int fd,
	size_t buf_len, size_t data_len, struct cntr *cntr)
{
	rs_filebuf_t *pf=NULL;
	if(!(pf=rs_alloc_struct(rs_filebuf_t))) return NULL;

	if(!(pf->buf=(char *)rs_alloc(buf_len, "file buffer")))
	{
		free(pf);
		return NULL;
	}
	pf->buf_len=buf_len;
	pf->fp=fp;
	pf->zp=zp;
	pf->fd=fd;<commit_msg>Small tidy up of rs_buf.c.<commit_after>/*= -*- c-basic-offset: 4; indent-tabs-mode: nil; -*-
 *
 * librsync -- the library for network deltas
 * $Id: buf.c,v 1.22 2003/12/16 00:10:55 abo Exp $
 * 
 * Copyright (C) 2000, 2001 by <NAME> <<EMAIL>>
 * 
 * This program 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 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
 * 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, write to the Free Software
 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 */

                              /*
                               | Pick a window, Jimmy, you're leaving.
                               |   -- <NAME>, regularly
                               */


/*
 * buf.c -- Buffers that map between stdio file streams and librsync
 * streams.  As the stream consumes input and produces output, it is
 * refilled from appropriate input and output FILEs.  A dynamically
 * allocated buffer of configurable size is used as an intermediary.
 *
 * TODO: Perhaps be more efficient by filling the buffer on every call
 * even if not yet completely empty.  Check that it's really our
 * buffer, and shuffle remaining data down to the front.
 *
 * TODO: Perhaps expose a routine for shuffling the buffers.
 */

#include "include.h"

/* use fseeko instead of fseek for long file support if we have it */
#ifdef HAVE_FSEEKO
#define fseek fseeko
#endif

void *rs_alloc(size_t size)
{
	return calloc_w(1, size, __func__);
}

rs_filebuf_t *rs_filebuf_new(struct asfd *asfd,
	BFILE *bfd, FILE *fp, gzFile zp, int fd,
	size_t buf_len, size_t data_len, struct cntr *cntr)
{
	rs_filebuf_t *pf=NULL;
	if(!(pf=(struct rs_filebuf *)calloc_w(1,
		sizeof(struct rs_filebuf), __func__))) return NULL;

	if(!(pf->buf=(char *)calloc_w(1, buf_len, __func__)))
	{
		free(pf);
		return NULL;
	}
	pf->buf_len=buf_len;
	pf->fp=fp;
	pf->zp=zp;
	pf->fd=fd;
{'fraction_non_alphanumeric': 0.09853658536585366, 'fraction_numerical': 0.01521951219512195, 'mean_word_length': 2.8225205070842656, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 21, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1503472', 'n_tokens_mistral': 1663, 'n_tokens_neox': 1558, 'n_words': 637}