In the past two days, I learned how to write a linux shell to understand the command in the original dos. COM is also a shell, which of course requires the access of many library functions in c to determine whether the database has the permission to access documents ).
Linux access function Function Description: checks whether a calling process can perform certain operations on a specified file.
Linux access function usage:
# Include
# Include
Int access (const char * pathname, int mode );
Linux access function parameters:
Pathname: name of the file to be tested.
Mode: operation mode to be tested. The value may be one or more R_ OK (readable ?), W_ OK (writable ?), X_ OK (executable ?) Or F_ OK (the file exists ?) Combination body.
Linux access function return instructions:
0 is returned when execution is successful. -1 is returned for failure, and errno is set to one of the following values
EINVAL: the mode value is invalid.
EACCES: the directory in the file or path name is not accessible.
ELOOP: explains that too many symbolic connections exist in the path name process.
ENAMETOOLONG: the path name is too long.
ENOENT: the directory in the path name does not exist or the symbolic connection is invalid.
ENOTDIR: The component used as a directory in the path name is not a directory.
EROFS: File System read-only
EFAULT: the path name points out of the accessible space.
EIO: Input/Output Error
ENOMEM: insufficient kernel memory
ETXTBSY: write error to program
Linux access function example:
- /* test.c */ /* test.c */
- #include
- #include
- #include
- #include
- int main(int argc, char *argv[])
- {
- if (argc
- #include
- #include
- #include
- #include
- int main(int argc, char *argv[])
- {
- if (argc
This article is from the ChinaUnix blog, If you view the original, click: http://blog.chinaunix.net/u3/93782/showart_1915418.html