/* * This function performs the details of file writing; writing the file * in buffer bp to file fn. Uses the file management routines in the * "fileio.c" package. Most of the grief is checking of some sort. */ int writeout(struct buffer *bp, char *fn) { int s; /* open writes message */ if ((s = ffwopen(fn, bp)) != FIOSUC) return (FALSE); s = ffputbuf(bp); if (s == FIOSUC) { /* no write error */ s = ffclose(bp); if (s == FIOSUC) ewprintf("Wrote %s", fn); } else /* ignore close error if it is a write error */ (void)ffclose(bp); (void)fupdstat(bp); return (s == FIOSUC); }
/* * This function performs the details of file writing; writing the file * in buffer bp to file fn. Uses the file management routines in the * "fileio.c" package. Most of the grief is checking of some sort. * You may want to call fupdstat() after using this function. */ int writeout(FILE ** ffp, struct buffer *bp, char *fn) { int s; /* open writes message */ if ((s = ffwopen(ffp, fn, bp)) != FIOSUC) return (FALSE); s = ffputbuf(*ffp, bp); if (s == FIOSUC) { /* no write error */ s = ffclose(*ffp, bp); if (s == FIOSUC) ewprintf("Wrote %s", fn); } else { /* print a message indicating write error */ (void)ffclose(*ffp, bp); ewprintf("Unable to write %s", fn); } return (s == FIOSUC); }
/* * This function performs the details of file writing; writing the file * in buffer bp to file fn. Uses the file management routines in the * "fileio.c" package. Most of the grief is checking of some sort. * You may want to call fupdstat() after using this function. */ int writeout(FILE ** ffp, struct buffer *bp, char *fn) { struct stat statbuf; int s; char dp[NFILEN]; if (stat(fn, &statbuf) == -1 && errno == ENOENT) { errno = 0; (void)xdirname(dp, fn, sizeof(dp)); (void)strlcat(dp, "/", sizeof(dp)); if (access(dp, W_OK) && errno == EACCES) { dobeep(); ewprintf("Directory %s write-protected", dp); return (FIOERR); } else if (errno == ENOENT) { dobeep(); ewprintf("%s: no such directory", dp); return (FIOERR); } } /* open writes message */ if ((s = ffwopen(ffp, fn, bp)) != FIOSUC) return (FALSE); s = ffputbuf(*ffp, bp); if (s == FIOSUC) { /* no write error */ s = ffclose(*ffp, bp); if (s == FIOSUC) ewprintf("Wrote %s", fn); } else { /* print a message indicating write error */ (void)ffclose(*ffp, bp); dobeep(); ewprintf("Unable to write %s", fn); } return (s == FIOSUC); }