int stat(char *filename, struct stat *statbuf)
Прототип:
Описание:
Функция stat() вносит в структуру, на которую указывает statbuf, информацию, содержащуюся в файле, связанном с указателем filename. Структура stat определена в sys\stat.h.
При успешном заполнении структуры stat возвращается 0. В случае неудачи возвращается —1, а errno устанавливается в ENOENT.
Пример:
В следующем примере открывается файл, заполняется структура stat и выводится одно из ее полей:
#include <stdio.h>
#include <sys\stat.h>
#include <stdlib.h>
int main(void)
{
FILE *fp;
struct stat buff;
if((fp=fopen("test", "rb"))==NULL) {
printf("Cannot open file.\n");
exit (1);
}
/* заполнение структуры типа stat */
stat("test", &buff);
printf("Size of the file is: %ld\n", buff.st_size);
fclose(fp);
return 0;
}
#include <stdio.h>
#include <sys\stat.h>
#include <stdlib.h>
int main(void)
{
FILE *fp;
struct stat buff;
if((fp=fopen("test", "rb"))==NULL) {
printf("Cannot open file.\n");
exit (1);
}
/* заполнение структуры типа stat */
stat("test", &buff);
printf("Size of the file is: %ld\n", buff.st_size);
fclose(fp);
return 0;
}