X-Git-Url: https://gapil.gnulinux.it/gitweb/?p=gapil.git;a=blobdiff_plain;f=sources%2Ftestctime.c;fp=sources%2Ftestctime.c;h=dfdeefadd6ac6ba1cb4aba7d2c23b6f2ed5230e4;hp=0000000000000000000000000000000000000000;hb=414401b178e7542189e5cc13ebafd8806cee3724;hpb=4decc63372dbdb009486d9877fe8d9a1df8e29ed diff --git a/sources/testctime.c b/sources/testctime.c new file mode 100644 index 0000000..dfdeefa --- /dev/null +++ b/sources/testctime.c @@ -0,0 +1,94 @@ +/* testctime.c + * + * Copyright (C) 2001 Simone Piccardi + * + * 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 2 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, write to the Free Software + * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + */ +/**************************************************************** + * + * Program test_ctime.c: + * Program to test function ctime + * + * Author: Simone Piccardi + * Oct. 2001 + * + * + ****************************************************************/ +/* + * Include needed headers + */ +#define _GNU_SOURCE +#include /* error definitions and routines */ +#include /* C standard library */ +#include /* unix standard library */ +#include /* standard I/O library */ +#include /* C strings library */ +#include + +/* Help printing routine */ +void usage(void); + +int main(int argc, char *argv[]) +{ +/* + * Variables definition + */ + int i; + /* + * Input section: decode command line parameters + * Use getopt function + */ + opterr = 0; /* don't want writing to stderr */ + while ( (i = getopt(argc, argv, "h")) != -1) { + switch (i) { + /* + * Handling options + */ + case 'h': /* help option */ + printf("Wrong -h option use\n"); + usage(); + return -1; + break; + case '?': /* unrecognized options */ + printf("Unrecognized options -%c\n",optopt); + usage(); + default: /* should not reached */ + usage(); + } + } + /* *********************************************************** + * + * Options processing completed + * + * Main code beginning + * + * ***********************************************************/ + time_t t; + t = time(NULL); + printf("%s", ctime(&t)); + return 0; +} +/* + * routine to print usage info and exit + */ +void usage(void) { + printf("Program testctime : test ctime functon \n"); + printf("Usage:\n"); + printf(" testctime [-h] \n"); + printf(" -h print this help\n"); + + exit(1); +} +