Bring in an errno.9 manual page (based on NetBSD's).
[dragonfly.git] / contrib / nvi2 / ex / ex_file.c
blobfdef2112f118fda3ac4fe689260dcc4cb23e4d95
1 /*-
2 * Copyright (c) 1992, 1993, 1994
3 * The Regents of the University of California. All rights reserved.
4 * Copyright (c) 1992, 1993, 1994, 1995, 1996
5 * Keith Bostic. All rights reserved.
7 * See the LICENSE file for redistribution information.
8 */
10 #include "config.h"
12 #ifndef lint
13 static const char sccsid[] = "$Id: ex_file.c,v 10.14 2001/06/25 15:19:16 skimo Exp $";
14 #endif /* not lint */
16 #include <sys/types.h>
17 #include <sys/queue.h>
18 #include <sys/time.h>
20 #include <bitstring.h>
21 #include <errno.h>
22 #include <limits.h>
23 #include <stdio.h>
24 #include <stdlib.h>
25 #include <string.h>
27 #include "../common/common.h"
30 * ex_file -- :f[ile] [name]
31 * Change the file's name and display the status line.
33 * PUBLIC: int ex_file(SCR *, EXCMD *);
35 int
36 ex_file(SCR *sp, EXCMD *cmdp)
38 char *p;
39 FREF *frp;
40 char *np;
41 size_t nlen;
43 NEEDFILE(sp, cmdp);
45 switch (cmdp->argc) {
46 case 0:
47 break;
48 case 1:
49 frp = sp->frp;
51 /* Make sure can allocate enough space. */
52 INT2CHAR(sp, cmdp->argv[0]->bp, cmdp->argv[0]->len + 1,
53 np, nlen);
54 if ((p = v_strdup(sp, np, nlen - 1)) == NULL)
55 return (1);
57 /* If already have a file name, it becomes the alternate. */
58 if (!F_ISSET(frp, FR_TMPFILE))
59 set_alt_name(sp, frp->name);
61 /* Free the previous name. */
62 free(frp->name);
63 frp->name = p;
66 * The file has a real name, it's no longer a temporary,
67 * clear the temporary file flags.
69 F_CLR(frp, FR_TMPEXIT | FR_TMPFILE);
71 /* Have to force a write if the file exists, next time. */
72 F_SET(frp, FR_NAMECHANGE);
74 /* Notify the screen. */
75 (void)sp->gp->scr_rename(sp, sp->frp->name, 1);
76 break;
77 default:
78 abort();
80 msgq_status(sp, sp->lno, MSTAT_SHOWLAST);
81 return (0);