Ignore:
Timestamp:
2012-04-01T19:38:04Z (12 years ago)
Author:
Sean Bartell <wingedtachikoma@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
e4fbccd
Parents:
d9faae91
Message:

Implement the `sleep' command.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/app/bdsh/cmds/modules/sleep/sleep.c

    rd9faae91 r3d367ee2  
    2727 */
    2828
     29#include <errno.h>
    2930#include <stdio.h>
    3031#include <stdlib.h>
     32#include <unistd.h>
    3133#include "config.h"
    3234#include "util.h"
     
    4143void help_cmd_sleep(unsigned int level)
    4244{
    43         printf("This is the %s help for '%s'.\n",
    44                 level ? EXT_HELP : SHORT_HELP, cmdname);
     45        if (level == HELP_SHORT) {
     46                printf("`%s' pauses for a given time interval\n", cmdname);
     47        } else {
     48                help_cmd_sleep(HELP_SHORT);
     49                printf(
     50                "Usage:  %s <duration>\n"
     51                "The duration is an integer number of seconds.\n",
     52                cmdname);
     53        }
     54
    4555        return;
    4656}
     
    4959int cmd_sleep(char **argv)
    5060{
     61        int ret;
    5162        unsigned int argc;
    52         unsigned int i;
     63        uint32_t duration;
    5364
    5465        /* Count the arguments */
    55         for (argc = 0; argv[argc] != NULL; argc ++);
     66        argc = cli_count_args(argv);
    5667
    57         printf("%s %s\n", TEST_ANNOUNCE, cmdname);
    58         printf("%d arguments passed to %s", argc - 1, cmdname);
    59 
    60         if (argc < 2) {
    61                 printf("\n");
    62                 return CMD_SUCCESS;
     68        if (argc != 2) {
     69                printf("%s - incorrect number of arguments. Try `help %s'\n",
     70                        cmdname, cmdname);
     71                return CMD_FAILURE;
    6372        }
    6473
    65         printf(":\n");
    66         for (i = 1; i < argc; i++)
    67                 printf("[%d] -> %s\n", i, argv[i]);
     74        ret = str_uint32_t(argv[1], NULL, 10, true, &duration);
     75        if (ret != EOK) {
     76                printf("%s - invalid duration.\n", cmdname);
     77                return CMD_FAILURE;
     78        }
     79
     80        (void) usleep((useconds_t)duration * 1000000);
    6881
    6982        return CMD_SUCCESS;
Note: See TracChangeset for help on using the changeset viewer.