|
|
1.1 ! root 1: .TH FIO 3 ! 2: .CT 2 file_io ! 3: .SH NAME ! 4: Finit, Frdline, Fgetc, Fread, Fseek, Fundo, ! 5: Fputc, Fprint, Fwrite, Fflush, Ftie, Fclose, Fexit \(mi fast buffered input/output ! 6: .SH SYNOPSIS ! 7: .nf ! 8: .2C ! 9: .B #include <fio.h> ! 10: .PP ! 11: .B void Finit(fd, buf) ! 12: .B char *buf; ! 13: .PP ! 14: .B int Fclose(fd); ! 15: .PP ! 16: .B int Fprint(fildes, format [, arg ...]) ! 17: .B int fildes; ! 18: .B char \(**format; ! 19: .PP ! 20: .B char *Frdline(fd) ! 21: .PP ! 22: .B int FIOLINELEN(fd) ! 23: .PP ! 24: .B long FIOSEEK(fd) ! 25: .PP ! 26: .B int Fgetc(fd) ! 27: .PP ! 28: .B void Fundo(fd) ! 29: .PP ! 30: .B long Fseek(fd, offset, ptr) ! 31: .B long offset; ! 32: .PP ! 33: .B int Fputc(fd, c) ! 34: .PP ! 35: .B long Fread(fd, addr, nbytes) ! 36: .B char *addr; ! 37: .B long nbytes; ! 38: .PP ! 39: .B long Fwrite(fd, addr, nbytes) ! 40: .B char *addr; ! 41: .B long nbytes; ! 42: .PP ! 43: .B int Fflush(fd) ! 44: .PP ! 45: .B void Ftie(ifd, ofd) ! 46: .PP ! 47: .B Fexit(type) ! 48: .1C ! 49: .fi ! 50: .SH DESCRIPTION ! 51: These routines provide buffered I/O, faster than, and incompatible ! 52: with ! 53: .IR stdio (3). ! 54: The routines can be called in any order. ! 55: I/O on different file descriptors is independent. ! 56: .PP ! 57: .I Finit ! 58: initializes a buffer (whose type is ! 59: .IR Fbuffer ) ! 60: associated with the file descriptor ! 61: .IR fd . ! 62: Any buffered input associated with ! 63: .I fd ! 64: will be lost. ! 65: The buffer can be supplied by the user ! 66: (it should be at least ! 67: .B sizeof(Fbuffer) ! 68: bytes) ! 69: or if ! 70: .I buf ! 71: is ! 72: .BR "(char *)0" , ! 73: .I Finit ! 74: will use ! 75: .IR malloc (3). ! 76: .IR Finit ! 77: must be called after a stretch of ! 78: .IR non- fio ! 79: activity, such as ! 80: .IR close ! 81: or ! 82: .IR lseek (2), ! 83: between ! 84: .I fio ! 85: calls on the same file descriptor number; ! 86: it is unnecessary, but harmless, before the first ! 87: .I fio ! 88: activity on a given file descriptor number. ! 89: .PP ! 90: .I Fclose ! 91: flushes the buffer for ! 92: .IR fd , ! 93: .IR free s ! 94: the buffer if it was allocated by ! 95: .IR Finit , ! 96: and then closes ! 97: .IR fd . ! 98: .PP ! 99: .I Frdline ! 100: reads a line from the file associated with the file descriptor ! 101: .IR fd . ! 102: The newline at the end of the line is replaced by a 0 ! 103: byte. ! 104: .I Frdline ! 105: returns a pointer to the start of the line or ! 106: .L (char *)0 ! 107: on end of file or read error. ! 108: The macro ! 109: .I FIOLINELEN ! 110: returns the length (not including the 0 ! 111: byte) of the most recent line returned by ! 112: .IR Frdline . ! 113: The value is undefined after a call to any other ! 114: .I fio ! 115: routine. ! 116: .PP ! 117: .I Fgetc ! 118: returns the next character from the file descriptor ! 119: .IR fd , ! 120: or a negative value ! 121: at end of file. ! 122: .PP ! 123: .I Fread ! 124: reads ! 125: .I nbytes ! 126: of data from the file descriptor ! 127: .I fd ! 128: into memory starting at ! 129: .IR addr . ! 130: The number of bytes read is returned on success ! 131: and a negative value is returned if a read error occurred. ! 132: .PP ! 133: .I Fseek ! 134: applies ! 135: .IR lseek (2) ! 136: to ! 137: .I fd ! 138: taking buffering into account. ! 139: It returns the new file offset. ! 140: The macro ! 141: .I FIOSEEK ! 142: returns the file offset of the next character to be processed. ! 143: .PP ! 144: .I Fundo ! 145: makes the characters returned by the last call to ! 146: .I Frdline ! 147: or ! 148: .I Fgetc ! 149: available for reading again. ! 150: There is only one level of undo. ! 151: .PP ! 152: .I Fputc ! 153: outputs the low order 8 bits of ! 154: .I c ! 155: on the file associated with file descriptor ! 156: .IR fd . ! 157: If this causes a ! 158: .IR write ! 159: (see ! 160: .IR read (2)) ! 161: to occur and there is an error, ! 162: a negative value is returned. ! 163: Otherwise, zero is returned. ! 164: .PP ! 165: .I Fprint ! 166: is a buffered interface to ! 167: .IR print (3). ! 168: If this causes a ! 169: .IR write ! 170: to occur and there is an error, ! 171: a negative value is returned. ! 172: Otherwise, the number of chars output is returned. ! 173: .PP ! 174: .I Fwrite ! 175: outputs ! 176: .I nbytes ! 177: bytes of data starting at ! 178: .I addr ! 179: to the file associated with file descriptor ! 180: .IR fd . ! 181: If this causes a ! 182: .IR write ! 183: to occur and there is an error, ! 184: a negative value is returned. ! 185: Otherwise, the number of bytes written is returned. ! 186: .PP ! 187: .I Fflush ! 188: causes any buffered output associated with ! 189: .I fd ! 190: to be written; ! 191: it must precede a call of ! 192: .I close ! 193: on ! 194: .IR fd. ! 195: The return is as for ! 196: .IR Fputc . ! 197: .PP ! 198: .I Ftie ! 199: links together two file descriptors such that any ! 200: .IR fio -initiated ! 201: .IR read (2) ! 202: on ! 203: .I ifd ! 204: causes a ! 205: .I Fflush ! 206: of ! 207: .I ofd ! 208: (if it has been initialized). ! 209: It is appropriate for most programs used as filters to do ! 210: .BR Ftie(0,1) . ! 211: The tie may be broken by ! 212: .BR "Ftie(ifd, -1)" . ! 213: .PP ! 214: .I Fexit ! 215: is used to clean up all ! 216: .I fio ! 217: buffers. ! 218: If ! 219: .I type ! 220: is zero, the buffers are ! 221: .IR Fflush ed, ! 222: otherwise they are ! 223: .IR Fclose d. ! 224: .B "Fexit(0)" ! 225: is automatically called at ! 226: .IR exit (3). ! 227: .SH SEE ALSO ! 228: .IR open (2), ! 229: .IR print (3), ! 230: .IR stdio (3) ! 231: .SH DIAGNOSTICS ! 232: .I Fio ! 233: routines that return integers yield ! 234: .B -1 ! 235: if ! 236: .I fd ! 237: is not the descriptor of an open file or if the operation ! 238: is inapplicable to ! 239: .I fd. ! 240: .SH BUGS ! 241: .I Frdline ! 242: deletes characters from lines longer than 4095 characters, ! 243: ignores characters after the last newline in a file, ! 244: and will read past and end-of-file indication on a stream. ! 245: .br ! 246: The data returned by ! 247: .I Frdline ! 248: may be overwritten by calls to any other ! 249: .I fio ! 250: routine. ! 251: .br ! 252: .I Fgetc ! 253: is much slower than ! 254: access through a pointer returned by ! 255: .I Frdline. ! 256: .br ! 257: There is no ! 258: .IR scanf (3) ! 259: analogue.
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.