📄 erase.c
字号:
/* * $ Revision 1.1 (c) 2001/10/13. Zhihui Li, Wanhe Metwork Corp.,Ltd.$ * Added command line processing and GNU long options. * */#include <stdio.h>#include <unistd.h>#include <string.h>#include <getopt.h>#include <fcntl.h>#include <linux/flash.h>extern char *optarg; /* Option argument */extern int optind; /* Option/arg index */extern int opterr; /* Error handling flg *//* Show brief command usage help: */static void usage(const char*cmd) { fprintf(stderr,"Usage: %s [-h | --help] [--version] infile...\n",cmd); printf("\t-h (or --help)\tGives this command help display.\n" "\t\t\tYour should do like this 'erase /dev/flash1'\n",stderr); printf("\t--version\tDisplay program version.\n",stderr);}static char* Basename(const char *path){ char *base_name=0; if((base_name=strrchr(path,'/'))!=0) ++base_name; /* Skip over */ else base_name =(char*)path; /* No dir. */ return base_name; }int main(int argc, char *argv[]){ int fd; char *base_name=0; int cmdx=0; /* lopts[] index */ int optch; /* Current option character */ static char stropts[]="h"; /* Supported options */ static struct option lopts[]={ {"help",0,0,'h'}, /* --help */ {"version",0,0,'v'}, /* --version */ {0,0,0,0} }; base_name=Basename(argv[0]); /* * Process all command line options : */ while((optch=getopt_long(argc,argv,stropts,lopts,&cmdx))!=EOF) switch(optch){ case 0: /* Processed lopts[cmdx] */ break; case 'h': usage(base_name); return 0; case 'v': fprintf(stderr,"\tVision 1.1 (c) 2001/10/13. Zhihui Lee, Wanhe Metwork Corp.,Ltd.\n"); return 0; default: /* Unsupported option */ printf("Use --help or -h for help.\n"); return 1; } if (argc != 2) { puts("Usage: erase /dev/flashX\n" "Use --help or -h for help\n"); exit(1); } if ((fd = open(argv[1], O_RDWR)) < 0) { perror("open"); exit(1); } if (ioctl(fd, FLASHIO_ERASEALL, 0L) == -1) { perror("ioctl(FLASHIO_ERASEALL)"); close(fd); exit(1); } close(fd); exit(0);}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -