Fix UTIME_OMIT handling
[dragonfly.git] / contrib / nvi2 / ex / ex_file.c
blobc06ac6e493a66324e9ff387709e0d133e0e0ea76
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 #include <sys/types.h>
13 #include <sys/queue.h>
14 #include <sys/time.h>
16 #include <bitstring.h>
17 #include <errno.h>
18 #include <limits.h>
19 #include <stdio.h>
20 #include <stdlib.h>
21 #include <string.h>
23 #include "../common/common.h"
26 * ex_file -- :f[ile] [name]
27 * Change the file's name and display the status line.
29 * PUBLIC: int ex_file(SCR *, EXCMD *);
31 int
32 ex_file(SCR *sp, EXCMD *cmdp)
34 char *p;
35 FREF *frp;
36 char *np;
37 size_t nlen;
39 NEEDFILE(sp, cmdp);
41 switch (cmdp->argc) {
42 case 0:
43 break;
44 case 1:
45 frp = sp->frp;
47 /* Make sure can allocate enough space. */
48 INT2CHAR(sp, cmdp->argv[0]->bp, cmdp->argv[0]->len + 1,
49 np, nlen);
50 if ((p = v_strdup(sp, np, nlen - 1)) == NULL)
51 return (1);
53 /* If already have a file name, it becomes the alternate. */
54 if (!F_ISSET(frp, FR_TMPFILE))
55 set_alt_name(sp, frp->name);
57 /* Free the previous name. */
58 free(frp->name);
59 frp->name = p;
62 * The file has a real name, it's no longer a temporary,
63 * clear the temporary file flags.
65 F_CLR(frp, FR_TMPEXIT | FR_TMPFILE);
67 /* Have to force a write if the file exists, next time. */
68 F_SET(frp, FR_NAMECHANGE);
70 /* Notify the screen. */
71 (void)sp->gp->scr_rename(sp, sp->frp->name, 1);
72 break;
73 default:
74 abort();
76 msgq_status(sp, sp->lno, MSTAT_SHOWLAST);
77 return (0);