umask, link, symlink 실습관련 예제..
#include
#include
#include
#include
#include
int main()
{
char *originalname = "test.txt";
char *hardfilename = "test.txt.hard";
char *softfilename = "test.txt.soft";
int filedes, retval;
mode_t oldmask;
char buffer[1024];
int nread;
struct stat finfo;
oldmask = umask(0377);
filedes = open(originalname, O_CREAT, 0755);
close(filedes);
if(retval = access(originalname, W_OK) == -1)
{
printf("%s is not writable\n", originalname);
chmod(originalname, 0644);
}
link(originalname, hardfilename);
symlink(originalname, softfilename);
rename(hardfilename, "newname.txt");
nread = readlink(softfilename, buffer, 1024);
write(1, buffer, nread);
stat(originalname, &finfo);
printf("file mode: %o \n", finfo.st_mode);
printf("file size: %d\n", finfo.st_size);
printf("Num of blocks: %d\n", finfo.st_blocks);
return 0;
}
출처 : 리눅스 프로그래밍 ( 한빛 미디어) ㅎㅎ;;