5 kx /*
5 kx * usleep
5 kx *
5 kx * Written by Donald Barnes <djb@redhat.com> for Red Hat, Inc.
5 kx *
5 kx * Copyright (c) 1997-2003 Red Hat, Inc. All rights reserved.
5 kx *
5 kx * This software may be freely redistributed under the terms of the GNU
5 kx * public license.
5 kx *
5 kx * You should have received a copy of the GNU General Public License
5 kx * along with this program; if not, write to the Free Software
5 kx * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
5 kx *
5 kx */
5 kx
5 kx
5 kx #include <unistd.h>
5 kx #include <stdlib.h>
5 kx #include <string.h>
5 kx #include <stdio.h>
5 kx
5 kx #include "popt.h"
5 kx
5 kx int main(int argc, char **argv) {
5 kx unsigned long count;
5 kx poptContext optCon;
5 kx int showVersion = 0;
5 kx int showOot = 0;
5 kx int rc;
5 kx char * countStr = NULL;
5 kx struct poptOption options[] = {
5 kx { "version", 'v', POPT_ARG_NONE, &showVersion, 0,
5 kx "Display the version of this program, and exit" },
5 kx { "oot", 'o', POPT_ARG_NONE, &showOot, 0,
5 kx "oot says hey!" },
5 kx POPT_AUTOHELP
5 kx { 0, 0, 0, 0, 0 }
5 kx };
5 kx
5 kx optCon = poptGetContext("usleep", argc, (const char **)argv, options,0);
5 kx /*poptReadDefaultConfig(optCon, 1);*/
5 kx poptSetOtherOptionHelp(optCon, "[microseconds]");
5 kx
5 kx if ((rc = poptGetNextOpt(optCon)) < -1) {
5 kx fprintf(stderr, "usleep: bad argument %s: %s\n",
5 kx poptBadOption(optCon, POPT_BADOPTION_NOALIAS),
5 kx poptStrerror(rc));
5 kx return 2;
5 kx }
5 kx
5 kx if (showVersion) {
5 kx printf("usleep version 1.2\n usleep --help for more info\n");
5 kx return 0;
5 kx }
5 kx
5 kx if (showOot) {
5 kx printf("oot says hey!\n");
5 kx return 0;
5 kx }
5 kx
5 kx countStr = (char *)poptGetArg(optCon);
5 kx
5 kx if (countStr == NULL) count = 1;
5 kx
5 kx else if (countStr && poptGetArg(optCon)) {
5 kx fprintf(stderr, "%s: exactly one argument (number of microseconds) "
5 kx "must be used\n", argv[0]);
5 kx return 2;
5 kx }
5 kx
5 kx else count = strtoul(countStr, NULL, 0);
5 kx
5 kx usleep(count);
5 kx return 0;
5 kx }