1 /*
2  * usleep
3  *
4  * Written by Donald Barnes <djb@redhat.com> for Red Hat, Inc.
5  *
6  * Copyright (c) 1997-2003 Red Hat, Inc. All rights reserved.
7  *
8  * This program is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License, version 2,
10  * as published by the Free Software Foundation.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program; if not, write to the Free Software Foundation,
19  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
20  *
21  */
22 
23 
24 #include <unistd.h>
25 #include <stdlib.h>
26 #include <string.h>
27 #include <stdio.h>
28 
29 #include "popt.h"
30 
main(int argc,char ** argv)31 int main(int argc, char **argv) {
32   unsigned long count;
33   poptContext optCon;
34   int showVersion = 0;
35   int showOot = 0;
36   int rc;
37   char * countStr = NULL;
38   struct poptOption options[] = {
39             { "version", 'v', POPT_ARG_NONE, &showVersion, 0,
40 			"Display the version of this program, and exit" },
41             { "oot", 'o', POPT_ARG_NONE, &showOot, 0,
42 			"oot says hey!" },
43 	    POPT_AUTOHELP
44             { 0, 0, 0, 0, 0 }
45         };
46 
47   optCon = poptGetContext("usleep", argc, argv, options,0);
48   /*poptReadDefaultConfig(optCon, 1);*/
49   poptSetOtherOptionHelp(optCon, "[microseconds]");
50 
51   if ((rc = poptGetNextOpt(optCon)) < -1) {
52 	fprintf(stderr, "usleep: bad argument %s: %s\n",
53 		poptBadOption(optCon, POPT_BADOPTION_NOALIAS),
54 		poptStrerror(rc));
55 	return 2;
56   }
57 
58   if (showVersion) {
59       printf("usleep version 1.2\n	usleep --help for more info\n");
60       return 0;
61   }
62 
63   if (showOot) {
64       printf("oot says hey!\n");
65       return 0;
66   }
67 
68   countStr = poptGetArg(optCon);
69 
70   if (countStr == NULL) count = 1;
71 
72   else if (countStr && poptGetArg(optCon)) {
73       fprintf(stderr, "%s: exactly one argument (number of microseconds) "
74       		"must be used\n", argv[0]);
75       return 2;
76   }
77 
78   else count = strtoul(countStr, NULL, 0);
79 
80   usleep(count);
81   return 0;
82 }
83