[BACK]Return to cvt.c CVS log [TXT][DIR] Up to [local] / src / usr.bin / sup / src

File: [local] / src / usr.bin / sup / src / Attic / cvt.c (download)

Revision 1.2, Wed Jun 26 05:39:39 1996 UTC (27 years, 11 months ago) by deraadt
Branch: MAIN
CVS Tags: OPENBSD_2_9_BASE, OPENBSD_2_9, OPENBSD_2_8_BASE, OPENBSD_2_8, OPENBSD_2_7_BASE, OPENBSD_2_7, OPENBSD_2_6_BASE, OPENBSD_2_6, OPENBSD_2_5_BASE, OPENBSD_2_5, OPENBSD_2_4_BASE, OPENBSD_2_4, OPENBSD_2_3_BASE, OPENBSD_2_3, OPENBSD_2_2_BASE, OPENBSD_2_2, OPENBSD_2_1_BASE, OPENBSD_2_1, OPENBSD_2_0_BASE, OPENBSD_2_0
Changes since 1.1: +2 -0 lines

rcsid

/*	$OpenBSD: cvt.c,v 1.2 1996/06/26 05:39:39 deraadt Exp $	*/

/*
 * Quick hack to convert old binary sup when.collection files into 
 * the new ascii format.
 */
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <fcntl.h>

int
main(argc, argv)
	int argc;
	char *argv[];
{
	long b;
	FILE *fp;
	int fd;

	if (argc != 2) {
		(void) fprintf(stderr, "Usage: %s <filename>\n", argv[0]);
		return 1;
	}

	if ((fd = open(argv[1], O_RDWR)) == -1) {
		perror("open");
		return 1;
	}

	if (read(fd, &b, sizeof(b)) != sizeof(b)) {
		perror("read");
		return 1;
	}

	if (lseek(fd, 0, SEEK_SET) == -1) {
		perror("lseek");
		return 1;
	}

	(void) close(fd);

	if ((fp = fopen(argv[1], "w")) == NULL) {
		perror("fopen");
		return 1;
	}

	if (fprintf(fp, "%ld\n", b) < 0) {
		perror("fprintf");
		return 1;
	}
	if (fclose(fp) != 0) {
		perror("fclose");
		return 1;
	}

	return 0;
}