pastebin - collaborative debugging tool
eckelmann.kpaste.net RSS


Does |fstatfs()| work with fd from |O_PATH| ? Yes...
Posted by Anonymous on Wed 19th Feb 2020 12:37
raw | new post
view followups (newest first): Does |fstatfs()| work with fd from |O_PATH| ? Yes... by Anonymous

  1.  
  2. /* Needed to obtain |O_PATH| */
  3. #ifndef _GNU_SOURCE
  4. #define _GNU_SOURCE 1
  5. #endif
  6.  
  7. #include <stdlib.h>
  8. #include <stdio.h>
  9. #include <string.h>
  10. #include <fcntl.h>
  11. #include <unistd.h>
  12. #include <sys/statfs.h>
  13. #include <sys/types.h>
  14. #include <sys/stat.h>
  15.  
  16.  
  17.  
  18. int main(int ac, char *av[])
  19. {
  20.         int fd;
  21.         struct statfs statfsbuf;
  22.        
  23.         (void)memset(&statfsbuf, 0, sizeof(statfsbuf));
  24.        
  25.         fd = open("/tmp", O_RDONLY|O_PATH);
  26.         if (fd < 0)
  27.         {
  28.                 perror("open() failed.");
  29.                 return EXIT_FAILURE;
  30.         }
  31.        
  32.         if (fstatfs(fd, &statfsbuf) != 0)
  33.         {
  34.                 perror("fstatfs() failed.");
  35.                 return EXIT_FAILURE;
  36.         }      
  37.  
  38.         (void)close(fd);
  39.  
  40.         (void)printf("f_blocks=%ld\n",  (long)statfsbuf.f_blocks);
  41.         (void)printf("f_bfree=%ld\n",   (long)statfsbuf.f_bfree);
  42.         (void)printf("f_bavail=%ld\n",  (long)statfsbuf.f_blocks);
  43.  
  44.         return EXIT_SUCCESS;
  45. }

Submit a correction or amendment below (click here to make a fresh posting)
After submitting an amendment, you'll be able to view the differences between the old and new posts easily.

Syntax highlighting:

To highlight particular lines, prefix each line with {%HIGHLIGHT}





All content is user-submitted.
The administrators of this site (kpaste.net) are not responsible for their content.
Abuse reports should be emailed to us at