📄 vrfytool.c
字号:
/* vrfytool.c 23.09.99 tn tool that does read a data-stream from stdin and does compare it with a file on the harddrive.*/#include <stdio.h>#include <stdlib.h>#include <unistd.h>#include <string.h>#include <sys/stat.h>#include <fcntl.h>#include <errno.h>#include <glib.h>#include "xcdroast.h"#define WAVHEADER 44void usage() { g_print("Usage: vrfytool [-d|-a] <file1> <file2> (Version: %s)\n", XCDROAST_VERSION); g_print("\twhen file2 is a dash (-) then compare from stdin\n"); g_print("\t -d: compare data-files (blocksize: 2048)\n"); g_print("\t -a: compare audio-files (blocksize: 2352)\n");}gint main(gint argc, gchar **argv) {gchar file1[MAXLINE];gchar file2[MAXLINE];guchar *buf1;guchar *buf2;struct stat buf;gint size;gint fd1, fd2;gint nread1, nread2;gint bytesread;gint percent, oldpercent;gint bs; if (argc != 4) { usage(); exit(1); } bs = 0; if (strcmp(argv[1],"-a") == 0) { bs = CDDAFRAME; } if (strcmp(argv[1],"-d") == 0) { bs = DATASECTORSIZE; } if (bs == 0) { usage(); exit(1); } strncpy(file1,argv[2],MAXLINE); strncpy(file2,argv[3],MAXLINE); /* get filesize */ if (stat(file1,&buf) != 0) { g_print("Error stating %s: %s\n",file1,strerror(errno)); exit(1); } /* calculate how many bytes to handle */ size = buf.st_size; buf1 = (guchar *)g_new(guchar, bs); buf2 = (guchar *)g_new(guchar, bs); /* open first file */ fd1 = open(file1, O_RDONLY, 0); if (fd1 < 0) { g_print("Error opening %s: %s\n",file1,strerror(errno)); exit(1); } /* open second file..or do read from stdin */ if (strcmp(file2, "-") == 0) { fd2 = STDIN_FILENO; } else { fd2 = open(file2, O_RDONLY, 0); if (fd2 < 0) { g_print("Error opening %s: %s\n",file2,strerror(errno)); exit(1); } } bytesread = 0; oldpercent = 0; g_print("Verifing of %s (%d bytes)\n",file1,size); fflush(stdout); /* start comparing */ while (1) { /* first sector for audio-files is only the wavheader */ /* so read first 44 bytes and then always 2352 bytes */ if (bs == WAVHEADER) { bs = CDDAFRAME; } if (bs == CDDAFRAME && bytesread == 0) { bs = WAVHEADER; } nread2 = read(fd2, buf2, bs); if (nread2 < 0) { g_print("Error reading %s: %s\n",file2,strerror(errno)); exit(1); } /* read exactly as many bytes from file as from stdin */ nread1 = read(fd1, buf1, nread2); if (nread1 < 0) { g_print("Error reading %s: %s\n",file1,strerror(errno)); exit(1); } /* g_print("nread1: %d, nread2: %d\n",nread1,nread2); */ if (nread1 != nread2) { g_print("Warning: Short read on position %d\n", bytesread); exit(1); } /* EOF */ if (nread1 == 0) break; if (memcmp(buf1,buf2,bs) != 0) { g_print("Warning: Files differ on position %d\n", bytesread); exit(1); } bytesread+=nread1; /* output percent meter */ percent = ((bytesread/1024) * 100) / (size/1024); if (percent != oldpercent) { g_print(" %d%%\n", percent); fflush(stdout); oldpercent = percent; } } g_free(buf1); g_free(buf2); close(fd1); close(fd2); if (bytesread != size) { g_print("Warning: different file sizes.\n"); exit(1); } /* all ok - compare perfect */ g_print("Compare of %s successful.\n",file1); fflush(stdout); return 0;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -