summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/b_sqb.c2
-rw-r--r--src/b_sqb_file.c62
-rw-r--r--src/b_sqb_file.h1
3 files changed, 49 insertions, 16 deletions
diff --git a/src/b_sqb.c b/src/b_sqb.c
index 226d09f..adfad0f 100644
--- a/src/b_sqb.c
+++ b/src/b_sqb.c
@@ -66,6 +66,8 @@ static uint8_t
ret = 0;
if (id < FT_ID_SQB_NT && id != FT_ID_SQB_Z && id != FT_ID_SQB_N)
ret = b_sqb_file_tests(id, argv);
+ else if (id == FT_ID_SQB_NT || id == FT_ID_SQB_OT)
+ ret = b_sqb_double_file_tests(id, argv);
return (ret);
}
diff --git a/src/b_sqb_file.c b/src/b_sqb_file.c
index d876516..f0cd374 100644
--- a/src/b_sqb_file.c
+++ b/src/b_sqb_file.c
@@ -19,32 +19,32 @@
#include "d_define.h"
static t_bool
- b_file_tests_one(uint8_t id,
- const char path[],
- struct stat *st)
+ b_file_tests(uint8_t id,
+ const char path[],
+ struct stat sb)
{
- if (id == FT_ID_SQB_B && S_ISBLK(st->st_mode) == 1)
+ if (id == FT_ID_SQB_B && S_ISBLK(sb.st_mode) == 1)
return (TRUE);
- else if (id == FT_ID_SQB_C && S_ISCHR(st->st_mode) == 1)
+ else if (id == FT_ID_SQB_C && S_ISCHR(sb.st_mode) == 1)
return (TRUE);
- else if (id == FT_ID_SQB_D && S_ISDIR(st->st_mode) == 1)
+ else if (id == FT_ID_SQB_D && S_ISDIR(sb.st_mode) == 1)
return (TRUE);
- else if (id == FT_ID_SQB_F && S_ISREG(st->st_mode) == 1)
+ else if (id == FT_ID_SQB_F && S_ISREG(sb.st_mode) == 1)
return (TRUE);
else if ((id == FT_ID_SQB_H || id == FT_ID_SQB_L_MAJ)
- && S_ISLNK(st->st_mode) == 1)
+ && S_ISLNK(sb.st_mode) == 1)
return (TRUE);
- else if (id == FT_ID_SQB_P && S_ISFIFO(st->st_mode) == 1)
+ else if (id == FT_ID_SQB_P && S_ISFIFO(sb.st_mode) == 1)
return (TRUE);
else if (id == FT_ID_SQB_R && access(path, R_OK) == 0)
return (TRUE);
- else if (id == FT_ID_SQB_S && st->st_size > 0)
+ else if (id == FT_ID_SQB_S && sb.st_size > 0)
return (TRUE);
else if (id == FT_ID_SQB_W && access(path, W_OK) == 0)
return (TRUE);
else if (id == FT_ID_SQB_X && access(path, X_OK) == 0)
return (TRUE);
- else if (id == FT_ID_SQB_S_MAJ && S_ISSOCK(st->st_mode) == 0)
+ else if (id == FT_ID_SQB_S_MAJ && S_ISSOCK(sb.st_mode) == 0)
return (TRUE);
return (FALSE);
}
@@ -53,18 +53,48 @@ uint8_t
b_sqb_file_tests(uint8_t id,
char *argv[])
{
- struct stat st;
- int32_t fd;
+ struct stat sb;
if (access(argv[1], 0) == -1)
return (1);
if (id == FT_ID_SQB_E)
return (0);
if (id == FT_ID_SQB_H || id == FT_ID_SQB_L_MAJ)
- lstat(argv[1], &st);
+ lstat(argv[1], &sb);
else
- stat(argv[1], &st);
- if (b_file_tests_one(id, argv[1], &st) == TRUE)
+ stat(argv[1], &sb);
+ if (b_file_tests(id, argv[1], sb) == TRUE)
+ return (0);
+ return (1);
+}
+
+static t_bool
+ b_sqb_file_comp_tests(uint8_t id,
+ struct stat sb_one,
+ struct stat sb_two)
+{
+ if (id == FT_ID_SQB_NT &&
+ sb_one.st_mtim.tv_sec > sb_two.st_mtim.tv_sec)
+ return (TRUE);
+ else if (id == FT_ID_SQB_OT &&
+ sb_one.st_mtim.tv_sec < sb_two.st_mtim.tv_sec)
+ return (TRUE);
+ return (FALSE);
+}
+
+uint8_t
+ b_sqb_double_file_tests(uint8_t id,
+ char *argv[])
+{
+ struct stat sb[2];
+
+ if (access(argv[0], 0) == -1)
+ return (1);
+ if (access(argv[2], 0) == -1)
+ return (1);
+ stat(argv[0], &sb[0]);
+ stat(argv[2], &sb[1]);
+ if (b_sqb_file_comp_tests(id, sb[0], sb[1]) == TRUE)
return (0);
return (1);
}
diff --git a/src/b_sqb_file.h b/src/b_sqb_file.h
index 0fb7e88..4d9b410 100644
--- a/src/b_sqb_file.h
+++ b/src/b_sqb_file.h
@@ -16,5 +16,6 @@
#include <stdint.h>
uint8_t b_sqb_file_tests(uint8_t id, char *argv[]);
+uint8_t b_sqb_double_file_tests(uint8_t id, char *argv[]);
#endif