ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
I'll just try to ignore the intended meaning in that. Me and the moderators will probably be happier in the end if I do so.
Anyway, I looked over the whole thing a few times before asking.
Quote:
Originally Posted by Sergei Steshenko
What was the first thing you do not understand ?
Code:
RETURN VALUE
Upon successful completion, 0 shall be returned. Otherwise, -1 shall be returned and
errno set to indicate the error.
ERRORS
The stat() function shall fail if:
EACCES Search permission is denied for a component of the path prefix.
EIO An error occurred while reading from the file system.
ELOOP A loop exists in symbolic links encountered during resolution of the path argu‐
ment.
ENAMETOOLONG
The length of the path argument exceeds {PATH_MAX} or a pathname component is
longer than {NAME_MAX}.
ENOENT A component of path does not name an existing file or path is an empty string.
ENOTDIR
A component of the path prefix is not a directory.
EOVERFLOW
The file size in bytes or the number of blocks allocated to the file or the
file serial number cannot be represented correctly in the structure pointed to
by buf.
The stat() function may fail if:
ELOOP More than {SYMLOOP_MAX} symbolic links were encountered during resolution of
the path argument.
ENAMETOOLONG
As a result of encountering a symbolic link in resolution of the path argument,
the length of the substituted pathname string exceeded {PATH_MAX}.
EOVERFLOW
A value to be stored would overflow one of the members of the stat structure.
The following sections are informative.
OK, which one of these errors mean "the file does not exist"?
ENOENT A component of path does not name an existing file or path is an empty string.
Okey, my english is not very good, but I can understand that if "the path does not name an existing file" means that the file does not exist what the string path points to.
I'll just try to ignore the intended meaning in that. Me and the moderators will probably be happier in the end if I do so.
Anyway, I looked over the whole thing a few times before asking.
Code:
RETURN VALUE
Upon successful completion, 0 shall be returned. Otherwise, -1 shall be returned and
errno set to indicate the error.
ERRORS
The stat() function shall fail if:
EACCES Search permission is denied for a component of the path prefix.
EIO An error occurred while reading from the file system.
ELOOP A loop exists in symbolic links encountered during resolution of the path argu‐
ment.
ENAMETOOLONG
The length of the path argument exceeds {PATH_MAX} or a pathname component is
longer than {NAME_MAX}.
ENOENT A component of path does not name an existing file or path is an empty string.
ENOTDIR
A component of the path prefix is not a directory.
EOVERFLOW
The file size in bytes or the number of blocks allocated to the file or the
file serial number cannot be represented correctly in the structure pointed to
by buf.
The stat() function may fail if:
ELOOP More than {SYMLOOP_MAX} symbolic links were encountered during resolution of
the path argument.
ENAMETOOLONG
As a result of encountering a symbolic link in resolution of the path argument,
the length of the substituted pathname string exceeded {PATH_MAX}.
EOVERFLOW
A value to be stored would overflow one of the members of the stat structure.
The following sections are informative.
OK, which one of these errors mean "the file does not exist"?
First of all, is this all you read ? Because I know for sure that had you read the whole manpage and had you followed some other references in the manpage, you would have found an easy answer to your "OK, which one of these errors mean "the file does not exist"?" question.
You did not read the manpage.
Back to your question - in my case I have the following explanation:
Code:
ENOENT A component of the path path does not exist, or the path is an empty string.
.
So, can you parse that statement - saying "parse" I mean human parsing of English ?
ENOENT A component of path does not name an existing file or path is an empty string.
Okey, my english is not very good, but I can understand that if "the path does not name an existing file" means that the file does not exist what the string path points to.
Am I right?
Don't worry, I've seen too many non-native English speakers who understand English much better than the native ones - probably because the non-native speakers were taught English systematically, were required to parse English sentences, were required to ask question about every sentence member, were required to tell stories they were supposed to read in their own words, etc.
By the way, MTK358, just in case you are still having difficulty parsing the English statement, and in case you have difficulties using WEB search, here is the 5-th match from Google: http://everything2.com/title/ENOENT .
I am not a native English speaker, but I think the acronym means "Error NO ENTity". And if you ever visit the second page of Google hits - http://aplawrence.com/Unixart/errors.html .
I guess you could say I read it but did not parse it.
I have already told: read, comprehend, analyze. If you are having difficulties with it, take an English class at a community college.
Now, at the very bottom of the manpage it is written:
Code:
SEE ALSO
access(2)
.
So, you had to also see
Code:
man 2 access
.
And, trust me, the "see also" manpage contains very simple ways to find answers to your questions.
As I have already said, you didn't read the manual.
And since you've mentioned moderators, I think they should always close such threads of yours because you do no read the manuals and do not understand English.
Since I am not sure you will read 'man 2 access', here are the relevant lines from it:
Code:
13 DESCRIPTION
14 access() checks whether the calling process can access the file pathname. If pathname is a symbolic link, it is dereferenced.
15
16 The mode specifies the accessibility check(s) to be performed, and is either the value F_OK, or a mask consisting of the bitwise OR of one or more of R_OK, W_OK,
17 and X_OK. F_OK tests for the existence of the file. R_OK, W_OK, and X_OK test whether the file exists and grants read, write, and execute permissions, respec-
18 tively.
Anyway, I looked over the whole thing a few times before asking.
I don't want to sound disrespectful but as the other people said, it doesn't
seem you read the manpage. It has a lot of information and even includes
a example c program showing how stat works.
Quote:
int stat(const char *path, struct stat *buf);
DESCRIPTION
stat() stats the file pointed to by path and fills in buf.
All of these system calls return a stat structure
The following POSIX macros are defined to check the file type using the
st_mode field:
S_ISDIR(m) directory?
The following flags are defined for the st_mode field:
S_IRUSR 00400 owner has read permission
S_IWUSR 00200 owner has write permission
S_IXUSR 00100 owner has execute permission
S_IRGRP 00040 group has read permission
S_IWGRP 00020 group has write permission
S_IXGRP 00010 group has execute permission
S_IROTH 00004 others have read permission
S_IWOTH 00002 others have write permission
S_IXOTH 00001 others have execute permission
RETURN VALUE
On success, zero is returned. On error, -1 is returned, and errno is
set appropriately.
ERRORS
EACCES Search permission is denied for one of the directories in the
path prefix of path. (See also path_resolution(7).)
ENOENT A component of path does not exist, or path is an empty string.
I think this part of the manpage explains all your questions.
Using access() to check if a user is authorized
to e.g. open a file before actually
doing so using open(2) creates a security
hole, because the user might exploit the
short time interval between checking and opening
the file to manipulate it.
my man page:
Code:
The access() system call is a potential
security hole due to race conditions and
should never be used.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.