1.通过对库函数的调用来实现对文件的改名
2.在C语言代码中调用汇编来实现对文件的改名
3.通过对库函数的调用来获取系统时间
代码如下:
#include<stdio.h>
#include<time.h>
int main(){
time_t tt;
struct tm *t;
tt = time(NULL);
t = localtime(&tt);
printf("time:%d:%d:%d:%d:%d:%d:
",t->tm_year+1900,t->tm_mon+1,t->tm_mday,t->tm_hour,t->tm_min,t->tm_sec);
return 0;
}
4.在C语言代码中调用汇编来触发系统调用
#include<stdio.h>
#include<time.h>
int main(){
time_t tt;
struct tm *t;
asm volatile(
"movl $0,%%ebx
"
"movl $0xd,%%eax
"
"int $0x80
"
"movl %%eax,%0
"
:"=m"(tt)
:
:"eax","ebx"
);
t=localtime(&tt);
printf("time:%d:%d:%d:%d:%d:%d:
",t->tm_year+1900,t->tm_mon+1,t->tm_mday,t->tm_hour,t->tm_min,t->tm_sec);
return 0;
}
遇到的问题:
解决办法利用32位进行编译:
gcc time-asm.c -o time-asm -m32