kfsdatagen_main.cc

来自「nandflash文件系统源代码」· CC 代码 · 共 48 行

CC
48
字号
//// Generate out test data to write/read from KFS and validate for correctness.//#include <iostream>    #include <unistd.h>#include <string.h>#include <stdlib.h>#include <fstream>using std::cout;using std::endl;using std::ofstream;void generateData(char *buf, int numBytes);intmain(int argc, char **argv){    int fsize;    if (argc < 2) {        cout << "Usage: " << argv[0] << " <filename> <size> " << endl;        exit(0);    }    fsize = atoi(argv[2]);    generateData(argv[1], fsize);    }voidgenerateData(char *fname, int numBytes){    ofstream ofs(fname);    int i;    if (!ofs) {        cout << "Unable to open file: " << fname << endl;        return;    }        for (i = 0; i < numBytes; i++) {        ofs << (char) ('a' + (rand() % 26));    }    ofs.close();}        

⌨️ 快捷键说明

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