From 08fcf513ccf9178caae6a5ca7570501a01150bd5 Mon Sep 17 00:00:00 2001 From: tTh Date: Sun, 10 Nov 2024 13:55:25 +0100 Subject: [PATCH] checking export directory, first try --- Fonderie/Makefile | 7 ++++-- Fonderie/t.c | 41 +++++++++++++++++++++++++++++++++- Fonderie/utilfuncs.c | 52 ++++++++++++++++++++++++++++++++++++++++++++ Fonderie/utilfuncs.h | 11 ++++++++++ 4 files changed, 108 insertions(+), 3 deletions(-) create mode 100644 Fonderie/utilfuncs.c create mode 100644 Fonderie/utilfuncs.h diff --git a/Fonderie/Makefile b/Fonderie/Makefile index 43e909f7..8be2419f 100644 --- a/Fonderie/Makefile +++ b/Fonderie/Makefile @@ -7,12 +7,12 @@ COPT = -g -fpic -no-pie -Wall -DDEBUG_LEVEL=0 -Werror=parentheses LIBS = ../libfloatimg.a -ltiff -lpnglite -lm -lz -lcfitsio OBJS = fifo.o sfx.o crapulator.o glitches.o metriques.o \ - filterstack.o single.o + filterstack.o single.o utilfuncs.o DEPS = ../floatimg.h \ ../libfloatimg.a \ fifo.h crapulator.h metriques.h glitches.h sfx.h \ - filterstack.h crapdef.h crapstr.h single.h + filterstack.h crapdef.h crapstr.h single.h utilfuncs.h all: fonderie interpolator singlepass t @@ -71,4 +71,7 @@ metriques.o: metriques.c metriques.h Makefile glitches.o: glitches.c glitches.h Makefile gcc ${COPT} -c $< +utilfuncs.o: utilfuncs.c utilfuncs.h Makefile + gcc ${COPT} -c $< + # --------------------------------------------------------- diff --git a/Fonderie/t.c b/Fonderie/t.c index b845adb5..61f98f9c 100644 --- a/Fonderie/t.c +++ b/Fonderie/t.c @@ -16,6 +16,8 @@ #include "crapulator.h" #include "single.h" +#include "utilfuncs.h" + /* ----------------------------------------------------------- */ int verbosity; @@ -28,6 +30,30 @@ int verbosity; #define STK 6 +/* ----------------------------------------------------------- */ +/* new Sat Nov 9 22:17:46 UTC 2024 */ +int essai_test_export_dir(char *footxt) +{ +int foo; + +#if DEBUG_LEVEL +fprintf(stderr, ">>> %s ( '%s' )\n", __func__, footxt); +#endif + +foo = check_if_export_dir_is_valid("/tmp/quux", 0); +fprintf(stderr, " got %d\n\n", foo); + +foo = check_if_export_dir_is_valid("/home", 0); +fprintf(stderr, " got %d\n\n", foo); + +foo = check_if_export_dir_is_valid("./", 0); +fprintf(stderr, " got %d\n\n", foo); + +foo = check_if_export_dir_is_valid("Makefile", 0); +fprintf(stderr, " got %d\n\n", foo); + +return -1; +} /* ----------------------------------------------------------- */ int essai_filterstack(char *fIname, char *fOname) @@ -36,6 +62,11 @@ int foo; FloatImg image; double debut, fin; +#if DEBUG_LEVEL +fprintf(stderr, ">>> %s ( '%s' '%s' )\n", __func__, fIname, fOname); +#endif + + // filterstack_list(STK, __func__); foo = fimg_create_from_dump(fIname, &image); @@ -218,15 +249,23 @@ while ((opt = getopt(argc, argv, "hF:g:i:Lo:O:svx")) != -1) { } #if DEBUG_LEVEL -fprintf(stderr, "%s : argc = %d, optind = %d\n", argv[0], argc, optind); +fprintf(stderr, ">>> %s : argc=%d, optind=%d\n", argv[0], argc, optind); #endif +foo = essai_test_export_dir("bla bla"); +if (foo) { + fprintf(stderr, "err %d in essai_test_export_dir\n", foo); + exit(1); + } +exit(0); + foo = parse_filter_chain(STK, filterchain); if (foo) { fprintf(stderr, "err %d in parse_filter_chain\n", foo); exit(1); } + if (do_xper) { experiment(infile); return 0; diff --git a/Fonderie/utilfuncs.c b/Fonderie/utilfuncs.c new file mode 100644 index 00000000..2521f96d --- /dev/null +++ b/Fonderie/utilfuncs.c @@ -0,0 +1,52 @@ +/* + * utilfuncs.c + * + * new Sat Nov 9 22:15:15 UTC 2024 + */ + +#include +#include +#include +#include + +#include "utilfuncs.h" + +extern int verbosity; + +/* -------------------------------------------------------------- */ +int check_if_export_dir_is_valid(char *path, int action) +{ +int foo; +struct stat statbuf; + +#if DEBUG_LEVEL +fprintf(stderr, ">>> %s ( '%s', %d )\n", __func__, path, action); +#endif + +foo = stat(path, &statbuf); +if (foo) { + if (verbosity) perror(path); + return 0; + } + +#if DEBUG_LEVEL +fprintf(stderr, " mode 0x%x\n", statbuf.st_mode); +#endif +if ((statbuf.st_mode & S_IFMT) != S_IFDIR) { + if (verbosity) fprintf(stderr, "%s: Not a directory\n", path); + return 0; + } + +/* OK, c'est un repertoire, mais peut-on écrire dedans ? */ +foo = access(path, W_OK); +#if DEBUG_LEVEL +fprintf(stderr, " access '%s' = %d\n", path, foo); +#endif +if (0 != foo) { + return 0; + } + +return 1; /* export dir is OK */ +} +/* -------------------------------------------------------------- */ + diff --git a/Fonderie/utilfuncs.h b/Fonderie/utilfuncs.h new file mode 100644 index 00000000..93ef97c1 --- /dev/null +++ b/Fonderie/utilfuncs.h @@ -0,0 +1,11 @@ +/* + * utilfuncs.c + * + * new Sat Nov 9 22:15:49 UTC 2024 + */ + +/* -------------------------------------------------------------- */ + +int check_if_export_dir_is_valid(char *path, int action); + +/* -------------------------------------------------------------- */