From 15d0398e07b2a2d25bd5aeae1be2fb30d9a9665b Mon Sep 17 00:00:00 2001 From: LAN-TW Date: Wed, 13 Nov 2013 01:21:11 +0800 Subject: HW2: judge 現在可以建立與刪除 FIFO 檔案了 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- hw2/judge.c | 53 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) create mode 100644 hw2/judge.c (limited to 'hw2/judge.c') 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 +#include +#include +#include +#include +#include + +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; +} -- cgit