Programming/System programming
sys/types.h
박세범
2011. 10. 10. 01:51
in order to get the mode of a file, we need to get the information of Inode struct
fortunately, there is a api stat() or fstat()
#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>
int main(int argc, char *argv[])
{
int fd;
struct stat info; // in order to get the status of a file
fd = open(argv[1],O_REWR);
fstat(fd, &info); //fstat(int fileDescriptor, struct stat* info)
printf(fd, (unsigned long)info.st_mode);
return 0;
}
st_mode is one structure in struct stat info. it has a mode of a file(permission)
so if we use this we can copy a file whose mode is exactly same as the file we want to copy from
fd = open(argv[1],O_REWR);
fstat(fd, &info); //fstat(int fileDescriptor, struct stat* info)
printf(fd, (unsigned long)info.st_mode);
return 0;
}
st_mode is one structure in struct stat info. it has a mode of a file(permission)
so if we use this we can copy a file whose mode is exactly same as the file we want to copy from