aboutsummaryrefslogtreecommitdiff
path: root/src/record.c
diff options
context:
space:
mode:
authorCharles <sircharlesaze@gmail.com>2020-06-22 15:09:59 +0200
committerCharles <sircharlesaze@gmail.com>2020-06-22 15:09:59 +0200
commit86e8aeb5bb66ae5625002533b529752a7814e6c0 (patch)
treebb30c103a5059c8dda817310dc57256d5b812ede /src/record.c
parent3f37f1c9bf64866de90ec418adcfe31b634231c2 (diff)
downloadtar-86e8aeb5bb66ae5625002533b529752a7814e6c0.tar.gz
tar-86e8aeb5bb66ae5625002533b529752a7814e6c0.tar.bz2
tar-86e8aeb5bb66ae5625002533b529752a7814e6c0.zip
Added archive extracting
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;
+}