diff options
author | LAN-TW <lantw44@gmail.com> | 2013-11-13 01:21:11 +0800 |
---|---|---|
committer | LAN-TW <lantw44@gmail.com> | 2013-11-13 01:22:18 +0800 |
commit | 15d0398e07b2a2d25bd5aeae1be2fb30d9a9665b (patch) | |
tree | 36b587a3b27cfefb967229a7dee26432c2007e30 /hw2/judge.c | |
parent | 2846470b91d6f76f93e2b0e674fbd310470dec1b (diff) | |
download | sp2013-15d0398e07b2a2d25bd5aeae1be2fb30d9a9665b.tar.gz sp2013-15d0398e07b2a2d25bd5aeae1be2fb30d9a9665b.tar.zst sp2013-15d0398e07b2a2d25bd5aeae1be2fb30d9a9665b.zip |
HW2: judge 現在可以建立與刪除 FIFO 檔案了
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; +} |