1 /* $NetBSD: ex_mkexrc.c,v 1.2 2013/11/22 15:52:05 christos Exp $ */
3 * Copyright (c) 1992, 1993, 1994
4 * The Regents of the University of California. All rights reserved.
5 * Copyright (c) 1992, 1993, 1994, 1995, 1996
6 * Keith Bostic. All rights reserved.
8 * See the LICENSE file for redistribution information.
14 static const char sccsid
[] = "Id: ex_mkexrc.c,v 10.13 2001/06/25 15:19:17 skimo Exp (Berkeley) Date: 2001/06/25 15:19:17 ";
17 #include <sys/types.h>
18 #include <sys/queue.h>
21 #include <bitstring.h>
30 #include "../common/common.h"
31 #include "pathnames.h"
34 * ex_mkexrc -- :mkexrc[!] [file]
36 * Create (or overwrite) a .exrc file with the current info.
38 * PUBLIC: int ex_mkexrc __P((SCR *, EXCMD *));
41 ex_mkexrc(SCR
*sp
, EXCMD
*cmdp
)
52 INT2CHAR(sp
, cmdp
->argv
[0]->bp
, cmdp
->argv
[0]->len
+ 1,
54 set_alt_name(sp
, fname
);
60 if (!FL_ISSET(cmdp
->iflags
, E_C_FORCE
) && !stat(fname
, &sb
)) {
61 msgq_str(sp
, M_ERR
, fname
,
62 "137|%s exists, not written; use ! to override");
66 /* Create with max permissions of rw-r--r--. */
67 if ((fd
= open(fname
, O_CREAT
| O_TRUNC
| O_WRONLY
,
68 S_IRUSR
| S_IWUSR
| S_IRGRP
| S_IROTH
)) < 0) {
69 msgq_str(sp
, M_SYSERR
, fname
, "%s");
73 if ((fp
= fdopen(fd
, "w")) == NULL
) {
79 if (seq_save(sp
, fp
, "abbreviate ", SEQ_ABBREV
) || ferror(fp
))
81 if (seq_save(sp
, fp
, "map ", SEQ_COMMAND
) || ferror(fp
))
83 if (seq_save(sp
, fp
, "map! ", SEQ_INPUT
) || ferror(fp
))
85 if (opts_save(sp
, fp
) || ferror(fp
))
92 msgq_str(sp
, M_INFO
, fname
, "138|New exrc file: %s");
98 msgq_str(sp
, M_SYSERR
, fname
, "%s");