task

creates a plain-text task file in the current directory
git clone git://brookjeynes.dev/bjeynes/task.git
Log | Files | Refs | README | LICENSE

commit 04c84834303a51f1b03bef5db6017cef6eb4c006
parent a6dfcc3f59a0b19a8e4831cc64155b0ec5c373d8
Author: brookjeynes <me@brookjeynes.dev>
Date:   Wed, 10 Jun 2026 11:54:10 +0000

refactor: simplify fopen call

Diffstat:
Mmain.c | 20+++++++-------------
1 file changed, 7 insertions(+), 13 deletions(-)

diff --git a/main.c b/main.c @@ -1,7 +1,6 @@ #include <stdio.h> #include <stdlib.h> #include <string.h> -#include <sys/stat.h> #include <unistd.h> struct options { @@ -37,7 +36,8 @@ int main(int argc, char *argv[]) { } if (strlen(argv[idx + 1]) != 1) { - fprintf(stderr, "err: priority must be a single letter between [A-Z]\n"); + fprintf(stderr, + "err: priority must be a single letter between [A-Z]\n"); exit(1); } @@ -72,14 +72,14 @@ int main(int argc, char *argv[]) { if (cli_args.priority != '\0') { char *alphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"; - int is_alphanumeric = 0; + int is_uppercase_letter = 0; for (int idx = 0; idx < 26; idx++) { if (cli_args.priority == alphabet[idx]) { - is_alphanumeric = 1; + is_uppercase_letter = 1; break; } } - if (!is_alphanumeric) { + if (!is_uppercase_letter) { fprintf(stderr, "err: priority must be between [A-Z]\n"); exit(1); } @@ -96,15 +96,9 @@ int main(int argc, char *argv[]) { } strcpy(title_to_file + title_len, ".txt"); - struct stat buffer; - if (stat(title_to_file, &buffer) == 0) { - fprintf(stderr, "err: file already exists\n"); - exit(1); - }; - - FILE *f = fopen(title_to_file, "w"); + FILE *f = fopen(title_to_file, "wx"); if (f == NULL) { - fprintf(stderr, "err: failed to open file\n"); + fprintf(stderr, "err: failed to open file. the file may already exist\n"); exit(1); }