version 1.88, 2012/05/23 05:29:22 |
version 1.89, 2012/05/25 04:56:58 |
|
|
|
|
#include "kbd.h" |
#include "kbd.h" |
|
|
static FILE *ffp; |
|
|
|
/* |
/* |
* Open a file for reading. |
* Open a file for reading. |
*/ |
*/ |
int |
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) |
if (errno == ENOENT) |
return (FIOFNF); |
return (FIOFNF); |
return (FIOERR); |
return (FIOERR); |
|
|
if (fisdir(fn) == TRUE) |
if (fisdir(fn) == TRUE) |
return (FIODIR); |
return (FIODIR); |
|
|
ffstat(bp); |
ffstat(*ffp, bp); |
|
|
return (FIOSUC); |
return (FIOSUC); |
} |
} |
|
|
* Update stat/dirty info |
* Update stat/dirty info |
*/ |
*/ |
void |
void |
ffstat(struct buffer *bp) |
ffstat(FILE *ffp, struct buffer *bp) |
{ |
{ |
struct stat sb; |
struct stat sb; |
|
|
|
|
int |
int |
fupdstat(struct buffer *bp) |
fupdstat(struct buffer *bp) |
{ |
{ |
|
FILE *ffp; |
|
|
if ((ffp = fopen(bp->b_fname, "r")) == NULL) { |
if ((ffp = fopen(bp->b_fname, "r")) == NULL) { |
if (errno == ENOENT) |
if (errno == ENOENT) |
return (FIOFNF); |
return (FIOFNF); |
return (FIOERR); |
return (FIOERR); |
} |
} |
ffstat(bp); |
ffstat(ffp, bp); |
(void)ffclose(bp); |
(void)ffclose(ffp, bp); |
return (FIOSUC); |
return (FIOSUC); |
} |
} |
|
|
|
|
* Open a file for writing. |
* Open a file for writing. |
*/ |
*/ |
int |
int |
ffwopen(const char *fn, struct buffer *bp) |
ffwopen(FILE ** ffp, const char *fn, struct buffer *bp) |
{ |
{ |
int fd; |
int fd; |
mode_t fmode = DEFFILEMODE; |
mode_t fmode = DEFFILEMODE; |
|
|
return (FIOERR); |
return (FIOERR); |
} |
} |
|
|
if ((ffp = fdopen(fd, "w")) == NULL) { |
if ((*ffp = fdopen(fd, "w")) == NULL) { |
ewprintf("Cannot open file for writing : %s", strerror(errno)); |
ewprintf("Cannot open file for writing : %s", strerror(errno)); |
close(fd); |
close(fd); |
return (FIOERR); |
return (FIOERR); |
|
|
*/ |
*/ |
/* ARGSUSED */ |
/* ARGSUSED */ |
int |
int |
ffclose(struct buffer *bp) |
ffclose(FILE *ffp, struct buffer *bp) |
{ |
{ |
if (fclose(ffp) == 0) |
if (fclose(ffp) == 0) |
return (FIOSUC); |
return (FIOSUC); |
|
|
* buffer. Return the status. |
* buffer. Return the status. |
*/ |
*/ |
int |
int |
ffputbuf(struct buffer *bp) |
ffputbuf(FILE *ffp, struct buffer *bp) |
{ |
{ |
struct line *lp, *lpend; |
struct line *lp, *lpend; |
|
|
|
|
* If the line length exceeds nbuf, FIOLONG is returned. |
* If the line length exceeds nbuf, FIOLONG is returned. |
*/ |
*/ |
int |
int |
ffgetline(char *buf, int nbuf, int *nbytes) |
ffgetline(FILE *ffp, char *buf, int nbuf, int *nbytes) |
{ |
{ |
int c, i; |
int c, i; |
|
|