
fstat 함수는 stat 함수와 유사하게 동작하며, 특정 파일 디스크립트를 사용하여 파일의 정보를 얻을 수 있습니다.
fstat 함수의 사용법은 다음과 같습니다.
#hostingforum.kr
c
#include
int fstat(int fd, struct stat *buf);
fd는 파일 디스크립트를 나타내고, buf는 파일의 정보를 저장할 구조체입니다.
예를 들어, 다음과 같이 사용할 수 있습니다.
#hostingforum.kr
c
#include
#include
int main() {
int fd = open("test.txt", O_RDONLY);
struct stat buf;
if (fstat(fd, &buf) == -1) {
perror("fstat");
return 1;
}
printf("파일의 크기: %lldn", buf.st_size);
printf("파일의 타입: %dn", buf.st_mode & S_IFMT);
close(fd);
return 0;
}
이 예제에서는 "test.txt" 파일의 크기와 타입을 출력합니다.
fstat 함수는 파일 디스크립트를 사용하여 파일의 정보를 얻을 수 있으므로, 파일을 열어 디스크립트를 얻은 후에 사용할 수 있습니다.
2025-04-16 06:06