chkfsize.c

来自「Boot code for ADM5120 with serial consol」· C语言 代码 · 共 42 行

C
42
字号
/* *	Tool to determine whether a file exceeds a given size. *	Author: HH *	Copyright 2006 HH, All Rights Reserved */#include <sys/stat.h>#include <unistd.h>void usage(char *me){	printf("Usage: %s input-file MAXSIZE\n", me);	printf("       where MAXSIZE is the maximum file size for which the program\n");	printf("       will return 0.  If the input-file size is greater than MAXSIZE\n");	printf("       the program will return 1.  Intended for use with Makefiles.\n");}int main(int argc, char** argv){	char *infile = NULL;	int fh, size, rc = 1;	struct stat status;	/*	Parse input arguments */	if ((argc != 3) || (sscanf(argv[2], "%i", &size) != 1)) {		usage((char *) basename(argv[0]));	} else {		/*	Input arguments look good */		infile  = argv[1];		if (stat(infile, &status) < 0) {			printf("%s: Can't stat file \"%s\"\n", basename(argv[0]), infile);		} else {			if (status.st_size <= size)				rc = 0;			else				printf("%s: File \"%s\" exceeds %d bytes (0x%.8X) in size\n", basename(argv[0]), infile, size, size);		}	}	return rc;}

⌨️ 快捷键说明

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