/*-
* Copyright (c) 2001-2005 Christian S.J. Peron
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/
#ifndef lint
static const char rcsid[] =
"@(#) $Header: /usr/cvs/ipex/version.c,v 1.3 2005/02/16 17:16:55 modulus Exp $";
#endif
#include <sys/param.h>
#include <sys/utsname.h>
#include <stdio.h>
#include <string.h>
#include <time.h>
#include <stdlib.h>
int
main(argc, argv)
int argc;
char **argv;
{
char hn[MAXHOSTNAMELEN + 1];
struct utsname uts;
char version[1024];
FILE *fp;
time_t clock_string;
char *c;
char *path;
time(&clock_string);
if ((fp = fopen("version.h", "w")) == NULL) {
perror("fopen()");
exit(1);
}
if ((path = malloc(MAXPATHLEN)) == 0) {
fprintf(stderr,"fatal: exhausted memory\n");
exit(1);
}
getwd(path);
(void) fprintf(fp,"#if (!defined(_VERSION_H_))\n");
(void) fprintf(fp,"#define _VERSION_H_\n\n");
memset(&uts, 0, sizeof(uts));
uname(&uts);
snprintf(version,sizeof(version),
"static const char version_string[]=\n"
"\"%s@%s:%s (%s/%s)\";\n\n",
getlogin(),
uts.nodename,
path,
uts.sysname,
uts.machine);
c = ctime(&clock_string);
(c[strlen(c)-1] = '\0');
(void) fprintf(fp,"static const char clock__[]=\n"
"\"%s\";\n\n", c);
(void) fprintf(fp,"%s\n", version);
(void) fprintf(fp,"#endif /* _VERSION_H_ */\n");
free(path);
fclose(fp);
return(0);
}
syntax highlighted by Code2HTML, v. 0.9.1