2 * Copyright (c) 1992, 1993
3 * The Regents of the University of California. All rights reserved.
5 * %sccs.include.redist.c%
9 static char sccsid
[] = "$Id: ex_mkexrc.c,v 8.6 1993/11/20 10:05:40 bostic Exp $ (Berkeley) $Date: 1993/11/20 10:05:40 $";
12 #include <sys/types.h>
23 #include "pathnames.h"
26 * ex_mkexrc -- :mkexrc[!] [file]
27 * Create (or overwrite) a .exrc file with the current info.
30 ex_mkexrc(sp
, ep
, cmdp
)
45 fname
= cmdp
->argv
[0];
46 set_alt_name(sp
, fname
);
52 if (!F_ISSET(cmdp
, E_FORCE
) && !stat(fname
, &sb
)) {
54 "%s exists, not written; use ! to override.", fname
);
58 /* Create with max permissions of rw-r--r--. */
59 if ((fd
= open(fname
, O_CREAT
| O_TRUNC
| O_WRONLY
,
60 S_IRUSR
| S_IWUSR
| S_IRGRP
| S_IROTH
)) < 0) {
61 msgq(sp
, M_SYSERR
, fname
);
65 if ((fp
= fdopen(fd
, "w")) == NULL
) {
72 if (abbr_save(sp
, fp
) || ferror(fp
))
74 if (map_save(sp
, fp
) || ferror(fp
))
76 if (opts_save(sp
, fp
) || ferror(fp
))
84 msgq(sp
, M_INFO
, "New .exrc file: %s. ", fname
);
90 e2
: msgq(sp
, M_ERR
, "%s: incomplete: %s", fname
, strerror(errno
));