diff options
Diffstat (limited to 'examples/c4touch.c')
| -rw-r--r-- | examples/c4touch.c | 61 |
1 files changed, 61 insertions, 0 deletions
diff --git a/examples/c4touch.c b/examples/c4touch.c new file mode 100644 index 0000000..5d0000d --- /dev/null +++ b/examples/c4touch.c @@ -0,0 +1,61 @@ +#include <stdlib.h> +#include <stdio.h> +#include <sys/stat.h> +#include <time.h> + +#include "cc4group.h" + +int main(int argc, char* argv[]) +{ + if(argc != 2 && argc != 3) + { + fprintf(stderr, "USAGE: %s <group> [author]\n", argv[0]); + return EXIT_FAILURE; + } + + CC4Group* group = cc4group.new(); + bool success, exists; + struct stat st; + if(stat(argv[1], &st) == 0) + { + success = cc4group.openExisting(group, argv[1]); + exists = true; + } + else + { + success = cc4group.create(group); + exists = false; + } + if(!success) + { + const char* error = cc4group.getErrorMessage(group); + if(exists) + { + fprintf(stderr, "ERROR: Can not open group file \"%s\": %s\n", argv[1], error); + } + else + { + fprintf(stderr, "ERROR: Can not initialize empty group file: %s\n", error); + } + } + + if(success) + { + cc4group.setCreation(group, time(NULL), NULL, false); + + if(argc == 3) + { + cc4group.setMaker(group, argv[2], NULL, true); + } + + success = (exists ? cc4group.saveOverwrite : cc4group.save)(group, argv[1]); + + if(!success) + { + fprintf(stderr, "ERROR: Can not save group file to \"%s\": %s\n", argv[1], cc4group.getErrorMessage(group)); + } + } + cc4group.delete(group); + + return success ? EXIT_SUCCESS : EXIT_FAILURE; +} |
