11 usage (char *argv0, int help)
13 char *progname = strrchr(argv0, '/');
18 fprintf (help ? stdout : stderr,
19 "Usage: %s [-e] file\n", progname);
23 fprintf (stderr, " or try '-h' for help\n");
27 printf ("Create the given file with O_EXCL...\n");
28 printf (" -e expect EEXIST\n");
29 printf (" -h print help");
30 printf (" Exit status is 0 on success, 1 on failure\n");
33 int main(int argc, char **argv)
38 while ((rc = getopt (argc, argv, "eh")) != -1)
51 if (optind != argc - 1) {
56 rc = open(argv[optind], O_CREAT|O_EXCL, 0644);
59 if (want_eexist && errno == EEXIST)
61 printf("open failed: %s (expected)\n", strerror(errno));
64 printf("open failed: %s\n", strerror(errno));
69 printf("open success (expecting EEXIST).\n");
72 printf("open success.\n");
76 return ((rc == 0) ? 0 : 1);