diff options
author | Calvin Morrison <mutantturkey@gmail.com> | 2014-11-06 23:30:04 -0500 |
---|---|---|
committer | Calvin Morrison <mutantturkey@gmail.com> | 2014-11-06 23:30:04 -0500 |
commit | ad16970487eed1de054624c4737d8a93b9660efe (patch) | |
tree | 9f8babd3f34a5466ba0f68f0c210031d9ed23afc | |
parent | a947110d2f93894ace6dc6c008d7be8caff317c2 (diff) |
move decs to top of fn's, use -d like htop
-rw-r--r-- | fsbm.c | 15 |
1 files changed, 7 insertions, 8 deletions
@@ -33,10 +33,11 @@ void endHandler(int signum) { void print_bps(double bytesPerSecond) { const char* prefixes[] = { "", "k", "M", "G", "T", "P", "E", "Z", "Y" }; - - // Calculate the value double value; const char* unit; + unsigned prefix = 0; + + // Calculate the value if(use_bits) { value = bytesPerSecond * 8; unit = "b/s"; @@ -47,7 +48,6 @@ void print_bps(double bytesPerSecond) { } // Choose the prefix - unsigned prefix = 0; while (prefix < (sizeof(prefixes) / sizeof(const char*)) && value > 1000.) { value /= 1000.; ++prefix; @@ -73,6 +73,7 @@ void print_stats() { long long unsigned rx_bytes, tx_bytes; struct timezone unused_timezone; struct timeval timestamp; + ptrdiff_t len = 0; // Read a line fgets(buf, sizeof(buf), dev); @@ -90,7 +91,6 @@ void print_stats() { // Remove leading whitespace from the name name = buf; - ptrdiff_t len = 0; while (*name == ' ' || *name == '\t') { ++name; } @@ -159,21 +159,20 @@ int main(int argc, char **argv) { // parse the command line int c; - int interval = 10 * 100000; - while ((c = getopt (argc, argv, "bi:hv")) != -1) + while ((c = getopt (argc, argv, "brd:hv")) != -1) switch (c) { case 'b': use_bits = true; break; - case 'i': + case 'd': // Magic numbers? fuck it that's not a magic number, that's a 'real' number. interval = atoi(optarg) * 100000; break; case 'h': - printf("USAGE: fsbm, -b specifies bits, -i sets interval in 10ths of seconds, 1 sec default\n"); + printf("USAGE: fsbm, -b specifies bits, -d sets interval in 10ths of seconds, 1 sec default\n"); exit(EXIT_SUCCESS); break; case 'v': |