summaryrefslogtreecommitdiff
path: root/tools/cpio/src/oblok.h
diff options
context:
space:
mode:
authorWaldemar Brodkorb <wbx@openadk.org>2010-07-29 15:25:12 +0200
committerWaldemar Brodkorb <wbx@openadk.org>2010-07-29 15:25:12 +0200
commitfd6481d82ff407139157e53df28563d40bb3ad3b (patch)
treeed2ae9e08c31d1eed424793272a60c25cdec6c00 /tools/cpio/src/oblok.h
parent14804005d5b33beb6f52d4a72034acb00c00eb90 (diff)
add a cpio implementation to tools directory
cpio utility is a mess in point of portability. For example NetBSD cpio implementation does not support userid and groupid changes for the archive. This feature is required for initramfs filesystem targets. This cpio is from the Heirloom project. Fix needed rebuild of tools, when changing targets.
Diffstat (limited to 'tools/cpio/src/oblok.h')
-rw-r--r--tools/cpio/src/oblok.h96
1 files changed, 96 insertions, 0 deletions
diff --git a/tools/cpio/src/oblok.h b/tools/cpio/src/oblok.h
new file mode 100644
index 000000000..1ee91b1c5
--- /dev/null
+++ b/tools/cpio/src/oblok.h
@@ -0,0 +1,96 @@
+/*
+ * Copyright (c) 2003 Gunnar Ritter
+ *
+ * This software is provided 'as-is', without any express or implied
+ * warranty. In no event will the authors be held liable for any damages
+ * arising from the use of this software.
+ *
+ * Permission is granted to anyone to use this software for any purpose,
+ * including commercial applications, and to alter it and redistribute
+ * it freely, subject to the following restrictions:
+ *
+ * 1. The origin of this software must not be misrepresented; you must not
+ * claim that you wrote the original software. If you use this software
+ * in a product, an acknowledgment in the product documentation would be
+ * appreciated but is not required.
+ *
+ * 2. Altered source versions must be plainly marked as such, and must not be
+ * misrepresented as being the original software.
+ *
+ * 3. This notice may not be removed or altered from any source distribution.
+ */
+/* Sccsid @(#)oblok.h 1.3 (gritter) 4/17/03 */
+
+#include <sys/types.h>
+
+#ifndef OBLOK
+enum {
+ OBLOK = 4096
+};
+#endif /* !OBLOK */
+
+enum ob_mode {
+ OB_EBF = 0, /* error or mode unset */
+ OB_NBF = 1, /* not buffered */
+ OB_LBF = 2, /* line buffered */
+ OB_FBF = 3 /* fully buffered */
+};
+
+struct oblok {
+ char ob_blk[OBLOK]; /* buffered data */
+ long long ob_wrt; /* amount of data written */
+ int ob_pos; /* position of first empty date byte */
+ int ob_fd; /* file descriptor to write to */
+ enum ob_mode ob_bf; /* buffering mode */
+};
+
+/*
+ * Allocate an output buffer with file descriptor fd and buffer mode bf.
+ * If bf is OB_EBF, the choice is made dependant upon the file type.
+ * NULL is returned if no memory is available.
+ */
+extern struct oblok *ob_alloc(int fd, enum ob_mode bf);
+
+/*
+ * Deallocate the passed output buffer, flushing all data. The file
+ * descriptor is not closed. Returns -1 if flushing fails.
+ */
+extern ssize_t ob_free(struct oblok *op);
+
+/*
+ * Write data of length sz to the passed output buffer. Returns -1 on
+ * error or the amount of data written.
+ */
+extern ssize_t ob_write(struct oblok *op, const char *data, size_t sz);
+
+/*
+ * Flush all data in the passed output buffer. Returns -1 on error or
+ * the amount of data written; 0 is success and means 'nothing to flush'.
+ * The underlying device is not flushed (i. e. no fsync() is performed).
+ */
+extern ssize_t ob_flush(struct oblok *op);
+
+/*
+ * Flush all output buffers. Called automatically using atexit(). Returns
+ * -1 on error or the number of buffers flushed; 0 is success.
+ */
+extern int ob_clear(void);
+
+/*
+ * putc() workalike.
+ */
+#define ob_put(c, op) ((op)->ob_bf != OB_FBF || (op)->ob_pos >= (OBLOK) - 1 ?\
+ ob_chr((c), (op)) : \
+ (int)((op)->ob_blk[(op)->ob_pos++] = (char)(c)))
+
+
+/*
+ * fputc() workalike.
+ */
+extern int ob_chr(int c, struct oblok *op);
+
+/*
+ * This function must be supplied by the calling code; it is called on
+ * write error.
+ */
+extern void writerr(struct oblok *op, int count, int written);