chksize.c

来自「DOS下的调试工具」· C语言 代码 · 共 51 行

C
51
字号
/*****************************************************************************
* chksize.c -- compare size of file with command line argument.
* Copyright (c) 2007, Oleg O. Chukaev
*
* 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\stat.h>

int main (int argc, char *argv[]) {

	struct stat statbuf;
	long size;

	if (argc < 3) {
		printf ("chksize: error: filename and/or filesize not specified\n");
		printf ("usage: chksize <file> <size-in-bytes>\n\n");
		return (1);
	}

	if ((stat (argv[1], &statbuf)) != 0) {
		printf ("chksize: error: file not found: `%s'\n\n", argv[1]);
		return (2);
	}

	size = atol (argv[2]);
	if (statbuf.st_size != size) {
		printf ("chksize: error: filesize do not match: %ld instead of %ld\n\n", statbuf.st_size, size);
		return (3);
	}

	return (0);
}


⌨️ 快捷键说明

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