[C] 读取打开文件信息 →→→→→进入此内容的聊天室

来自 , 2020-06-21, 写在 C, 查看 112 次.
URL http://www.code666.cn/view/35936504
  1. #include <sys\stat.h>
  2. #include <stdio.h>
  3. #include <time.h>
  4.  
  5. #define FILENAME "TEST.$$$"
  6.  
  7. int main(void)
  8. {
  9.    struct stat statbuf;
  10.    FILE *stream;
  11.  
  12.    /* open a file for update */
  13.    if ((stream = fopen(FILENAME, "w+")) == NULL)
  14.    {
  15.       fprintf(stderr, "Cannot open output file.\n");
  16.       return(1);
  17.    }
  18.  
  19.    /* get information about the file */
  20.    stat(FILENAME, &statbuf);
  21.  
  22.    fclose(stream);
  23.  
  24.    /* display the information returned */
  25.    if (statbuf.st_mode & S_IFCHR)
  26.       printf("Handle refers to a device.\n");
  27.    if (statbuf.st_mode & S_IFREG)
  28.       printf("Handle refers to an ordinary file.\n");
  29.    if (statbuf.st_mode & S_IREAD)
  30.       printf("User has read permission on file.\n");
  31.    if (statbuf.st_mode & S_IWRITE)
  32.       printf("User has write permission on file.\n");
  33.  
  34.    printf("Drive letter of file: %c\n", 'A'+statbuf.st_dev);
  35.    printf("Size of file in bytes: %ld\n", statbuf.st_size);
  36.    printf("Time file last opened: %s\n", ctime(&statbuf.st_ctime));
  37.    return 0;
  38. }
  39.  

回复 "读取打开文件信息"

这儿你可以回复上面这条便签

captcha