00001
00007
00008
00009 #include <kernel.h>
00010 #include <stdio.h>
00011 #include <string.h>
00012 #include <stdlib.h>
00013
00022 command xsh_sleep(ushort stdin, ushort stdout, ushort stderr,
00023 ushort nargs, char *args[])
00024 {
00025 long delay;
00026
00027
00028 if (nargs == 2 && strncmp(args[1],"--help",6) == 0)
00029 {
00030 fprintf(stdout, "Usage:sleep DELAY\n");
00031 fprintf(stdout, "Sleep for DELAY seconds.\n");
00032 fprintf(stdout, "\t--help\t display this help and exit\n");
00033 return OK;
00034 }
00035
00036
00037 if (nargs < 2)
00038 {
00039 fprintf(stderr,"sleep: missing operand\n");
00040 fprintf(stderr,"Try 'sleep --help' for more information\n");
00041 return SYSERR;
00042 }
00043 if (nargs > 2)
00044 {
00045 fprintf(stderr,"sleep: too many arguments\n");
00046 fprintf(stderr,"Try 'sleep --help' for more information\n");
00047 return SYSERR;
00048 }
00049
00050
00051 delay = atol(args[1]);
00052 if (delay < 0)
00053 {
00054 fprintf(stderr,"sleep: invalid delay of %d seconds\n");
00055 }
00056 return sleep(delay * 1000);
00057 }