Blame src/filebuf.h

Packit Service 20376f
/*
Packit Service 20376f
 * Copyright (C) the libgit2 contributors. All rights reserved.
Packit Service 20376f
 *
Packit Service 20376f
 * This file is part of libgit2, distributed under the GNU GPL v2 with
Packit Service 20376f
 * a Linking Exception. For full terms see the included COPYING file.
Packit Service 20376f
 */
Packit Service 20376f
#ifndef INCLUDE_filebuf_h__
Packit Service 20376f
#define INCLUDE_filebuf_h__
Packit Service 20376f
Packit Service 20376f
#include "fileops.h"
Packit Service 20376f
#include "hash.h"
Packit Service 20376f
#include <zlib.h>
Packit Service 20376f
Packit Service 20376f
#ifdef GIT_THREADS
Packit Service 20376f
#	define GIT_FILEBUF_THREADS
Packit Service 20376f
#endif
Packit Service 20376f
Packit Service 20376f
#define GIT_FILEBUF_HASH_CONTENTS		(1 << 0)
Packit Service 20376f
#define GIT_FILEBUF_APPEND				(1 << 2)
Packit Service 20376f
#define GIT_FILEBUF_FORCE				(1 << 3)
Packit Service 20376f
#define GIT_FILEBUF_TEMPORARY			(1 << 4)
Packit Service 20376f
#define GIT_FILEBUF_DO_NOT_BUFFER		(1 << 5)
Packit Service 20376f
#define GIT_FILEBUF_FSYNC				(1 << 6)
Packit Service 20376f
#define GIT_FILEBUF_DEFLATE_SHIFT		(7)
Packit Service 20376f
Packit Service 20376f
#define GIT_FILELOCK_EXTENSION ".lock\0"
Packit Service 20376f
#define GIT_FILELOCK_EXTLENGTH 6
Packit Service 20376f
Packit Service 20376f
typedef struct git_filebuf git_filebuf;
Packit Service 20376f
struct git_filebuf {
Packit Service 20376f
	char *path_original;
Packit Service 20376f
	char *path_lock;
Packit Service 20376f
Packit Service 20376f
	int (*write)(git_filebuf *file, void *source, size_t len);
Packit Service 20376f
Packit Service 20376f
	bool compute_digest;
Packit Service 20376f
	git_hash_ctx digest;
Packit Service 20376f
Packit Service 20376f
	unsigned char *buffer;
Packit Service 20376f
	unsigned char *z_buf;
Packit Service 20376f
Packit Service 20376f
	z_stream zs;
Packit Service 20376f
	int flush_mode;
Packit Service 20376f
Packit Service 20376f
	size_t buf_size, buf_pos;
Packit Service 20376f
	git_file fd;
Packit Service 20376f
	bool fd_is_open;
Packit Service 20376f
	bool created_lock;
Packit Service 20376f
	bool did_rename;
Packit Service 20376f
	bool do_not_buffer;
Packit Service 20376f
	bool do_fsync;
Packit Service 20376f
	int last_error;
Packit Service 20376f
};
Packit Service 20376f
Packit Service 20376f
#define GIT_FILEBUF_INIT {0}
Packit Service 20376f
Packit Service 20376f
/*
Packit Service 20376f
 * The git_filebuf object lifecycle is:
Packit Service 20376f
 * - Allocate git_filebuf, preferably using GIT_FILEBUF_INIT.
Packit Service 20376f
 *
Packit Service 20376f
 * - Call git_filebuf_open() to initialize the filebuf for use.
Packit Service 20376f
 *
Packit Service 20376f
 * - Make as many calls to git_filebuf_write(), git_filebuf_printf(),
Packit Service 20376f
 *   git_filebuf_reserve() as you like. The error codes for these
Packit Service 20376f
 *   functions don't need to be checked. They are stored internally
Packit Service 20376f
 *   by the file buffer.
Packit Service 20376f
 *
Packit Service 20376f
 * - While you are writing, you may call git_filebuf_hash() to get
Packit Service 20376f
 *   the hash of all you have written so far. This function will
Packit Service 20376f
 *   fail if any of the previous writes to the buffer failed.
Packit Service 20376f
 *
Packit Service 20376f
 * - To close the git_filebuf, you may call git_filebuf_commit() or
Packit Service 20376f
 *   git_filebuf_commit_at() to save the file, or
Packit Service 20376f
 *   git_filebuf_cleanup() to abandon the file.  All of these will
Packit Service 20376f
 *   free the git_filebuf object. Likewise, all of these will fail
Packit Service 20376f
 *   if any of the previous writes to the buffer failed, and set
Packit Service 20376f
 *   an error code accordingly.
Packit Service 20376f
 */
Packit Service 20376f
int git_filebuf_write(git_filebuf *lock, const void *buff, size_t len);
Packit Service 20376f
int git_filebuf_reserve(git_filebuf *file, void **buff, size_t len);
Packit Service 20376f
int git_filebuf_printf(git_filebuf *file, const char *format, ...) GIT_FORMAT_PRINTF(2, 3);
Packit Service 20376f
Packit Service 20376f
int git_filebuf_open(git_filebuf *lock, const char *path, int flags, mode_t mode);
Packit Service 20376f
int git_filebuf_open_withsize(git_filebuf *file, const char *path, int flags, mode_t mode, size_t size);
Packit Service 20376f
int git_filebuf_commit(git_filebuf *lock);
Packit Service 20376f
int git_filebuf_commit_at(git_filebuf *lock, const char *path);
Packit Service 20376f
void git_filebuf_cleanup(git_filebuf *lock);
Packit Service 20376f
int git_filebuf_hash(git_oid *oid, git_filebuf *file);
Packit Service 20376f
int git_filebuf_flush(git_filebuf *file);
Packit Service 20376f
int git_filebuf_stats(time_t *mtime, size_t *size, git_filebuf *file);
Packit Service 20376f
Packit Service 20376f
#endif