On Sun, Jan 24, 2021 at 5:09 PM Eryu Guan <guan@xxxxxxx> wrote: > > On Sat, Jan 16, 2021 at 06:56:17PM +0200, Amir Goldstein wrote: > > Reduce boilerplate code. > > define _GNU_SOURCE needed for asprintf. > > > > Signed-off-by: Amir Goldstein <amir73il@xxxxxxxxx> > > --- > > src/t_immutable.c | 221 ++++++++++++++++++++++------------------------ > > 1 file changed, 104 insertions(+), 117 deletions(-) > > > > diff --git a/src/t_immutable.c b/src/t_immutable.c > > index 86c567ed..b6a76af0 100644 > > --- a/src/t_immutable.c > > +++ b/src/t_immutable.c > > @@ -8,6 +8,9 @@ > > > > #define TEST_UTIME > > > > +#ifndef _GNU_SOURCE > > +#define _GNU_SOURCE > > +#endif > > #include <stdio.h> > > #include <stdlib.h> > > #include <string.h> > > @@ -1895,13 +1898,66 @@ static int check_test_area(const char *dir) > > return 0; > > } > > > > +static int create_dir(char **ppath, const char *fmt, const char *dir) > > +{ > > + const char *path; > > + struct stat st; > > + > > + if (asprintf(ppath, fmt, dir) == -1) { > > + return -1; > > + } > > + path = *ppath; > > + if (stat(path, &st) == 0) { > > + fprintf(stderr, "%s: Test area directory %s must not exist for test area creation.\n", > > + __progname, path); > > + return 1; > > Other places return -1 but 1 is returned here, should be -1 as well? > It is a semantically different return value. -1 are error cases, 1 means already existing, so the caller that requested to create the dir could treat this as success. I did not end up implementing the 'allow_existing' feature in this way, but I see no reason to change the return value, because future implementation could make use of this distinction. Unless you insist. Thanks, Amir.