open.c
#include <unistd.h>#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <stdlib.h>
#include <stdio.h>
int main(void)
{
int fd;
if((fd=open("/WIN_UBUNTU/sample/open/opentest.c",O_CREAT|O_TRUNC|O_WRONLY,0600))<0)
{
perror("open:");
exit(1);
}
else
{
printf("open file: opentest.c %d\n", fd);
}
if(close(fd)<0)
{
perror("close:");
exit(1);
}
else
{
printf("close file: opentest.c %d\n", fd);
}
exit(0);
}
Makefile
obj=open.o
open:$(obj)gcc $(obj) -o open
open.o:open.c
gcc -c open.c
clean:
rm $(obj) open opentest.c