summaryrefslogtreecommitdiff
path: root/usr.bin/mg/fileio.c
diff options
context:
space:
mode:
authorlum <lum@cvs.openbsd.org>2012-05-25 04:56:59 +0000
committerlum <lum@cvs.openbsd.org>2012-05-25 04:56:59 +0000
commit8ecc578aab55dc7c3cf258dd3e511048fd7cddab (patch)
tree6a1080875817be80fe02e750e3601c784f3e9772 /usr.bin/mg/fileio.c
parent0de601c280f7774e627bbabcfdf5bcdd1787959c (diff)
Remove static FILE pointer used for handling files in fileio.c. Pass
by reference instead. This allows the mg startup file to open other files without unexpected things happening. Discussed with Sunil Nimmagadda.
Diffstat (limited to 'usr.bin/mg/fileio.c')
-rw-r--r--usr.bin/mg/fileio.c28
1 files changed, 14 insertions, 14 deletions
diff --git a/usr.bin/mg/fileio.c b/usr.bin/mg/fileio.c
index 3833bc614f1..3c8b0c96f96 100644
--- a/usr.bin/mg/fileio.c
+++ b/usr.bin/mg/fileio.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: fileio.c,v 1.88 2012/05/23 05:29:22 lum Exp $ */
+/* $OpenBSD: fileio.c,v 1.89 2012/05/25 04:56:58 lum Exp $ */
/* This file is in the public domain. */
@@ -22,15 +22,13 @@
#include "kbd.h"
-static FILE *ffp;
-
/*
* Open a file for reading.
*/
int
-ffropen(const char *fn, struct buffer *bp)
+ffropen(FILE ** ffp, const char *fn, struct buffer *bp)
{
- if ((ffp = fopen(fn, "r")) == NULL) {
+ if ((*ffp = fopen(fn, "r")) == NULL) {
if (errno == ENOENT)
return (FIOFNF);
return (FIOERR);
@@ -40,7 +38,7 @@ ffropen(const char *fn, struct buffer *bp)
if (fisdir(fn) == TRUE)
return (FIODIR);
- ffstat(bp);
+ ffstat(*ffp, bp);
return (FIOSUC);
}
@@ -49,7 +47,7 @@ ffropen(const char *fn, struct buffer *bp)
* Update stat/dirty info
*/
void
-ffstat(struct buffer *bp)
+ffstat(FILE *ffp, struct buffer *bp)
{
struct stat sb;
@@ -71,13 +69,15 @@ ffstat(struct buffer *bp)
int
fupdstat(struct buffer *bp)
{
+ FILE *ffp;
+
if ((ffp = fopen(bp->b_fname, "r")) == NULL) {
if (errno == ENOENT)
return (FIOFNF);
return (FIOERR);
}
- ffstat(bp);
- (void)ffclose(bp);
+ ffstat(ffp, bp);
+ (void)ffclose(ffp, bp);
return (FIOSUC);
}
@@ -85,7 +85,7 @@ fupdstat(struct buffer *bp)
* Open a file for writing.
*/
int
-ffwopen(const char *fn, struct buffer *bp)
+ffwopen(FILE ** ffp, const char *fn, struct buffer *bp)
{
int fd;
mode_t fmode = DEFFILEMODE;
@@ -100,7 +100,7 @@ ffwopen(const char *fn, struct buffer *bp)
return (FIOERR);
}
- if ((ffp = fdopen(fd, "w")) == NULL) {
+ if ((*ffp = fdopen(fd, "w")) == NULL) {
ewprintf("Cannot open file for writing : %s", strerror(errno));
close(fd);
return (FIOERR);
@@ -125,7 +125,7 @@ ffwopen(const char *fn, struct buffer *bp)
*/
/* ARGSUSED */
int
-ffclose(struct buffer *bp)
+ffclose(FILE *ffp, struct buffer *bp)
{
if (fclose(ffp) == 0)
return (FIOSUC);
@@ -137,7 +137,7 @@ ffclose(struct buffer *bp)
* buffer. Return the status.
*/
int
-ffputbuf(struct buffer *bp)
+ffputbuf(FILE *ffp, struct buffer *bp)
{
struct line *lp, *lpend;
@@ -170,7 +170,7 @@ ffputbuf(struct buffer *bp)
* If the line length exceeds nbuf, FIOLONG is returned.
*/
int
-ffgetline(char *buf, int nbuf, int *nbytes)
+ffgetline(FILE *ffp, char *buf, int nbuf, int *nbytes)
{
int c, i;