add sleep & date, thanks kamil
parent
8e26716a5a
commit
474ee643ed
@ -0,0 +1,20 @@
|
||||
.TH DATE 1 sbase\-VERSION
|
||||
.SH NAME
|
||||
date \- print date and time
|
||||
.SH SYNOPSIS
|
||||
.B date
|
||||
.RB [ \-d
|
||||
.IR time ]
|
||||
.RI [+ format ]
|
||||
.SH DESCRIPTION
|
||||
.B date
|
||||
prints the date and time. If a
|
||||
.I format
|
||||
is given it is used to format the date as per
|
||||
.BR strftime (3).
|
||||
.SH OPTIONS
|
||||
.TP
|
||||
.BI \-d " time"
|
||||
prints
|
||||
.I time
|
||||
instead of the system time, given as the number of seconds since the Unix epoch.
|
@ -0,0 +1,32 @@
|
||||
/* See LICENSE file for copyright and license details. */
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <time.h>
|
||||
#include "util.h"
|
||||
|
||||
int
|
||||
main(int argc, char *argv[])
|
||||
{
|
||||
char buf[BUFSIZ];
|
||||
char *fmt = "%c";
|
||||
int i;
|
||||
struct tm *now = NULL;
|
||||
time_t t;
|
||||
|
||||
t = time(NULL);
|
||||
for(i = 1; i < argc; i++)
|
||||
if(!strncmp("+", argv[i], 1))
|
||||
fmt = &argv[i][1];
|
||||
else if(!strcmp("-d", argv[i]) && i+1 < argc)
|
||||
t = strtol(argv[++i], NULL, 0);
|
||||
else
|
||||
eprintf("usage: %s [-d time] [+format]\n", argv[0]);
|
||||
now = localtime(&t);
|
||||
if(!now)
|
||||
eprintf("localtime failed\n");
|
||||
|
||||
strftime(buf, sizeof buf, fmt, now);
|
||||
puts(buf);
|
||||
return EXIT_SUCCESS;
|
||||
}
|
@ -0,0 +1,9 @@
|
||||
.TH SLEEP 1 sbase\-VERSION
|
||||
.SH NAME
|
||||
sleep \- wait for a number of seconds
|
||||
.SH SYNOPSIS
|
||||
.B sleep
|
||||
.I seconds
|
||||
.SH DESCRIPTION
|
||||
.B sleep
|
||||
waits until the given number of seconds have elapsed.
|
@ -0,0 +1,18 @@
|
||||
/* See LICENSE file for copyright and license details. */
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
#include "util.h"
|
||||
|
||||
int
|
||||
main(int argc, char *argv[])
|
||||
{
|
||||
unsigned int seconds;
|
||||
|
||||
if(argc != 2)
|
||||
eprintf("usage: %s seconds\n", argv[0]);
|
||||
|
||||
seconds = atoi(argv[1]);
|
||||
while((seconds = sleep(seconds)) > 0)
|
||||
;
|
||||
return EXIT_SUCCESS;
|
||||
}
|
Loading…
Reference in New Issue