aboutsummaryrefslogtreecommitdiff
path: root/pass.c
diff options
context:
space:
mode:
authorsinanmohd <sinan@sinanmohd.com>2023-12-30 16:24:19 +0530
committersinanmohd <sinan@sinanmohd.com>2023-12-30 16:25:43 +0530
commita042114987129a32c7d7d3243a46e0dfd00b13b2 (patch)
tree8c92c4eb22627a4036e123db5f4f2c944a68bffa /pass.c
parentdc1f4733c0c21c897dbcc430787d33dc0e6c6af3 (diff)
pass.c/cat: print newline if output is a terminal
Diffstat (limited to 'pass.c')
-rw-r--r--pass.c10
1 files changed, 8 insertions, 2 deletions
diff --git a/pass.c b/pass.c
index e68a262..b66e2ac 100644
--- a/pass.c
+++ b/pass.c
@@ -1,4 +1,5 @@
#include <stdio.h>
+#include <unistd.h>
#include <string.h>
#include <stdlib.h>
#include <errno.h>
@@ -36,10 +37,15 @@ int cat(const char *path)
const char *s = NULL;
s = pass_cat(path);
- if (s)
+ if (!s)
+ return -1;
+
+ if(isatty(STDOUT_FILENO))
+ puts(s);
+ else
fputs(s, stdout);
- return (s == NULL);
+ return 0;
}
int add(const char *path)