2 * The routines in this file read and write ASCII files from the disk. All of
3 * the knowledge about files are here. A better message writing scheme should
9 FILE *ffp
; /* File pointer, all functions. */
12 * Open a file for reading.
17 if ((ffp
=fopen(fn
, "r")) == NULL
)
23 * Open a file for writing. Return TRUE if all is well, and FALSE on error
32 if ((fd
=creat(fn
, 0666, "rfm=var", "rat=cr")) < 0
33 || (ffp
=fdopen(fd
, "w")) == NULL
) {
35 if ((ffp
=fopen(fn
, "w")) == NULL
) {
37 mlwrite("Cannot open file for writing");
44 * Close a file. Should look at the status in all systems.
49 if (fclose(ffp
) != FALSE
) {
50 mlwrite("Error closing file");
60 * Write a line to the already opened file. The "buf" points to the buffer,
61 * and the "nbuf" is its length, less the free newline. Return the status.
62 * Check only at the newline.
64 int ffputline(buf
, nbuf
)
70 for (i
= 0; i
< nbuf
; ++i
)
71 fputc(buf
[i
]&0xFF, ffp
);
76 mlwrite("Write I/O error");
84 * Read a line from a file, and store the bytes in the supplied buffer. The
85 * "nbuf" is the length of the buffer. Complain about long lines and lines
86 * at the end of the file that don't have a newline present. Check for I/O
87 * errors too. Return status.
89 int ffgetline(buf
, nbuf
)
98 while ((c
= fgetc(ffp
)) != EOF
&& c
!= '\n') {
100 mlwrite("File has long line");
108 mlwrite("File read error");
113 mlwrite("File has funny line at EOF");