lstat in unix

This is a discussion on lstat in unix within the C++ Programming forums, part of the General Programming Boards category; I am trying to get the size of a file in bytes using Lstat() in unix. I am getting this ...

  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 wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,447
    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.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  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, 09: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, 07:44 PM
  4. Unix Sockets
    By prvindia in forum Linux Programming
    Replies: 5
    Last Post: 03-11-2003, 08: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

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21