/* timestamp.c: Timestamp acquisition and setting code.
 *
 * $Id: timestamp.c,v 1.6 2002/12/20 11:15:27 andy Exp $
 *
 * Copyright (C) 2002 Andy Goth <unununium@openverse.com>
 * For more information visit http://ioioio.net/devel/install-log/
 * 
 * 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., 59 Temple
 * Place - Suite 330, Boston, MA  02111-1307, USA. */

#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h> 
#include <sys/stat.h> 
#include <time.h>
#include <utime.h>
#include <unistd.h>
#include <errno.h>
#include "install-log.h"

typedef struct stat stat_t;

/* Gets the time of the timestamp file. */
void get_timestamp(void)
{
	stat_t status;
	
	char* filename = safe_sprintf(NULL, NULL, "%s/.timestamp", logdir);
	collapse(filename, '/');
	if (stat(filename, &status) == -1)
		fail("Run 'touch %s' and install something first\n", filename);
	free(filename);

	timestamp = status.st_mtime;
}

/* Makes the timestamp file reflect the current time. */
void touch_timestamp(void)
{
	char* filename = safe_sprintf(NULL, NULL, "%s/.timestamp", logdir);
	collapse(filename, '/');
	if (utime(filename, NULL) == -1)
		alert("timestamp(%s/.timestamp): %s\n", logdir,
				strerror(errno));
	free(filename);
}

/* EOF */

