From 82ffdb5ca82878add63018f7943ed2afb8390d03 Mon Sep 17 00:00:00 2001 From: Jonas 'Sortie' Termansen Date: Wed, 15 May 2013 20:29:49 +0200 Subject: [PATCH] Add date(1). --- utils/.gitignore | 1 + utils/Makefile | 1 + utils/date.cpp | 43 +++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 45 insertions(+) create mode 100644 utils/date.cpp diff --git a/utils/.gitignore b/utils/.gitignore index a84da8b1..2f9143f2 100644 --- a/utils/.gitignore +++ b/utils/.gitignore @@ -6,6 +6,7 @@ clear colormake column cp +date echo editor find diff --git a/utils/Makefile b/utils/Makefile index 39211138..66ff4919 100644 --- a/utils/Makefile +++ b/utils/Makefile @@ -22,6 +22,7 @@ clear \ colormake \ column \ cp \ +date \ echo \ editor \ find \ diff --git a/utils/date.cpp b/utils/date.cpp new file mode 100644 index 00000000..1bc9512b --- /dev/null +++ b/utils/date.cpp @@ -0,0 +1,43 @@ +/******************************************************************************* + + Copyright(C) Jonas 'Sortie' Termansen 2013. + + This program is free software: you can redistribute it and/or modify it + under the terms of the GNU General Public License as published by the Free + Software Foundation, either version 3 of the License, or (at your option) + any later version. + + This program 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 General Public License for + more details. + + You should have received a copy of the GNU General Public License along with + this program. If not, see . + + date.cpp + Print or set system date and time. + +*******************************************************************************/ + +#include +#include +#include +#include +#include + +int main(/*int argc, char* argv[]*/) +{ + time_t current_time = time(NULL); + + struct tm tm; + if ( !localtime_r(¤t_time, &tm) ) + error(1, errno, "time(%ji)", (intmax_t) current_time); + + const size_t BUFFER_SIZE = 256; + char buffer[BUFFER_SIZE]; + strftime(buffer, BUFFER_SIZE, "%a %b %d %H:%M:%S %Y", &tm); + printf("%s\n", buffer); + + return 0; +}