|
|
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 void 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 int 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: Lines longer than 4096 characters will have characters deleted. ! 105: .I Frdline ! 106: returns a pointer to the start of the line or ! 107: .L (char *)0 ! 108: on end of file or read error. ! 109: The macro ! 110: .I FIOLINELEN ! 111: returns the length (not including the 0 ! 112: byte) of the most recent line returned by ! 113: .IR Frdline . ! 114: The value is undefined after a call to any other ! 115: .I fio ! 116: routine. ! 117: .PP ! 118: .I Fgetc ! 119: returns the next character from the file descriptor ! 120: .IR fd , ! 121: or a negative value ! 122: at end of file. ! 123: .PP ! 124: .I Fread ! 125: reads ! 126: .I nbytes ! 127: of data from the file descriptor ! 128: .I fd ! 129: into memory starting at ! 130: .IR addr . ! 131: The number of bytes read is returned on success ! 132: and a negative value is returned if a read error occurred. ! 133: .PP ! 134: .I Fseek ! 135: applies ! 136: .IR lseek (2) ! 137: to ! 138: .I fd ! 139: taking buffering into account. ! 140: It returns the new file offset. ! 141: The macro ! 142: .I FIOSEEK ! 143: returns the file offset of the next character to be processed. ! 144: .PP ! 145: .I Fundo ! 146: makes the characters returned by the last call to ! 147: .I Frdline ! 148: or ! 149: .I Fgetc ! 150: available for reading again. ! 151: There is only one level of undo. ! 152: .PP ! 153: .I Fputc ! 154: outputs the low order 8 bits of ! 155: .I c ! 156: on the file associated with file descriptor ! 157: .IR fd . ! 158: If this causes a ! 159: .IR write ! 160: (see ! 161: .IR read (2)) ! 162: to occur and there is an error, ! 163: a negative value is returned. ! 164: Otherwise, zero is returned. ! 165: .PP ! 166: .I Fprint ! 167: is a buffered interface to ! 168: .IR print (3). ! 169: If this causes a ! 170: .IR write ! 171: to occur and there is an error, ! 172: a negative value is returned. ! 173: Otherwise, the number of chars output is returned. ! 174: .PP ! 175: .I Fwrite ! 176: outputs ! 177: .I nbytes ! 178: bytes of data starting at ! 179: .I addr ! 180: to the file associated with file descriptor ! 181: .IR fd . ! 182: If this causes a ! 183: .IR write ! 184: to occur and there is an error, ! 185: a negative value is returned. ! 186: Otherwise, the number of bytes written is returned. ! 187: .PP ! 188: .I Fflush ! 189: causes any buffered output associated with ! 190: .I fd ! 191: to be written; ! 192: it must precede a call of ! 193: .I close ! 194: on ! 195: .IR fd. ! 196: The return is as for ! 197: .IR Fputc . ! 198: .PP ! 199: .I Ftie ! 200: links together two file descriptors such that any ! 201: .IR fio -initiated ! 202: .IR read (2) ! 203: on ! 204: .I ifd ! 205: causes a ! 206: .I Fflush ! 207: of ! 208: .I ofd ! 209: (if it has been initialized). ! 210: It is appropriate for most programs used as filters to do ! 211: .BR Ftie(0,1) . ! 212: The tie may be broken by ! 213: .BR "Ftie(ifd, -1)" . ! 214: .PP ! 215: .I Fexit ! 216: is used to clean up all ! 217: .I fio ! 218: buffers. ! 219: If ! 220: .I type ! 221: is zero, the buffers are ! 222: .IR Fflush ed, ! 223: otherwise they are ! 224: .IR Fclose d. ! 225: .B "Fexit(0)" ! 226: is automatically called at ! 227: .IR exit (3). ! 228: .SH SEE ALSO ! 229: .IR open (2), ! 230: .IR print (3), ! 231: .IR stdio (3) ! 232: .SH DIAGNOSTICS ! 233: .I Fio ! 234: routines that return integers yield ! 235: .B -1 ! 236: if ! 237: .I fd ! 238: is not the descriptor of an open file or if the operation ! 239: is inapplicable to ! 240: .I fd. ! 241: .SH BUGS ! 242: The data returned by ! 243: .I Frdline ! 244: may be overwritten by calls to any other ! 245: .I fio ! 246: routine. ! 247: .br ! 248: .I Fgetc ! 249: is much slower than ! 250: access through a pointer returned by ! 251: .I Frdline. ! 252: .br ! 253: There is no ! 254: .IR scanf (3) ! 255: analogue.
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.