[tcp] Enable AF_INET6 transport for tcp connections
[gpxe.git] / src / hci / commands / time_cmd.c
blob947410ec76e0288f8815f971a055e2bfbe0f02f2
1 /*
2 * Copyright (C) 2009 Daniel Verkamp <daniel@drv.nu>.
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License as
6 * published by the Free Software Foundation; either version 2 of the
7 * License, or any later version.
9 * This program is distributed in the hope that it will be useful, but
10 * WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18 * March-19-2009 @ 02:44: Added sleep command.
19 * Shao Miller <shao.miller@yrdsb.edu.on.ca>.
22 #include <stdio.h>
23 #include <stdlib.h>
24 #include <string.h>
25 #include <unistd.h>
26 #include <gpxe/command.h>
27 #include <gpxe/nap.h>
28 #include <gpxe/timer.h>
30 static int time_exec ( int argc, char **argv ) {
31 unsigned long start;
32 int rc, secs;
34 if ( argc == 1 ||
35 !strcmp ( argv[1], "--help" ) ||
36 !strcmp ( argv[1], "-h" ) )
38 printf ( "Usage:\n"
39 " %s <command>\n"
40 "\n"
41 "Time a command\n",
42 argv[0] );
43 return 1;
46 start = currticks();
47 rc = execv ( argv[1], argv + 1 );
48 secs = (currticks() - start) / ticks_per_sec();
50 printf ( "%s: %ds\n", argv[0], secs );
52 return rc;
55 struct command time_command __command = {
56 .name = "time",
57 .exec = time_exec,
60 static int sleep_exec ( int argc, char **argv ) {
61 unsigned long start, delay;
63 if ( argc == 1 ||
64 !strcmp ( argv[1], "--help" ) ||
65 !strcmp ( argv[1], "-h" ))
67 printf ( "Usage:\n"
68 " %s <seconds>\n"
69 "\n"
70 "Sleep for <seconds> seconds\n",
71 argv[0] );
72 return 1;
74 start = currticks();
75 delay = strtoul ( argv[1], NULL, 0 ) * ticks_per_sec();
76 while ( ( currticks() - start ) <= delay )
77 cpu_nap();
78 return 0;
81 struct command sleep_command __command = {
82 .name = "sleep",
83 .exec = sleep_exec,