Документ взят из кэша поисковой машины. Адрес оригинального документа : http://www.sao.ru/hq/sts/linux/book/c_marshall/subsection2_18_3_3.html
Дата изменения: Unknown
Дата индексирования: Sat Sep 11 20:23:37 2010
Кодировка:

Поисковые слова: m 35
errno



Next: Process Control and Management Up: File and Directory Manipulation Previous: File Manipulation Routines

errno

errno is a special system variable that is set if a system call cannot perform its set task.

To use errno in a C program it must be declared via:

extern int errno;

It can be manually reset within a C program other wise it simply retains its last value.

int chmod(char *path, int mode) change the mode of access of a file. specified by path to the given mode.

chmod() returns 0 on success, -1 on failure and sets errno to indicate the error. Errors are defined in #include <sys/stat.h>

The access mode of a file can be set using predefined macros in sys/stat.h - see man pages - or by setting the mode in a a 3 digit octal number.

The rightmost digit specifies owner privileges, middle group privileges and the leftmost other users privileges.

For each octal digit think of it a 3 bit binary number. Leftmost bit = read access (on/off) middle is write, right is executable.

So 4 (octal 100) = read only, 2 (010) = write, 6 (110) = read and write, 1 (001) = execute.

so for access mode 600 gives user read and write access others no access. 666 gives everybody read/write access.

NOTE: a UNIX command chmod also exists

int stat(char *path, struct stat *buf), int fstat(int fd, struct stat *buf)

stat() obtains information about the file named by path. Read, write or execute permission of the named file is not required, but all directories listed in the path name leading to the file must be searchable.

fstat() obtains the same information about an open file referenced by the argument descriptor, such as would be obtained by an open call (Low level I/O).

buf is a pointer to a stat structure into which information is placed concerning the file. A stat structure is define in #include <sys/types.h>, see man pages for more information.

stat(), and fstat() return 0 on success, -1 on failure and sets errno to indicate the error. Errors are again defined in #include <sys/stat.h>

int unlink(char *path) - removes the directory entry named by path

unlink() returns 0 on success, -1 on failure and sets errno to indicate the error. Errors listed in #include <sys/stat.h>

NOTE: There are a few more file manipulation routines (Appendix ).



Next: Process Control and Management Up: File and Directory Manipulation Previous: File Manipulation Routines


Dave.Marshall@cm.cf.ac.uk
Wed Sep 14 10:06:31 BST 1994