Browse Source

faux.file: Revert chunk engine

Serj Kalichev 4 years ago
parent
commit
7b13f85d91
4 changed files with 3 additions and 160 deletions
  1. 1 0
      faux/base/io.c
  2. 0 1
      faux/file/Makefile.am
  3. 0 128
      faux/file/chunk.c
  4. 2 31
      faux/file/private.h

+ 1 - 0
faux/base/io.c

@@ -84,6 +84,7 @@ ssize_t faux_write_block(int fd, const void *buf, size_t n) {
  * @param [in] buf Buffer to write.
  * @param [in] n Number of bytes to write.
  * @return Number of bytes readed or < 0 on error.
+ * 0 bytes indicates EOF
  */
 ssize_t faux_read(int fd, void *buf, size_t n) {
 

+ 0 - 1
faux/file/Makefile.am

@@ -1,4 +1,3 @@
 libfaux_la_SOURCES += \
-	faux/file/chunk.c \
 	faux/file/file.c \
 	faux/file/private.h

+ 0 - 128
faux/file/chunk.c

@@ -1,128 +0,0 @@
-#include <stdlib.h>
-#include <stdio.h>
-#include <assert.h>
-
-#include "private.h"
-
-faux_chunk_t *faux_chunk_new(size_t size) {
-
-	faux_chunk_t *chunk = NULL;
-
-	if (0 == size) // Illegal 0 size
-		return NULL;
-
-	chunk = faux_zmalloc(sizeof(*chunk));
-	if (!chunk)
-		return NULL;
-
-	// Init
-	chunk->buf = faux_zmalloc(size);
-	if (!chunk->buf) {
-		faux_free(chunk);
-		return NULL;
-	}
-	chunk->size = size;
-	chunk->start = chunk->buf;
-	chunk->end = chunk->buf;
-
-	return chunk;
-}
-
-
-void faux_chunk_free(faux_chunk_t *chunk) {
-
-	// Without assert()
-	if (!chunk)
-		return;
-
-	faux_free(chunk->buf);
-	faux_free(chunk);
-}
-
-
-size_t faux_chunk_len(faux_chunk_t *chunk) {
-
-	assert(chunk);
-	if (!chunk)
-		return 0;
-
-	return (chunk->end - chunk->start);
-}
-
-
-ssize_t faux_chunk_inc_len(faux_chunk_t *chunk, size_t inc_len) {
-
-	assert(chunk);
-	if (!chunk)
-		return -1;
-	assert((faux_chunk_len(chunk) + inc_len) <= chunk->size);
-	if ((faux_chunk_len(chunk) + inc_len) > chunk->size)
-		return -1;
-	chunk->end += inc_len;
-
-	return faux_chunk_len(chunk);
-}
-
-
-ssize_t faux_chunk_dec_len(faux_chunk_t *chunk, size_t dec_len) {
-
-	assert(chunk);
-	if (!chunk)
-		return -1;
-	assert(faux_chunk_len(chunk) >= dec_len);
-	if (faux_chunk_len(chunk) < dec_len)
-		return -1;
-	chunk->start += dec_len;
-
-	return faux_chunk_len(chunk);
-}
-
-
-ssize_t faux_chunk_size(faux_chunk_t *chunk) {
-
-	assert(chunk);
-	if (!chunk)
-		return -1;
-
-	return chunk->size;
-}
-
-
-void *faux_chunk_buf(faux_chunk_t *chunk) {
-
-	assert(chunk);
-	if (!chunk)
-		return NULL;
-
-	return chunk->buf;
-}
-
-
-void *faux_chunk_write_pos(faux_chunk_t *chunk) {
-
-	assert(chunk);
-	if (!chunk)
-		return NULL;
-
-	return chunk->end;
-}
-
-
-void *faux_chunk_read_pos(faux_chunk_t *chunk) {
-
-	assert(chunk);
-	if (!chunk)
-		return NULL;
-
-	return chunk->start;
-}
-
-
-ssize_t faux_chunk_left(faux_chunk_t *chunk) {
-
-	assert(chunk);
-	if (!chunk)
-		return -1;
-
-	return (chunk->buf + chunk->size - chunk->end);
-}

+ 2 - 31
faux/file/private.h

@@ -1,38 +1,9 @@
 #include "faux/faux.h"
+#include "faux/list.h"
 #include "faux/file.h"
 
-
-// Chunk class
-
-struct faux_chunk_s {
-	void *buf; // Allocated buffer
-	size_t size; // Size of allocated buffer
-	void *start; // Pointer to data start
-	void *end; // Pointer to data end
-};
-
-typedef struct faux_chunk_s faux_chunk_t;
-
-C_DECL_BEGIN
-
-faux_chunk_t *faux_chunk_new(size_t size);
-void faux_chunk_free(faux_chunk_t *chunk);
-size_t faux_chunk_len(faux_chunk_t *chunk);
-ssize_t faux_chunk_inc_len(faux_chunk_t *chunk, size_t inc_len);
-ssize_t faux_chunk_dec_len(faux_chunk_t *chunk, size_t dec_len);
-ssize_t faux_chunk_size(faux_chunk_t *chunk);
-void *faux_chunk_buf(faux_chunk_t *chunk);
-void *faux_chunk_write_pos(faux_chunk_t *chunk);
-void *faux_chunk_read_pos(faux_chunk_t *chunk);
-ssize_t faux_chunk_left(faux_chunk_t *chunk);
-
-C_DECL_END
-
-
-// File class
-
 /** @brief Chunk size to allocate buffer */
-#define FAUX_FILE_CHUNK_SIZE 128
+#define FAUX_FILE_CHUNK_SIZE 1024
 
 struct faux_file_s {
 	int fd; // File descriptor