Thread: lstat in unix

  1. #1
    Registered User
    Join Date
    Mar 2006
    Posts
    12

    lstat in unix

    I am trying to get the size of a file in bytes using Lstat() in unix. I am getting this error when i try to print out the value "stat.st_size" which should be where the size in bytes is stored right?
    The name of the file is take in as a command line argument.

    Error:
    Code:
    workdamnit.cpp:67: error: request for member `st_size' in `stat', which is 
    of non-class type `int ()(const char*, stat*)'
    Code:
    file.open(argv[1]);
    status = lstat(argv[1], &buffer);
    cout<<"the size is"<< stat.st_size<<endl;
    Is this more of that crazy pointer stuff? Am I required to use them here?

  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
    1. The thing you read the file status into is called buffer, not stat
    So perhaps buffer.st_size ?

    2. There is also a function called stat, which is the symbol you're really trying to use at the moment, and the cause of the function-like error message.
    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
    Mar 2006
    Posts
    12
    I got it to work. Thank you.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. How to program in unix
    By Cpro in forum Linux Programming
    Replies: 21
    Last Post: 02-12-2008, 10:54 AM
  2. Setting up a Unix box
    By @nthony in forum Tech Board
    Replies: 6
    Last Post: 07-22-2007, 10:22 PM
  3. UNIX (Linux, BSD, etc) Programming :: UNIX
    By kuphryn in forum Linux Programming
    Replies: 6
    Last Post: 04-01-2004, 08:44 PM
  4. Unix Sockets
    By prvindia in forum Linux Programming
    Replies: 5
    Last Post: 03-11-2003, 09:16 AM
  5. About Unix Programming - Making a career desision
    By null in forum C Programming
    Replies: 0
    Last Post: 10-14-2001, 07:37 AM