[hackers] [sbase] Adding tar. || David Galos

From: <git_AT_suckless.org>
Date: Thu, 18 Jul 2013 17:15:22 +0200

commit 2c75eb98d9b4623f787a3c9bc97c6f29a0f4d59c
Author: David Galos <galosd83_AT_students.rowan.edu>
Date: Thu Jul 18 11:15:35 2013 -0400

    Adding tar.

diff --git a/Makefile b/Makefile
index 909f1ce..2bb244d 100644
--- a/Makefile
+++ b/Makefile
_AT_@ -69,6 +69,7 @@ SRC = \
         sponge.c \
         sync.c \
         tail.c \
+ tar.c \
         tee.c \
         test.c \
         touch.c \
diff --git a/tar.1 b/tar.1
new file mode 100644
index 0000000..0f257b2
--- /dev/null
+++ b/tar.1
_AT_@ -0,0 +1,62 @@
+.TH TAR 1 sbase\-VERSION
+.SH NAME
+tar \- create, list or extract a tape archive
+.SH SYNOPSIS
+.B tar
+.RB [ \-f
+.IR tarfile]
+.RB [ \-C
+.IR dir ]
+.RB [ - ] x | t
+
+.B tar
+.RB [ \-f
+.IR tarfile]
+.RB [ \-C
+.IR dir ]
+.RB [ - ] c
+.I dir
+
+.B tar
+.RB [ \-C
+.IR dir ]
+.B cf
+.I tarfile
+.I dir
+
+.B tar
+.RB [ \-C
+.IR dir ]
+.B x|tf
+.I tarfile
+
+.SH DESCRIPTION
+.B tar
+is the standard file archiver. Generally the archives
+created with it are further compressed.
+.SH OPTIONS
+.TP
+.B x
+extract tarball from stdin
+.TP
+.B t
+list all files in tarball from stdin
+.TP
+.BI c\ path
+creates tarball from
+.I path
+and prints it to stdout
+.TP
+.BI f\ tarfile
+Make
+.I tarfile
+be the archive, rather than stdin or stdout.
+.TP
+.BI C\ dir
+Change dierctory to
+.I dir
+before beginning.
+.SH SEE ALSO
+.IR ar (1)
+.IR gzip (1)
+.IR bzip2 (1)
diff --git a/tar.c b/tar.c
new file mode 100644
index 0000000..855b413
--- /dev/null
+++ b/tar.c
_AT_@ -0,0 +1,298 @@
+/* See LICENSE file for copyright and license details. */
+#include <stdlib.h>
+#include <unistd.h>
+#include <stdio.h>
+#include <string.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <limits.h>
+#include <ftw.h>
+#include <grp.h>
+#include <pwd.h>
+#include "util.h"
+
+typedef struct Header Header;
+struct Header {
+ char name[100];
+ char mode[8];
+ char uid[8];
+ char gid[8];
+ char size[12];
+ char mtime[12];
+ char chksum[8];
+ char type;
+ char link[100];
+ char magic[6];
+ char version[2];
+ char uname[32];
+ char gname[32];
+ char major[8];
+ char minor[8];
+};
+
+enum {
+ Blksiz = 512
+};
+
+enum Type {
+ REG = '0', HARDLINK = '1', SYMLINK = '2', CHARDEV = '3',
+ BLOCKDEV = '4', DIRECTORY = '5', FIFO = '6'
+};
+
+static void putoctal(char *, unsigned, int);
+static int strlcpy(char *, const char *, int n);
+static int archive(const char *, const struct stat *, int);
+static int unarchive(char *, int, char[Blksiz]);
+static int print(char *, int , char[Blksiz]);
+static void c(char *);
+static void xt(int (*)(char*, int, char[Blksiz]));
+
+static FILE *tarfile;
+
+static void
+usage(void)
+{
+ eprintf("usage: tar [-f tarfile] [-C dir] [-]x|t
"
+ " tar [-f tarfile] [-C dir] [-]c dir
"
+ " tar [-C dir] cf tarfile dir
"
+ " tar [-C dir] x|tf tarfile
");
+}
+
+int
+main(int argc, char *argv[])
+{
+ char *file, *dir, *ap;
+ char mode = '
Received on Thu Jul 18 2013 - 17:15:22 CEST

This archive was generated by hypermail 2.3.0 : Thu Jul 18 2013 - 17:24:15 CEST