Exemple #1
0
/*
 * This function performs the details of file writing. Uses the file
 * management routines in the "fileio.c" package. The number of lines written
 * is displayed. Sadly, it looks inside a LINE; provide a macro for this. Most
 * of the grief is error checking of some sort.
 */
int writeout(char *fn)
{
  LINE *lp;
  int nline, s;

  if ((s = ffwopen(fn)) != FIOSUC) /* Open writes message */
    return (FALSE);
  mlwrite("[Writing]");		/* tell us were writing */
  lp = lforw(curbp->b_linep);	/* First line */
  nline = 0;			/* Number of lines */
  while (lp != curbp->b_linep)
    {
      if ((s = ffputline(&lp->l_text[0], llength(lp))) != FIOSUC)
	break;
      ++nline;
      lp = lforw(lp);
    }
  if (s == FIOSUC)
    {				/* No write error */
      s = ffclose();
      if (s == FIOSUC)
	{			/* No close error */
	  if (nline != 1)
	    mlwrite("[Wrote %d lines]", nline);
	  else
	    mlwrite("[Wrote 1 line]");
	}
    }
  else				/* ignore close error */
    ffclose();			/* if a write error */
  if (s != FIOSUC)		/* some sort of error */
    return (FALSE);
  return (TRUE);
}
Exemple #2
0
/*
 * 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);
}
Exemple #3
0
/*
 * 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);
}
Exemple #4
0
/*
 * This function performs the details of file
 * writing. Uses the file management routines in the
 * "fileio.c" package. The number of lines written is
 * displayed. Sadly, it looks inside a struct line; provide
 * a macro for this. Most of the grief is error
 * checking of some sort.
 */
int writeout(char *fn)
{
	int s;
	struct line *lp;
	int nline;

#if	CRYPT
	s = resetkey();
	if (s != TRUE)
		return s;
#endif

	if ((s = ffwopen(fn)) != FIOSUC) {	/* Open writes message. */
		return FALSE;
	}
	mlwrite("(Writing...)");	/* tell us were writing */
	lp = lforw(curbp->b_linep);	/* First line.          */
	nline = 0;		/* Number of lines.     */
	while (lp != curbp->b_linep) {
		if ((s = ffputline(&lp->l_text[0], llength(lp))) != FIOSUC)
			break;
		++nline;
		lp = lforw(lp);
	}
	if (s == FIOSUC) {	/* No write error.      */
		s = ffclose();
		if (s == FIOSUC) {	/* No close error.      */
			if (nline == 1)
				mlwrite("(Wrote 1 line)");
			else
				mlwrite("(Wrote %d lines)", nline);
		}
	} else			/* Ignore close error   */
		ffclose();	/* if a write error.    */
	if (s != FIOSUC)	/* Some sort of error.  */
		return FALSE;
	return TRUE;
}
Exemple #5
0
Fichier : file.c Projet : sctb/em
/*
 * 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);
}