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.
12 #include <sys/types.h>
13 #include <sys/queue.h>
16 #include <bitstring.h>
25 #include "../common/common.h"
26 #include "pathnames.h"
29 * ex_mkexrc -- :mkexrc[!] [file]
31 * Create (or overwrite) a .exrc file with the current info.
33 * PUBLIC: int ex_mkexrc(SCR *, EXCMD *);
36 ex_mkexrc(SCR *sp, EXCMD *cmdp)
49 INT2CHAR(sp, cmdp->argv[0]->bp, cmdp->argv[0]->len + 1,
51 set_alt_name(sp, fname);
57 if (!FL_ISSET(cmdp->iflags, E_C_FORCE) && !stat(fname, &sb)) {
58 msgq_str(sp, M_ERR, fname,
59 "137|%s exists, not written; use ! to override");
63 /* Create with max permissions of rw-r--r--. */
64 if ((fd = open(fname, O_CREAT | O_TRUNC | O_WRONLY,
65 S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH)) < 0) {
66 msgq_str(sp, M_SYSERR, fname, "%s");
70 if ((fp = fdopen(fd, "w")) == NULL) {
76 if (seq_save(sp, fp, "abbreviate ", SEQ_ABBREV) || ferror(fp))
78 if (seq_save(sp, fp, "map ", SEQ_COMMAND) || ferror(fp))
80 if (seq_save(sp, fp, "map! ", SEQ_INPUT) || ferror(fp))
82 if (opts_save(sp, fp) || ferror(fp))
89 msgq_str(sp, M_INFO, fname, "138|New exrc file: %s");
95 msgq_str(sp, M_SYSERR, fname, "%s");