#include <unistd.h>
#include <stdio.h>
extern unsigned char _binary_bin_start;
extern unsigned char _binary_bin_end;
extern unsigned char _binary_bin_size;
int main(int argc, char *argv[]){
unsigned char *pblob = &_binary_bin_start;
int size = &_binary_bin_end - &_binary_bin_start;
printf("size: %d\n", size);
FILE *f = fopen("hello.bin", "wb");
if(f==NULL){
printf("file not opened");
}else{
int ret = fwrite(&_binary_bin_start, size, 1, f);
fclose(f);
printf("return val: %d\n", ret);
}
}
我编译它然后链接到用objcopy创建的可执行二进制文件的目标文件。昨天一切都很好,创建了文件hello.bin,填充了数据,并且在chmod之后可执行。今天它突然停止填充数据 - 文件位于0字节并且没有'文件未打开'消息,并且fwrite的返回值为1.
可能是什么原因?