diff --git a/Makefile b/Makefile index 132b9d8..3443384 100644 --- a/Makefile +++ b/Makefile @@ -29,6 +29,7 @@ dist: $(PACKAGE)-$(VERSION)/src/cksum.c \ $(PACKAGE)-$(VERSION)/src/cmp.c \ $(PACKAGE)-$(VERSION)/src/cp.c \ + $(PACKAGE)-$(VERSION)/src/date.c \ $(PACKAGE)-$(VERSION)/src/df.c \ $(PACKAGE)-$(VERSION)/src/dirname.c \ $(PACKAGE)-$(VERSION)/src/du.c \ diff --git a/src/Makefile b/src/Makefile index 84cc263..9ad96b8 100644 --- a/src/Makefile +++ b/src/Makefile @@ -1,4 +1,4 @@ -TARGETS = basename cat chgrp chmod chown cksum cmp cp df dirname du echo false file find head id kill link ln locale logname ls mkdir mkfifo more mv nice pr printf ps pwd renice rm rmdir sleep strings tail test time touch true tty uname uniq unlink wc who +TARGETS = basename cat chgrp chmod chown cksum cmp cp date df dirname du echo false file find head id kill link ln locale logname ls mkdir mkfifo more mv nice pr printf ps pwd renice rm rmdir sleep strings tail test time touch true tty uname uniq unlink wc who PREFIX = /usr/local DESTDIR = BINDIR = $(PREFIX)/bin @@ -72,6 +72,13 @@ cp_LDFLAGS = $(LDFLAGSF) $(LDFLAGS) cp: $(cp_OBJS) $(CC) -o cp $(cp_OBJS) $(cp_LDFLAGS) +date_OBJS = date.o +date_CFLAGS = $(CPPFLAGSF) $(CPPFLAGS) $(CFLAGSF) $(CFLAGS) +date_LDFLAGS = $(LDFLAGSF) $(LDFLAGS) + +date: $(date_OBJS) + $(CC) -o date $(date_OBJS) $(date_LDFLAGS) + df_OBJS = df.o df_CFLAGS = $(CPPFLAGSF) $(CPPFLAGS) $(CFLAGSF) $(CFLAGS) df_LDFLAGS = $(LDFLAGSF) $(LDFLAGS) @@ -376,6 +383,9 @@ cmp.o: cmp.c cp.o: cp.c $(CC) $(cp_CFLAGS) -c cp.c +date.o: date.c + $(CC) $(date_CFLAGS) -c date.c + df.o: df.c $(CC) $(df_CFLAGS) -c df.c @@ -497,7 +507,7 @@ who.o: who.c $(CC) $(who_CFLAGS) -c who.c clean: - $(RM) -- $(basename_OBJS) $(cat_OBJS) $(chgrp_OBJS) $(chmod_OBJS) $(chown_OBJS) $(cksum_OBJS) $(cmp_OBJS) $(cp_OBJS) $(df_OBJS) $(dirname_OBJS) $(du_OBJS) $(echo_OBJS) $(false_OBJS) $(file_OBJS) $(find_OBJS) $(head_OBJS) $(id_OBJS) $(kill_OBJS) $(link_OBJS) $(ln_OBJS) $(locale_OBJS) $(logname_OBJS) $(ls_OBJS) $(mkdir_OBJS) $(mkfifo_OBJS) $(more_OBJS) $(mv_OBJS) $(nice_OBJS) $(pr_OBJS) $(printf_OBJS) $(ps_OBJS) $(pwd_OBJS) $(renice_OBJS) $(rm_OBJS) $(rmdir_OBJS) $(sleep_OBJS) $(strings_OBJS) $(tail_OBJS) $(test_OBJS) $(time_OBJS) $(touch_OBJS) $(true_OBJS) $(tty_OBJS) $(uname_OBJS) $(uniq_OBJS) $(unlink_OBJS) $(wc_OBJS) $(who_OBJS) + $(RM) -- $(basename_OBJS) $(cat_OBJS) $(chgrp_OBJS) $(chmod_OBJS) $(chown_OBJS) $(cksum_OBJS) $(cmp_OBJS) $(cp_OBJS) $(date_OBJS) $(df_OBJS) $(dirname_OBJS) $(du_OBJS) $(echo_OBJS) $(false_OBJS) $(file_OBJS) $(find_OBJS) $(head_OBJS) $(id_OBJS) $(kill_OBJS) $(link_OBJS) $(ln_OBJS) $(locale_OBJS) $(logname_OBJS) $(ls_OBJS) $(mkdir_OBJS) $(mkfifo_OBJS) $(more_OBJS) $(mv_OBJS) $(nice_OBJS) $(pr_OBJS) $(printf_OBJS) $(ps_OBJS) $(pwd_OBJS) $(renice_OBJS) $(rm_OBJS) $(rmdir_OBJS) $(sleep_OBJS) $(strings_OBJS) $(tail_OBJS) $(test_OBJS) $(time_OBJS) $(touch_OBJS) $(true_OBJS) $(tty_OBJS) $(uname_OBJS) $(uniq_OBJS) $(unlink_OBJS) $(wc_OBJS) $(who_OBJS) distclean: clean $(RM) -- $(TARGETS) @@ -520,6 +530,8 @@ install: $(TARGETS) $(MKDIR) $(DESTDIR)$(BINDIR) $(INSTALL) -m 0755 cp $(DESTDIR)$(BINDIR)/cp $(MKDIR) $(DESTDIR)$(BINDIR) + $(INSTALL) -m 0755 date $(DESTDIR)$(BINDIR)/date + $(MKDIR) $(DESTDIR)$(BINDIR) $(INSTALL) -m 0755 df $(DESTDIR)$(BINDIR)/df $(MKDIR) $(DESTDIR)$(BINDIR) $(INSTALL) -m 0755 dirname $(DESTDIR)$(BINDIR)/dirname @@ -609,6 +621,7 @@ uninstall: $(RM) -- $(DESTDIR)$(BINDIR)/cksum $(RM) -- $(DESTDIR)$(BINDIR)/cmp $(RM) -- $(DESTDIR)$(BINDIR)/cp + $(RM) -- $(DESTDIR)$(BINDIR)/date $(RM) -- $(DESTDIR)$(BINDIR)/df $(RM) -- $(DESTDIR)$(BINDIR)/dirname $(RM) -- $(DESTDIR)$(BINDIR)/du diff --git a/src/date.c b/src/date.c new file mode 100644 index 0000000..485b990 --- /dev/null +++ b/src/date.c @@ -0,0 +1,82 @@ +/* $Id$ */ +/* Copyright (c) 2014 Pierre Pronchery */ +/* This file is part of DeforaOS Unix utils */ +/* 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, version 3 of the License. + * + * 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 . */ + + + +#include +#include +#include + + +/* date */ +/* private */ +/* prototypes */ +static int _date(void); +static int _date_error(char const * message, int ret); +static int _usage(void); + + +/* functions */ +/* date */ +static int _date(void) +{ + time_t t; + struct tm tm; + char buf[128]; + + tzset(); + if((t = time(NULL)) == -1) + return -_date_error("time", 1); + if(localtime_r(&t, &tm) == NULL) + return -_date_error("localtime_r", 1); + if(strftime(buf, sizeof(buf), "%a %b %e %H:%M:%S %Z %Y", &tm) == 0) + return -_date_error("strftime", 1); + puts(buf); + return 0; +} + + +/* error */ +static int _date_error(char const * message, int ret) +{ + fputs("date: ", stderr); + perror(message); + return ret; +} + + +/* usage */ +static int _usage(void) +{ + fputs("Usage: date\n", stderr); + return 1; +} + + +/* main */ +int main(int argc, char * argv[]) +{ + int o; + + while((o = getopt(argc, argv, "")) != -1) + switch(o) + { + default: + return _usage(); + } + if(argc - optind != 0) + return _usage(); + return (_date() == 0) ? 0 : 2; +} diff --git a/src/project.conf b/src/project.conf index 3b29c9b..d633abb 100644 --- a/src/project.conf +++ b/src/project.conf @@ -1,4 +1,4 @@ -targets=basename,cat,chgrp,chmod,chown,cksum,cmp,cp,df,dirname,du,echo,false,file,find,head,id,kill,link,ln,locale,logname,ls,mkdir,mkfifo,more,mv,nice,pr,printf,ps,pwd,renice,rm,rmdir,sleep,strings,tail,test,time,touch,true,tty,uname,uniq,unlink,wc,who +targets=basename,cat,chgrp,chmod,chown,cksum,cmp,cp,date,df,dirname,du,echo,false,file,find,head,id,kill,link,ln,locale,logname,ls,mkdir,mkfifo,more,mv,nice,pr,printf,ps,pwd,renice,rm,rmdir,sleep,strings,tail,test,time,touch,true,tty,uname,uniq,unlink,wc,who cflags_force=-W cflags=-Wall -g -O2 -pedantic dist=Makefile,common.c @@ -47,6 +47,11 @@ type=binary sources=cp.c install=$(BINDIR) +[date] +type=binary +sources=date.c +install=$(BINDIR) + [df] type=binary sources=df.c diff --git a/tools/utils.c b/tools/utils.c index ceb4c25..83c6183 100644 --- a/tools/utils.c +++ b/tools/utils.c @@ -138,6 +138,21 @@ #undef _prefs_parse #undef _cp +/* date.c */ +#define main _date_main +#define _usage _date_usage +#define _Prefs _date_Prefs +#define Prefs date_Prefs +#define _prefs_parse _date_prefs_parse +#define _date __date +#include "../src/date.c" +#undef main +#undef _usage +#undef _Prefs +#undef Prefs +#undef _prefs_parse +#undef _date + /* df.c */ #define main _df_main #define _usage _df_usage @@ -750,6 +765,7 @@ Call calls[] = { "cksum", _cksum_main }, { "cmp", _cmp_main }, { "cp", _cp_main }, + { "date", _date_main }, { "df", _df_main }, { "dirname", _dirname_main }, { "du", _du_main },