1 /* $NetBSD: ex_mkexrc.c,v 1.4 2014/11/27 20:00:09 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.
13 #include <sys/cdefs.h>
16 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 ";
19 __RCSID("$NetBSD: ex_mkexrc.c,v 1.4 2014/11/27 20:00:09 christos Exp $");
22 #include <sys/types.h>
23 #include <sys/queue.h>
26 #include <bitstring.h>
35 #include "../common/common.h"
36 #include "pathnames.h"
39 * ex_mkexrc -- :mkexrc[!] [file]
41 * Create (or overwrite) a .exrc file with the current info.
43 * PUBLIC: int ex_mkexrc __P((SCR *, EXCMD *));
46 ex_mkexrc(SCR
*sp
, EXCMD
*cmdp
)
57 INT2CHAR(sp
, cmdp
->argv
[0]->bp
, cmdp
->argv
[0]->len
+ 1,
59 set_alt_name(sp
, fname
);
65 if (!FL_ISSET(cmdp
->iflags
, E_C_FORCE
) && !stat(fname
, &sb
)) {
66 msgq_str(sp
, M_ERR
, fname
,
67 "137|%s exists, not written; use ! to override");
71 /* Create with max permissions of rw-r--r--. */
72 if ((fd
= open(fname
, O_CREAT
| O_TRUNC
| O_WRONLY
,
73 S_IRUSR
| S_IWUSR
| S_IRGRP
| S_IROTH
)) < 0) {
74 msgq_str(sp
, M_SYSERR
, fname
, "%s");
78 if ((fp
= fdopen(fd
, "w")) == NULL
) {
84 if (seq_save(sp
, fp
, "abbreviate ", SEQ_ABBREV
) || ferror(fp
))
86 if (seq_save(sp
, fp
, "map ", SEQ_COMMAND
) || ferror(fp
))
88 if (seq_save(sp
, fp
, "map! ", SEQ_INPUT
) || ferror(fp
))
90 if (opts_save(sp
, fp
) || ferror(fp
))
97 msgq_str(sp
, M_INFO
, fname
, "138|New exrc file: %s");
103 msgq_str(sp
, M_SYSERR
, fname
, "%s");