1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56
|
/* $NetBSD: cvt.c,v 1.3 2002/07/10 18:53:57 wiz 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(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;
}
|