aboutsummaryrefslogtreecommitdiff
path: root/src/record.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/record.c')
-rw-r--r--src/record.c60
1 files changed, 60 insertions, 0 deletions
diff --git a/src/record.c b/src/record.c
new file mode 100644
index 0000000..be78978
--- /dev/null
+++ b/src/record.c
@@ -0,0 +1,60 @@
+#include "tar.h"
+
+int record_write(int fd, char *s, size_t size)
+{
+ char buf[RECORD_SIZE];
+
+ while (size > RECORD_SIZE)
+ {
+ memcpy(buf, s, RECORD_SIZE);
+ s += RECORD_SIZE;
+ size -= RECORD_SIZE;
+ if (write(fd, buf, RECORD_SIZE) == -1)
+ {
+ perror(NULL);
+ return -1;
+ }
+ }
+ bzero(buf, RECORD_SIZE);
+ memcpy(buf, s, size);
+ if (write(fd, buf, RECORD_SIZE) == -1)
+ {
+ perror(NULL);
+ return -1;
+ }
+ return (0);
+}
+
+int record_write_blank(int fd, size_t count)
+{
+ char buf[RECORD_SIZE] = {0};
+ while (count-- > 0)
+ {
+ if (write(fd, buf, RECORD_SIZE) == -1)
+ {
+ perror(NULL);
+ return -1;
+ }
+ }
+ return 0;
+}
+
+int record_read(int fd, char record[RECORD_SIZE])
+{
+ int ret = read(fd, record, RECORD_SIZE);
+ if (ret == -1)
+ {
+ perror(NULL);
+ return -1;
+ }
+ if (ret != RECORD_SIZE)
+ return -1;
+ return 0;
+}
+
+static char g_record_blank[RECORD_SIZE] = {0};
+
+bool record_is_blank(char record[RECORD_SIZE])
+{
+ return memcmp(record, g_record_blank, RECORD_SIZE) == 0;
+}