aboutsummaryrefslogtreecommitdiff
path: root/src/utils.c
diff options
context:
space:
mode:
authorCharles <sircharlesaze@gmail.com>2020-06-22 19:48:39 +0200
committerCharles <sircharlesaze@gmail.com>2020-06-22 19:48:39 +0200
commitd99f14c2a908b9db8d24180c9681009a4d1c0207 (patch)
tree935d334b242e38f70ef1e503446a35f0b66e104c /src/utils.c
parent88ab5a5273e13066ce3f496a690f10d20a278bb4 (diff)
downloadtar-d99f14c2a908b9db8d24180c9681009a4d1c0207.tar.gz
tar-d99f14c2a908b9db8d24180c9681009a4d1c0207.tar.bz2
tar-d99f14c2a908b9db8d24180c9681009a4d1c0207.zip
Added list option and verbose mode
Diffstat (limited to 'src/utils.c')
-rw-r--r--src/utils.c35
1 files changed, 35 insertions, 0 deletions
diff --git a/src/utils.c b/src/utils.c
new file mode 100644
index 0000000..5d3608f
--- /dev/null
+++ b/src/utils.c
@@ -0,0 +1,35 @@
+#include "tar.h"
+
+void put_file_name(char *file_name)
+{
+ fputs(file_name, stderr);
+ fputc('\n', stderr);
+}
+
+void put_file_verbose(t_header *header, struct stat *statbuf)
+{
+ char *time_str;
+ char *new_line_ptr;
+
+ time_str = ctime(&statbuf->st_mtime);
+ if ((new_line_ptr = strchr(time_str, '\n')) != NULL)
+ *new_line_ptr = '\0';
+ printf(
+ "%c%c%c%c%c%c%c%c%c%c %s/%s %6lu %s %s\n",
+ header->file_type[0] == '0' ? '-' : 'd',
+ statbuf->st_mode & S_IRUSR ? 'r' : '-',
+ statbuf->st_mode & S_IWUSR ? 'w' : '-',
+ statbuf->st_mode & S_IXUSR ? 'x' : '-',
+ statbuf->st_mode & S_IRGRP ? 'r' : '-',
+ statbuf->st_mode & S_IWGRP ? 'w' : '-',
+ statbuf->st_mode & S_IXGRP ? 'x' : '-',
+ statbuf->st_mode & S_IROTH ? 'r' : '-',
+ statbuf->st_mode & S_IWOTH ? 'w' : '-',
+ statbuf->st_mode & S_IXOTH ? 'x' : '-',
+ header->user_name,
+ header->group_name,
+ statbuf->st_size,
+ time_str,
+ header->file_name
+ );
+}