Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2162)

Unified Diff: bootstat.c

Issue 6870023: Add "bootstat --output-dir" option. Base URL: ssh://gitrw.chromium.org:9222/bootstat.git@master
Patch Set: Get bootstat.c to where it actually compiles. Created 9 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « bootstat.h ('k') | bootstat_log.c » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: bootstat.c
diff --git a/bootstat.c b/bootstat.c
index 573f9efe7880bb50bdfd6023022391f6890c3dc8..e13e0df3d3b061979f78da1f6b3c340bd4c7fd0b 100644
--- a/bootstat.c
+++ b/bootstat.c
@@ -1,4 +1,4 @@
-// Copyright (c) 2010 The Chromium OS Authors. All rights reserved.
+// Copyright (c) 2011 The Chromium OS Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
@@ -6,26 +6,56 @@
// 'bootstat' facility. The command provides a command line wrapper
// around the key functionality declared in "bootstat.h"
+#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
+#include <getopt.h>
#include <libgen.h>
#include "bootstat.h"
-static void usage(char* cmd)
+static void usage(const char* cmd)
{
- fprintf(stderr, "usage: %s <event-name>\n", basename(strdup(cmd)));
+ fprintf(stderr,
+ "usage: %s [options] <event-name>\n"
+ "Options:\n"
+ " -o/--output-dir <directory>\n"
+ " specify alternate directory for timestamp output\n",
+ basename(strdup(cmd)));
exit(EXIT_FAILURE);
}
int main(int argc, char* argv[])
{
- if (argc != 2)
- usage(argv[0]);
-
- bootstat_log(argv[1]);
+ static const struct option command_options[] = {
+ { "o", required_argument, NULL, 'o' },
+ { "output-dir", required_argument, NULL, 'o' },
+ { 0, 0, 0, 0 }
+ };
+ char *output_dir = NULL;
+
+ for (;;) {
+ int c = getopt_long_only(argc, argv, "", command_options, NULL);
+
+ if (c == -1) {
+ break;
+ }
+
+ if (c == 'o') {
+ output_dir = optarg;
+ }
+ }
+
+ if (output_dir != NULL) {
+ if (bootstat_set_output_directory(output_dir) < 0) {
+ perror(output_dir);
+ usage(argv[0]);
+ }
+ }
+
+ bootstat_log(argv[optind]);
return EXIT_SUCCESS;
}
« no previous file with comments | « bootstat.h ('k') | bootstat_log.c » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698