|
|
1.1 ! root 1: .TH OPEN 2 ! 2: .CT 2 file_io ! 3: .SH NAME ! 4: open, creat, close \(mi open a file for reading or writing, create file ! 5: .SH SYNOPSIS ! 6: .nf ! 7: .B int open(file, rwmode) ! 8: .B char *file; ! 9: .PP ! 10: .B int creat(file, mode) ! 11: .B char *file; ! 12: .PP ! 13: .B int close(fildes) ! 14: .fi ! 15: .SH DESCRIPTION ! 16: .I Open ! 17: opens the ! 18: .I file, ! 19: for reading if ! 20: .I rwmode ! 21: is 0, ! 22: for writing if ! 23: .I rwmode ! 24: is 1, ! 25: or for both if ! 26: .I rwmode ! 27: is 2, ! 28: and returns an associated file descriptor. ! 29: .I File ! 30: is a null-terminated string representing ! 31: a path name. ! 32: The file pointer is set to 0. ! 33: .PP ! 34: .I Creat ! 35: creates a new ! 36: .I file ! 37: or prepares to rewrite an existing ! 38: .IR file , ! 39: opens it for writing, ! 40: and returns an associated file descriptor. ! 41: If the file is new, ! 42: the owner is set to the effective userid of the creating process; ! 43: the group to that of the containing directory; ! 44: the mode to ! 45: .IR mode ! 46: as modified by the mode mask of the creating process; see ! 47: .IR umask (2). ! 48: .I Mode ! 49: need not allow writing. ! 50: If the file already exists, ! 51: it is truncated to 0 length; ! 52: the mode, owner, and group remain unchanged, ! 53: and must permit writing. ! 54: .PP ! 55: A program may reserve a filename for exclusive use ! 56: by ! 57: calling ! 58: .I creat ! 59: with a mode that forbids writing. ! 60: If the file does not exist, ! 61: .I creat ! 62: will succeed; ! 63: further attempts to ! 64: .I creat ! 65: the same file will be denied. ! 66: More sophisticated ! 67: (but less portable) ! 68: concurrent access control ! 69: may be obtained by setting the ! 70: .B S_ICCTYP ! 71: field in the mode; ! 72: see ! 73: .IR stat (2). ! 74: .PP ! 75: .I Close ! 76: closes the file associated with a file descriptor. ! 77: Files are closed upon termination of a process, ! 78: but since ! 79: there is a limit on the number of open files per process, ! 80: .I close ! 81: is necessary for programs which deal with many files. ! 82: It is possible to arrange for files to be closed ! 83: by ! 84: .IR exec (2); ! 85: see ! 86: .B FIOCLEX ! 87: in ! 88: .IR ioctl (2). ! 89: .SH "SEE ALSO" ! 90: .IR dup (2), ! 91: .IR pipe (2), ! 92: .IR read (2), ! 93: .IR exec (2), ! 94: .IR ioctl (2), ! 95: .IR stat (2), ! 96: .IR unlink (2) ! 97: .SH DIAGNOSTICS ! 98: .IR "open, creat" : ! 99: .BR EACCES , ! 100: .BR EBUSY , ! 101: .BR ECONC , ! 102: .BR EFAULT , ! 103: .BR EINTR , ! 104: .BR EIO , ! 105: .BR EISDIR , ! 106: .BR ELOOP , ! 107: .BR EMFILE , ! 108: .BR ENFILE , ! 109: .BR ENOENT , ! 110: .BR ENOTDIR , ! 111: .BR EROFS , ! 112: .BR ETXTBSY ! 113: .br ! 114: .IR creat : ! 115: .BR ENOSPC ! 116: .br ! 117: .IR close: ! 118: .B EBADF ! 119: .SH BUGS ! 120: It should be possible to call ! 121: .I open ! 122: without waiting for carrier on communication lines. ! 123: .br ! 124: The group of a newly-created file should ! 125: (once again) ! 126: be the effective groupid of the creating process. ! 127: .br ! 128: The trick of creating a file with an unwritable mode ! 129: fails for the super-user.
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.