Thread: struct stat

  1. #1
    Registered User
    Join Date
    Sep 2009
    Posts
    4

    struct stat

    I need to use the built-in struct stat.
    How can I get the information of a file into a stat structure?

    Thanks in advance,
    DarkRoom

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,660
    There is no build-in struct stat
    It depends on your OS, so if you're trying this on windows, then you're out of luck.

    Tell us what you're trying to do, and the OS/Compiler you're using.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  3. #3
    Registered User
    Join Date
    Sep 2009
    Posts
    4
    Sorry, I wasn't explicit. I am using ubuntu. Compiler gcc
    I want to use the structure stat defined in sys/stat.h to gather file information.

  4. #4
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,660
    OK, that would work.
    Have you figured anything out at all? Have you read the manual page for the function?
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  5. #5
    Registered User
    Join Date
    Sep 2009
    Posts
    4
    Ya, i got it. But is am still facing problems to check whether a given file path is that of a directory. Because I need to implement ls -l, I need the permissions and also the information about it being a directory.

  6. #6
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,336
    So are you not allowed to use S_<whatever> macros for some reason?

  7. #7
    and the hat of sweating
    Join Date
    Aug 2007
    Location
    Toronto, ON
    Posts
    3,545
    Quote Originally Posted by Salem View Post
    There is no build-in struct stat
    It depends on your OS, so if you're trying this on windows, then you're out of luck.

    Tell us what you're trying to do, and the OS/Compiler you're using.
    Why? Windows supports the stat() function too, although they probably renamed it to _stat().
    "I am probably the laziest programmer on the planet, a fact with which anyone who has ever seen my code will agree." - esbo, 11/15/2008

    "the internet is a scary place to be thats why i dont use it much." - billet, 03/17/2010

  8. #8
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    Quote Originally Posted by cpjust View Post
    Why? Windows supports the stat() function too, although they probably renamed it to _stat().
    There is no such thing as a "windows compiler". There are compilers that run in Windows. There are compilers that can produce executables for Windows. But saying "Windows supports the stat() function..." is not accurate.

    There is no stat function in the standard C library.


    Quzah.
    Hope is the first step on the road to disappointment.

  9. #9
    Registered User
    Join Date
    Sep 2009
    Posts
    4
    Thanks, I didn't know about the S_<macros>.
    Searched the internet and got it. Now my code works.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Need help with linked list sorting function
    By Jaggid1x in forum C Programming
    Replies: 6
    Last Post: 06-02-2009, 02:14 AM
  2. struct stat st_blocks and st_blksize
    By insomnis in forum C++ Programming
    Replies: 1
    Last Post: 12-27-2006, 03:16 AM
  3. Search Engine - Binary Search Tree
    By Gecko2099 in forum C Programming
    Replies: 9
    Last Post: 04-17-2005, 02:56 PM
  4. Request for comments
    By Prelude in forum A Brief History of Cprogramming.com
    Replies: 15
    Last Post: 01-02-2004, 10:33 AM
  5. Bi-Directional Linked Lists
    By Thantos in forum C Programming
    Replies: 6
    Last Post: 12-11-2003, 10:24 AM

Tags for this Thread