⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 openfiles.c

📁 使用libscsi做的一系列cdrom操作工具程序。包含cdwrite,cdflush,cdda三个程序
💻 C
字号:
/*  openfiles -- open track files and calculate space needed  Copyright (C) 1996 Dieter Baron and Armin Obersteiner  This file is part of cdwrite.  The authors can be contacted at	<dillo@giga.or.at>	<armin.obersteiner@giga.or.at>  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., 675 Mass Ave, Cambridge, MA 02139, USA.*/#include "cdwrite.h"#include <sys/types.h>#include <sys/stat.h>#include <stdio.h>#include <string.h>#include <limits.h>#include <unistd.h>#include <errno.h>#include <fcntl.h>intopen_files(void){    int i;    u_char b[2048];    int blks, blksize;    struct stat stat;    blks = 0;    for (i=0; i<track; i++) {	if (strcmp(tinfo[i].name, "-") == 0)	    tinfo[i].fd = 0;	else {	    if ((tinfo[i].fd = open(tinfo[i].name, O_RDONLY, 0)) < 0) {		fprintf(stderr, "%s: can't open `%s': %s\n",			prg, tinfo[i].name, strerror(errno));		return -1;	    }	}	if (tinfo[i].size == ULONG_MAX) {	    if (lseek(tinfo[i].fd, 16<<11, SEEK_SET) < 0) {		fprintf(stderr, "%s: can't get iso size for `%s' "			"(seek): %s\n",			prg, tinfo[i].name, strerror(errno));		return -1;	    }	    if (read(tinfo[i].fd, b, 2048) < 0) {		fprintf(stderr, "%s: can't get iso size for `%s' (read): %s\n",			prg, tinfo[i].name, strerror(errno));		return -1;	    }	    	    if (lseek(tinfo[i].fd, 0, SEEK_SET) < 0) {		fprintf(stderr, "%s: can't rewind `%s': %s\n",			prg, tinfo[i].name, strerror(errno));		return -1;	    }#if SC_BIGENDIAN	    tinfo[i].size = *(u_long *)(b+84)*2048;#else	    tinfo[i].size = *(u_long *)(b+80)*2048;#endif	    if (tinfo[i].size == 0) {		fprintf(stderr, "%s: iso size for `%s' is zero\n",			prg, tinfo[i].name);		return -1;	    }	}    	if (fstat(tinfo[i].fd, &stat) < 0) {	    fprintf(stderr, "%s: can't stat `%s': %s\n",		    prg, tinfo[i].name, strerror(errno));	    return -1;	}	if (tinfo[i].size == 0) {#if defined(S_IFCHR) && defined(S_IFBLK)	    if ((stat.st_mode & S_IFMT) == S_IFCHR		|| (stat.st_mode & S_IFMT) == S_IFBLK) {		fprintf(stderr, "%s: `%s' is special device, but no "			"size specified\n",			prg, tinfo[i].name);		return -1;	    }#endif        	    if ((tinfo[i].size=(u_long)stat.st_size) == 0		&& verbose > -1) {		fprintf(stderr, "%s: warning: unknown size for "			"track %d (%s)\n",			prg, i, tinfo[i].name);		if (confirm > -1)		    confirm = 1;	    }	}	else {	    if (tinfo[i].size > stat.st_size && stat.st_size != 0) {		fprintf(stderr, "%s: `%s': specified size (%ld) is larger "			"than actual (%ld)\n",			prg, tinfo[i].name,			(long)tinfo[i].size, (long)stat.st_size);		return -1;	    }	}    	blksize = tinfo[i].audio ? 2352 : 2048;	if (tinfo[i].size % blksize != 0 && verbose > -1) {	    fprintf(stderr, "%s: warning: length of track %d (%s) is not "		    "multiple of block length\n",		    prg, i, tinfo[i].name);	    if (confirm > -1)		confirm = 1;	}	blks += (tinfo[i].size+blksize-1) / blksize;    }    return blks;}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -