2012-03-02 17:59:36 +05:30
|
|
|
/*
|
|
|
|
* uptime.c - display system uptime
|
|
|
|
* Copyright (C) 2012 Craig Small <csmall-procps@enc.com.au>
|
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
|
|
|
*/
|
|
|
|
|
2011-06-05 01:03:11 +05:30
|
|
|
#include <errno.h>
|
|
|
|
#include <getopt.h>
|
|
|
|
#include <stdlib.h>
|
2002-02-02 05:10:38 +05:30
|
|
|
#include <stdio.h>
|
2011-10-09 15:55:30 +05:30
|
|
|
|
|
|
|
#include "c.h"
|
|
|
|
#include "nls.h"
|
2002-02-02 04:17:29 +05:30
|
|
|
#include "proc/whattime.h"
|
|
|
|
#include "proc/version.h"
|
|
|
|
|
2011-10-09 15:55:30 +05:30
|
|
|
static void __attribute__ ((__noreturn__)) usage(FILE * out)
|
2011-06-05 01:03:11 +05:30
|
|
|
{
|
2011-10-09 15:55:30 +05:30
|
|
|
fputs(USAGE_HEADER, out);
|
|
|
|
fprintf(out, _(" %s [options]\n"), program_invocation_short_name);
|
|
|
|
fputs(USAGE_OPTIONS, out);
|
|
|
|
fputs(USAGE_HELP, out);
|
|
|
|
fputs(USAGE_VERSION, out);
|
|
|
|
fprintf(out, USAGE_MAN_TAIL("uptime(1)"));
|
2011-06-05 01:03:11 +05:30
|
|
|
|
|
|
|
exit(out == stderr ? EXIT_FAILURE : EXIT_SUCCESS);
|
|
|
|
}
|
|
|
|
|
|
|
|
int main(int argc, char **argv)
|
|
|
|
{
|
|
|
|
int c;
|
|
|
|
|
|
|
|
static const struct option longopts[] = {
|
|
|
|
{"help", no_argument, NULL, 'h'},
|
|
|
|
{"version", no_argument, NULL, 'V'},
|
|
|
|
{NULL, 0, NULL, 0}
|
|
|
|
};
|
|
|
|
|
2012-01-03 13:18:43 +05:30
|
|
|
program_invocation_name = program_invocation_short_name;
|
2011-12-07 17:57:21 +05:30
|
|
|
setlocale (LC_ALL, "");
|
|
|
|
bindtextdomain(PACKAGE, LOCALEDIR);
|
|
|
|
textdomain(PACKAGE);
|
|
|
|
|
2011-06-05 01:03:11 +05:30
|
|
|
while ((c = getopt_long(argc, argv, "hV", longopts, NULL)) != -1)
|
|
|
|
switch (c) {
|
|
|
|
case 'h':
|
|
|
|
usage(stdout);
|
|
|
|
case 'V':
|
2011-10-09 15:55:30 +05:30
|
|
|
printf(PROCPS_NG_VERSION);
|
2011-06-05 01:03:11 +05:30
|
|
|
return EXIT_SUCCESS;
|
|
|
|
default:
|
|
|
|
usage(stderr);
|
|
|
|
}
|
|
|
|
|
|
|
|
print_uptime();
|
|
|
|
return EXIT_SUCCESS;
|
2002-02-02 04:17:29 +05:30
|
|
|
}
|