LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 06-24-2005, 08:33 AM   #1
MDBlueIce
Member
 
Registered: Aug 2004
Distribution: Suse Linux 9.1
Posts: 47

Rep: Reputation: 15
*NIX systems programming: error using stat function


Can someone who is familiar with the


int stat(const char *restrict path, struct stat *restrict buf)


function in C tell me why the following code does not output "succesful"?


int main()
{


struct stat * buf;
if (lstat("/bin/ls", buf)==0)
printf("succesful\n");



}

Thankyou.
 
Old 06-24-2005, 08:51 AM   #2
MoneyCat
LQ Newbie
 
Registered: Jun 2005
Location: USA
Distribution: Ubuntu 5.04
Posts: 10

Rep: Reputation: 0
Code:
      1 #include <sys/stat.h>
      2
      3 int main()
      4 {
      5     struct stat buf;
      6
      7     if (lstat("/bin/ls", &buf)==0)
      8         printf("succesful\n");
      9
     10     return 0;
     11
     12 }

The only change from your code is that you were passing an incorrect parameter to lstat.


Good Luck

Last edited by MoneyCat; 06-24-2005 at 08:55 AM.
 
Old 06-24-2005, 09:09 AM   #3
MDBlueIce
Member
 
Registered: Aug 2004
Distribution: Suse Linux 9.1
Posts: 47

Original Poster
Rep: Reputation: 15
Your code gives me the following compilation error on line 5:

error: storage size of 'buf' isn't known

Were you able to compile it yourself?
 
Old 06-24-2005, 09:15 AM   #4
MoneyCat
LQ Newbie
 
Registered: Jun 2005
Location: USA
Distribution: Ubuntu 5.04
Posts: 10

Rep: Reputation: 0
Quote:
Were you able to compile it yourself?
Yes, it compiled & gave a 'successful' output on:

1) Ubuntu 5.04 -- gcc v3.3.5
2) IRIX64 Neptune -- gcc v2.95.3
3) IRIX64 Neptune -- MIPSPro v7.4

That errors seems to indicate that the compiler was unable to find struct stat in the sys/stat.h header file.

Last edited by MoneyCat; 06-24-2005 at 10:48 AM.
 
Old 06-24-2005, 10:34 AM   #5
MDBlueIce
Member
 
Registered: Aug 2004
Distribution: Suse Linux 9.1
Posts: 47

Original Poster
Rep: Reputation: 15
Well. I'm compiling it on cygwin in the office. Perhaps when I go home I will try it on a true *NIX installation, Slackware. Thanks for the help though.
 
Old 06-24-2005, 10:51 AM   #6
MoneyCat
LQ Newbie
 
Registered: Jun 2005
Location: USA
Distribution: Ubuntu 5.04
Posts: 10

Rep: Reputation: 0
Quote:
Well. I'm compiling it on cygwin in the office.

Well, your thread does say "*NIX systems programming..."
 
Old 06-24-2005, 10:59 AM   #7
itsme86
Senior Member
 
Registered: Jan 2004
Location: Oregon, USA
Distribution: Slackware
Posts: 1,246

Rep: Reputation: 59
According to man stat you should be #include'ing all these:

#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>

That could very likely be your problem.
 
Old 06-27-2005, 06:42 AM   #8
MDBlueIce
Member
 
Registered: Aug 2004
Distribution: Suse Linux 9.1
Posts: 47

Original Poster
Rep: Reputation: 15
Yes, you were right. The extra
#include <sys/stat.h>
allowed my coed to compile. Thankyou.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[c] unix systems programming in MS VS C++? saiz66 Programming 2 10-07-2004 08:16 AM
Write own stat() function... indian Programming 1 09-14-2004 07:06 AM
32gb limit , *nix systems? DiZi Linux - Hardware 2 08-03-2004 03:29 PM
*nix Software for programming SPS with Step7? bligg Linux - Software 0 11-06-2003 09:17 AM
stat function in BASH... PokerFace Programming 1 11-04-2002 11:31 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 10:31 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration