- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- strange problem with "struct stat"
Operating System - HP-UX
1824636
Members
4785
Online
109672
Solutions
Forums
Categories
Company
Local Language
юдл
back
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Forums
Discussions
Discussions
Discussions
Forums
Forums
Discussions
юдл
back
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Blogs
Information
Community
Resources
Community Language
Language
Forums
Blogs
Go to solution
Topic Options
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО02-14-2002 03:44 AM
тАО02-14-2002 03:44 AM
Hi..
I am facing strange problem with stat(...) call, sometime it works - some times it does not.
For following program -
=================== test-stat1.c ============
#include
main()
{
struct stat buf;
int nb;
if((stat("ex.man",buf)) != 0)
{
perror("ex.man");
exit(-1);
}
nb=buf.st_size;
printf("%d\n",nb);
}
========= end test-stat1.c ==============
it works perfectly.
But if i interchange lines 4 & 5 in the program, i.e. as follows - it does not work. That is, it prints value of nb as zero.
=========== test-stat2.c ============
#include
main()
{
int nb;
struct stat buf;
if((stat("ex.man",buf)) != 0)
{
perror("ex.man");
exit(-1);
}
nb=buf.st_size;
printf("%d\n",nb);
}
============= end test-stat2.c ===============
isn't it strange? I just declare int before struct and the program does not work. Morever, if I add some lines in the working program test-stat1.c, it stops working and prints value of nb as zero. i.e. consider expansion of program test-stat1.c
============= test-stat3.c ========
#include
main()
{
struct stat buf;
int nb;
/*
* some program lines added here,
* nothing is related to buf or nb
* .... */
....
.....
.....
.....
if((stat("ex.man",buf)) != 0)
{
perror("ex.man");
exit(-1);
}
nb=buf.st_size;
printf("%d\n",nb);
}
============== end program ==============
Now I get value of nb as zero again!!
One more strange observation is, if I put following line just before nb=buf.st_size; then the program works fine!! the line is -
printf("%s\n",buf);
Please let me know your views...
Am I missing something?
Thanks,
Suhas
I am facing strange problem with stat(...) call, sometime it works - some times it does not.
For following program -
=================== test-stat1.c ============
#include
main()
{
struct stat buf;
int nb;
if((stat("ex.man",buf)) != 0)
{
perror("ex.man");
exit(-1);
}
nb=buf.st_size;
printf("%d\n",nb);
}
========= end test-stat1.c ==============
it works perfectly.
But if i interchange lines 4 & 5 in the program, i.e. as follows - it does not work. That is, it prints value of nb as zero.
=========== test-stat2.c ============
#include
main()
{
int nb;
struct stat buf;
if((stat("ex.man",buf)) != 0)
{
perror("ex.man");
exit(-1);
}
nb=buf.st_size;
printf("%d\n",nb);
}
============= end test-stat2.c ===============
isn't it strange? I just declare int before struct and the program does not work. Morever, if I add some lines in the working program test-stat1.c, it stops working and prints value of nb as zero. i.e. consider expansion of program test-stat1.c
============= test-stat3.c ========
#include
main()
{
struct stat buf;
int nb;
/*
* some program lines added here,
* nothing is related to buf or nb
* .... */
....
.....
.....
.....
if((stat("ex.man",buf)) != 0)
{
perror("ex.man");
exit(-1);
}
nb=buf.st_size;
printf("%d\n",nb);
}
============== end program ==============
Now I get value of nb as zero again!!
One more strange observation is, if I put following line just before nb=buf.st_size; then the program works fine!! the line is -
printf("%s\n",buf);
Please let me know your views...
Am I missing something?
Thanks,
Suhas
Solved! Go to Solution.
3 REPLIES 3
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО02-14-2002 04:02 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО02-14-2002 08:27 PM
тАО02-14-2002 08:27 PM
Re: strange problem with "struct stat"
And if you're wondering why it mysteriously works 'sometimes', well, thats what happens when there's a corruption of memory (usually by incorrect use of pointers).
Trust me, if you get rid of the compiler warnings, all the ghosts in the machine will be exorcised!
Trust me, if you get rid of the compiler warnings, all the ghosts in the machine will be exorcised!

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО02-14-2002 10:38 PM
тАО02-14-2002 10:38 PM
Re: strange problem with "struct stat"
Thanks Deepak,
It worked!
It's really a problem when you do something wrong and still the program works - but that too sometimes! no way to know that you are doing wrong....
It worked!
It's really a problem when you do something wrong and still the program works - but that too sometimes! no way to know that you are doing wrong....
The opinions expressed above are the personal opinions of the authors, not of Hewlett Packard Enterprise. By using this site, you accept the Terms of Use and Rules of Participation.
Company
Learn About
News and Events
Support
© Copyright 2025 Hewlett Packard Enterprise Development LP