📄 create_image.c
字号:
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
int main(int argc, char *argv[])
{
/*FILE *fp;
if (argc != 2) {
printf("use: create_image filename\n");
return 0;
}
fp = fopen(argv[1], "ab+");
if (fp == NULL) {
printf("open %s failed!\n", argv[1]);
return 0;
}
fseek(fp, 1474560 - 1, SEEK_SET);
fprintf(fp, "%d", 3);
fclose(fp);
*/
int fp;
char *pbuf = NULL;
int endpos = 0;
if (argc != 2) {
printf("use: create_image filename\n");
return 0;
}
fp = open(argv[1], O_RDWR, O_CREAT | O_EXCL | O_SYNC);
if (fp == -1) {
perror("failed!\n");
return 0;
}
endpos = lseek(fp, 0, SEEK_END);
//printf("endpos:%d\n", endpos);
pbuf = malloc(1474560 - endpos);
memset(pbuf, 0, 1474560 - endpos);
write(fp, pbuf, 1474560 - endpos);
free(pbuf);
close(fp);
return 0;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -