diff options
Diffstat (limited to 'hw2/judge.c')
-rw-r--r-- | hw2/judge.c | 53 |
1 files changed, 53 insertions, 0 deletions
diff --git a/hw2/judge.c b/hw2/judge.c new file mode 100644 index 0000000..141f359 --- /dev/null +++ b/hw2/judge.c @@ -0,0 +1,53 @@ +/* b01902062 èĉşç */ +#ifdef HAVE_CONFIG_H +# include "config.h" +#endif + +#include "logger.h" +#include "xwrap.h" + +#include <errno.h> +#include <stdio.h> +#include <string.h> +#include <sys/stat.h> +#include <sys/types.h> +#include <unistd.h> + +int main (int argc, char* argv[]) { + if (argc < 2) { + fprintf (stderr, "Usage: %s judge_id\n", argv[0]); + return 1; + } + + const char* judgename = argv[1]; + char* fifoname[5] = { + xstrcat ("judge", judgename, ".FIFO", NULL), + xstrcat ("judge", judgename, "_A.FIFO", NULL), + xstrcat ("judge", judgename, "_B.FIFO", NULL), + xstrcat ("judge", judgename, "_C.FIFO", NULL), + xstrcat ("judge", judgename, "_D.FIFO", NULL) + }; + + for (int i = 0; i < ARRAY_LEN (fifoname, char*); i++) { + if (mkfifo (fifoname[i], S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP) < 0) { + fprintf (stderr, "%s: cannot create FIFO `%s\': %s", + argv[0], fifoname[i], strerror (errno)); + return 2; + } + } + + Comp135 comp_struct, *comp; + comp = &comp_struct; + + comp135_init (comp, argv[0], false); + + + comp135_destroy (comp); + + for (int i = 0; i < ARRAY_LEN (fifoname, char*); i++) { + unlink (fifoname[i]); + free (fifoname[i]); + } + + return 0; +} |