]> git.pld-linux.org Git - projects/rc-scripts.git/blame - src/usleep.c
- give user ability to disable linux multipath drivers and daemons
[projects/rc-scripts.git] / src / usleep.c
CommitLineData
e7243979
ER
1/*
2 * usleep.c Sleep for the specified number of microseconds
52471a31 3 *
e7243979 4 * Usage: usleep [ microseconds ]
52471a31 5 *
e7243979
ER
6 * Copyright 2001 Werner Fink, 2001 SuSE GmbH Nuernberg, Germany.
7 * Copyright 2005 Werner Fink, 2005 SUSE LINUX Products GmbH, Germany.
458f14b7 8 *
e7243979
ER
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
13 *
14 * Author: Werner Fink <werner@suse.de>
7742e157
AF
15 */
16
e7243979
ER
17#ifndef __USE_STRING_INLINES
18# define __USE_STRING_INLINES
19#endif
20#ifdef __NO_STRING_INLINES
21# undef __NO_STRING_INLINES
22#endif
23#include <libgen.h>
7742e157
AF
24#include <string.h>
25#include <stdio.h>
e7243979
ER
26#include <stdlib.h>
27#include <unistd.h>
28#ifdef _POSIX_PRIORITY_SCHEDULING
29# include <sched.h>
30#endif
31#define USAGE "Usage:\t%s [ microseconds ]\n", we_are
7742e157 32
e7243979
ER
33static char *we_are;
34int main(int argc, char **argv)
35{
36 unsigned long int usec = 1;
7742e157 37
e7243979
ER
38 if (argc > 2)
39 goto err;
458f14b7 40
e7243979
ER
41 if (argc > 1) {
42 char *endptr;
43 usec = strtoul(argv[1], &endptr, 10);
44 if (*endptr != '\0')
45 goto err;
46 }
458f14b7 47
e7243979
ER
48 if (usec)
49 usleep(usec);
50#ifdef _POSIX_PRIORITY_SCHEDULING
51 else
52 (void)sched_yield();
53#endif
54 _exit(0);
458f14b7 55
e7243979
ER
56 /* Do this at the end for speed */
57err:
58 we_are = basename(argv[0]);
59 fprintf(stderr, USAGE);
458f14b7 60
e7243979
ER
61 if (argc > 1 && *(argv[1]) == '-') {
62 argv[1]++;
63 if (!strcmp(argv[1], "-help") || *(argv[1]) == 'h' || *(argv[1]) == '?') {
64 fprintf(stderr, "Sleep for the specified number of microseconds.\n\n");
65 fprintf(stderr, "Help options:\n");
66 fprintf(stderr, " -h, -?, --help display this help and exit.\n");
67 exit (0);
68 }
69 }
70 exit (1);
71}
This page took 0.074653 seconds and 4 git commands to generate.