我的学习之旅(7) build工具
来源:互联网 发布:mac pro测评 编辑:程序博客网 时间:2024/06/05 07:45
build_boot.c源代码
#include <stdio.h>#include <string.h>#include <stdlib.h> #include <sys/types.h> #include <sys/stat.h>#include <linux/fs.h>#include <unistd.h>#include <fcntl.h>#define MINIX_HEADER_LEN 32#define BOOT_LENGTH 512int main(int argc, char *argv[] ){ char buf[1024]; int fd; int len; if( argc != 3 ) { printf("no input file\n"); return 0; } sprintf(buf,"rm -f %s", argv[2]); system(buf); sprintf(buf,"touch %s", argv[2]); system(buf); fd = open(argv[1], O_RDONLY, 0 ); if( fd < 0 ){ printf("open file:%s failed\n", argv[1]); return 0; } if( read(fd, buf, MINIX_HEADER_LEN)!= MINIX_HEADER_LEN) { close(fd); printf("Invalid mini header len:%d\n", MINIX_HEADER_LEN); return 0; } memset(buf, 0x0, sizeof(buf)); len = read(fd, buf, sizeof(buf)); if( len != BOOT_LENGTH ) { printf("wrong boot length:%d, should be %d\n", len, BOOT_LENGTH); return 0; } close(fd); fd = open(argv[2], O_WRONLY, O_CREAT | O_EXCL | O_SYNC ); if( fd < 0 ){ printf("open file:%s failed\n", argv[2]); return 0; } len = write(fd, buf, BOOT_LENGTH); if( len != BOOT_LENGTH ){ printf("write failed with len:%d, should be:%d\n", len, BOOT_LENGTH); return 0; } close(fd); return 0;}
build_setup.c和build_boot.c类似。
编译: gcc -Wall -O2 -fomit-frame-pointer -o build_boot build_boot.c
gcc -Wall -O2 -fomit-frame-pointer -o build_boot build_setup.c
0 0
- 我的学习之旅(7) build工具
- 我的数据工具学习之旅
- 我的Java开发学习之旅------>自己编写的Java数组操作工具
- 我的学习之旅
- BUILD工具的操作过程
- BUILD工具的调用
- build工具的基本原理
- 我的Android NDK之旅(一),不使用ndk-build命令来创建jni
- 我的Android NDK之旅(二),使用ndk-build构建Jni
- 我的python的学习之旅
- 我的Java开发学习之旅------>工具类:Java获取字符串和文件进行MD5值
- 我的Java开发学习之旅------>工具类:Java使用正则表达式分离出字符串中的中文和英文
- 我的DirectDraw7学习之旅
- 我的VS.NET学习之旅
- 我的VS.NET学习之旅
- 我的VS.NET学习之旅
- 开始我的AS3学习之旅
- 我的程序设计学习之旅1
- php实现工厂模式
- MYSQL手册 以及PHPINFO里面的设置
- 在android模拟器下显示jquery mobile的页面
- Java File
- 求质数1 C实现
- 我的学习之旅(7) build工具
- 实现表达式求值(c++实现)
- IOC
- 通过vnc 用电脑 控制 手机
- 黑马程序员---第一个IOS程序
- ZeroMQ介绍
- Mac PhotoShop CS6破解
- ZIGBee拓扑
- AS3 纯代码打造不规则遮罩,透明区域不操作