From a7d5c8c41464ff8e6cf4f9a3e3a1e8086339d038 Mon Sep 17 00:00:00 2001 From: Oskar Date: Mon, 24 Jun 2024 18:01:11 +0200 Subject: first commit --- .gitignore | 3 ++ LICENSE | 21 ++++++++++++ Makefile | 22 ++++++++++++ README | 1 + TODO | 0 test/Makefile | 0 trashsys.c | 107 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 7 files changed, 154 insertions(+) create mode 100644 .gitignore create mode 100644 LICENSE create mode 100644 Makefile create mode 100644 README create mode 100644 TODO create mode 100644 test/Makefile create mode 100644 trashsys.c diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..e551279 --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ +trashsys.txt +tsr +tsr-TESTING diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..f66c023 --- /dev/null +++ b/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2024 734j + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. \ No newline at end of file diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..91fdebd --- /dev/null +++ b/Makefile @@ -0,0 +1,22 @@ +CC=gcc +CFLAGS_TESTBIN=-O3 -Wfatal-errors -Wall -Werror -Wextra -g -fsanitize=address -Wpedantic -std=gnu99 +CFLAGS=-O3 -flto -march=native -DNDEBUG -fomit-frame-pointer -s -static -std=gnu99 +TARGET=tsr +TESTTARGET=tsr-TESTING +INSTALL_DIRECTORY=/usr/local/bin +MAKEFLAGS += +SRCS=trashsys.c + +all: release +clean: + rm -f $(TARGET) + rm -f test/$(TESTTARGET) + +tests: + $(CC) $(CFLAGS_TESTBIN) $(SRCS) -o test/$(TESTTARGET) + +install: + cp $(TARGET) $(INSTALL_DIRECTORY) + +release: + $(CC) $(CFLAGS) $(SRCS) -o $(TARGET) diff --git a/README b/README new file mode 100644 index 0000000..4e0750d --- /dev/null +++ b/README @@ -0,0 +1 @@ +Simple trashing system \ No newline at end of file diff --git a/TODO b/TODO new file mode 100644 index 0000000..e69de29 diff --git a/test/Makefile b/test/Makefile new file mode 100644 index 0000000..e69de29 diff --git a/trashsys.c b/trashsys.c new file mode 100644 index 0000000..7b6da79 --- /dev/null +++ b/trashsys.c @@ -0,0 +1,107 @@ +#include +#include +#include +#include +#include +#include + +#define USAGE "to be decided" + +struct trashsys_log_info { + uint64_t ts_log_id; + char ts_log_filename[255]; + size_t ts_log_filesize; + time_t ts_log_trashtime; + char ts_log_originalpath[4096]; + bool ts_log_tmp; +}; + +int main (int argc, char *argv[]) { + + if (argc == 1) { + fprintf(stderr, "%s: please specify a filename\n%s\n", argv[0], USAGE); + return EXIT_FAILURE; + } + + bool y_used = false; + bool n_used = false; + bool v_used = false; + bool f_used = false; + bool a_used = false; + bool t_used = false; + bool l_used = false; + bool L_used = false; + bool c_used = false; + bool C_used = false; + bool R_used = false; + + int opt; + int returnval; + char *optarg_copy = NULL; // We will copy optarg to this + while ((opt = getopt(argc, argv, "ynvfatlLcCR:")) != -1) { + switch (opt) { + case 'y': + + y_used = true; + + break; + case 'n': + + n_used = true; + + break; + case 'v': + + v_used = true; + + break; + case 'f': + + f_used = true; + + break; + case 'a': + + a_used = true; + + break; + case 't': + + t_used = true; + + break; + case 'l': + + l_used = true; + + break; + case 'L': + + L_used = true; + + break; + case 'c': + + c_used = true; + + break; + case 'C': + + C_used = true; + + break; + case 'R': + + R_used = true; + + break; + } + } + + + if (n_used == true && y_used == true) { // If both YES and NO are used print usage and exit + fprintf(stderr, "%s", USAGE); + return EXIT_FAILURE; + } + return 0; +} -- cgit v1.2.3