473,756 Members | 6,661 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

lstat() and stat()

I'm running into an issue.

To my understanding, when lstat() returns -1 (FAILURE) it's because it
hit a broken link?
If that is not the case, then how can i retrieve information on either
a broken link, or even a soft link?
Sep 30 '08 #1
6 7107
On Mon, 29 Sep 2008 19:03:37 -0700 (PDT), onLINES
<do*******@gmai l.comwrote in comp.lang.c:
I'm running into an issue.

To my understanding, when lstat() returns -1 (FAILURE) it's because it
hit a broken link?
If that is not the case, then how can i retrieve information on either
a broken link, or even a soft link?
There are no functions named stat() or lstat() in the C standard
library, they are extensions provided by your compiler and operating
system. That makes them off-topic here.

You need to ask this question in a group that supports your particular
compiler/OS combination. Based on the headers in your post, it is
possible that news:comp.os.ms-windows.program mer.win32 might be a good
choice.

--
Jack Klein
Home: http://JK-Technology.Com
FAQs for
comp.lang.c http://c-faq.com/
comp.lang.c++ http://www.parashift.com/c++-faq-lite/
alt.comp.lang.l earn.c-c++
http://www.club.cc.cmu.edu/~ajo/docs/FAQ-acllc.html
Sep 30 '08 #2
onLINES <dopeli...@gmai l.comwrote:
I'm running into an issue.

To my understanding, when lstat() returns -1 (FAILURE)
it's because it hit a broken link?
If that is not the case, then how can i retrieve
information on either a broken link, or even a soft link?
lstat is not a standard C function. I suggest you take your
question to POSIX or *nix group. I also suggest you RTM and
Google your question before posting.

--
Peter
Sep 30 '08 #3
onLINES wrote, On 30/09/08 03:03:
I'm running into an issue.

To my understanding, when lstat() returns -1 (FAILURE) it's because it
hit a broken link?
If that is not the case, then how can i retrieve information on either
a broken link, or even a soft link?
stat and stat are not part of the C standard. They are, however,
extensions provided on Unix. So I suggest you ask on
comp.unix.progr ammer where there are lots of people who know about Unix
extensions.

It is possible that someone here will provide what looks like a useful
answer, but as the real experts are not here but over in
comp.unix.progr ammer there is a real possibility that any errors on what
they say won't be corrected (or better solutions be pointed out) and
such errors might not show up until you try demonstrating the code to
your boss.
--
Flash Gordon
If spamming me sent it to sm**@spam.cause way.com
If emailing me use my reply-to address
See the comp.lang.c Wiki hosted by me at http://clc-wiki.net/
Sep 30 '08 #4
On 30 Sep 2008 at 2:03, onLINES wrote:
To my understanding, when lstat() returns -1 (FAILURE) it's because it
hit a broken link?
If that is not the case, then how can i retrieve information on either
a broken link, or even a soft link?
You are quite mistaken. lstat() will stat the symlink itself, and not
the file that it refers to. Since it therefore never tries to follow the
link, how could it know it's broken?

If you try to stat() a broken link, stat() will return -1 and set errno
to indicate that there is no such file or directory.

The stat(2) manpage lists all the possible things errno can be set to.

Sep 30 '08 #5
onLINES wrote:
I'm running into an issue.

To my understanding, when lstat() returns -1 (FAILURE) it's because it
hit a broken link?
As per my understanding (of the POSIX manual page of lstat) your
understanding is wrong
If that is not the case, then how can i retrieve information on either
a broken link, or even a soft link?
[OT]
Assuming you mean the lstat from POSIX:
Whether the filename fed to lstat() is a symbolic link is encoded into
st_mode, which will have S_IFLINK set in this case.
stat() will report an error if operating on an orphaned symbolic link, so
first call lstat(), check whether st_mode has S_IFLINK set, then call stat
and check whether it fails with ernno set to ENOENT
[/OT]

Bye, Jojo
Sep 30 '08 #6
Flash Gordon <sm**@spam.caus eway.comwrites:
onLINES wrote, On 30/09/08 03:03:
>I'm running into an issue.
To my understanding, when lstat() returns -1 (FAILURE) it's because
it
hit a broken link?
If that is not the case, then how can i retrieve information on either
a broken link, or even a soft link?

stat and stat are not part of the C standard. They are, however,
extensions provided on Unix. So I suggest you ask on
comp.unix.progr ammer where there are lots of people who know about
Unix extensions.
[...]

But if you ask this question on comp.unix.progr ammer, their first
question for you will be why you didn't read the documentation first.
So read the documentation first.

--
Keith Thompson (The_Other_Keit h) ks***@mib.org <http://www.ghoti.net/~kst>
Nokia
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"
Sep 30 '08 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
9541
by: Steven T. Hatton | last post by:
I found the following two statements in the file linked below: struct stat st; stat(fileName.c_str(), &st); http://websvn.kde.org/branches/work/kdevelop4-parser/main.cpp?rev=420247&view=markup This is from /usr/include/sys/stat.h which I'm pretty sure is what #include <sys/stat.h> is pulling in. I plain and simply do not understand what the above two lines of code do. Can someone please explain?
10
5276
by: David Farning | last post by:
I am new to c and not yet sure of the boundary between c and it's implementations. So please redirect me if this should be asked elsewhere. I am working on a function to determine if a directory exists. The idea comes from a snippet I found in a samba source file. bool dirExist(char *dname) { struct stat *stbuf; //stbuf = (struct stat*)malloc(sizeof(struct stat));
5
3164
by: diadia | last post by:
#include <sys/types.h> #include <sys/stat.h> #include "ctype.h" #include <stdio.h> int estimateLen(struct stat buf, FILE *fp) { size_t _size = buf.st_size / 4;
2
5052
by: Michael Glassford | last post by:
The Python 2.5 News at http://www.python.org/download/releases/2.5/NEWS.txt states that Python 2.5 was changed to "Use Win32 API to implement os.stat/fstat. As a result, subsecond timestamps are reported, the limit on path name lengths is removed, and stat reports WindowsError now (instead of OSError)." Although not mentioned in the Python 2.5 News, apparently there was a similar change on Mac that I'm having some problems with. On the...
6
1368
by: one2001boy | last post by:
Hello, I tried to find the access time of a file using stat() function. but the following C code in windows vc.net 2003 always give the same access time. the same code works correctly in linux gcc. do I miss something? #include <stdio.h> #include <sys/stat.h> int main() {
6
1772
by: Hansen | last post by:
Hi Group, I've made a statistic module for our framework, and have put it in a namespace called stat (which resides in a namespace called dao) My problem is that now the compiler thinks that it is the struct called stat from wchar.h that I'm refering to even though I've written dao::stat::stat_base I have included the stat_base.h header and have checked for using statements, but nothing seems to work.
24
6122
by: Joe Salmeri | last post by:
I just upgraded from Python 2.4.2 to Python 2.5.1 and have found some unexpected behavior that appears to be a bug in the os.stat module. My OS is Windows XP SP2 + all updates. I have several programs that have worked flawlessly on all previous Python versions for years and they are now producing incorrect results in the code that uses os.stat. Searching through the 2.5.1 release notes I found the following:
2
1383
by: Giampaolo Rodola' | last post by:
Hi there. In a code of mine I'd like to use os.lstat whenever possible. My only concern is if it's available on all platforms. It could be safe using always os.lstat instead of: try: os.lstat except AttributeError: os.stat
3
7004
by: Deniz Dogan | last post by:
Hello. I have a question regarding the st_mode field of the "stat" struct in sys/stat.h. I'd like to know how to use the S_IRWXU, S_IRWXG and S_IRWXO flags to mask the mode_t value into human readable form such as 755, 644, etc. Currently I do something similar to this: usr_t = (mod & S_IRWXU); usr_r = (mod & S_IRUSR);
0
9275
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10040
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
9846
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
6534
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5142
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5304
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3806
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3359
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2666
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.