/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License, Version 1.0 only
* (the "License"). You may not use this file except in compliance
* with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
* Copyright 2005 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
/* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
/* All Rights Reserved */
/* Copyright (c) 1981 Regents of the University of California */
#pragma ident "%Z%%M% %I% %E% SMI"
#include <ctype.h>
#include <errno.h>
#include <dirent.h>
#include <pwd.h>
#include <locale.h>
#include <limits.h>
#include <unistd.h>
#include "ex_tune.h"
/*
* Expreserve - preserve a file in usrpath(preserve)
*
* This routine is very naive - it doesn't remove anything from
* usrpath(preserve)... this may mean that we * stuff there...
* the danger in doing anything with usrpath(preserve)
* is that the clock may be messed up and we may get confused.
*
* We are called in two ways - first from the editor with no arguments
* and the standard input open on the temp file. Second with an argument
*
* BUG: should do something about preserving Rx... (register contents)
* temporaries.
*/
struct header {
#ifndef VMUNIX
#else
int Flines;
#endif
} H;
void notify(int, unsigned char *, int, int);
void mkdigits(unsigned char *);
int
int argc;
{
unsigned char *filname;
#if !defined(TEXT_DOMAIN)
#endif
(void) textdomain(TEXT_DOMAIN);
/*
* If only one argument, then preserve the standard input.
*/
if (argc == 1) {
if (copyout((unsigned char *) 0))
return (1);
return (0);
}
/*
* If not super user, then can only preserve standard input.
*/
if (getuid()) {
return (1);
}
/*
* it as we go.
*/
return (1);
}
{
return (1);
}
{
/*
* Ex temporaries must begin with Ex;
* we check that the 12th character of the name is null
* so we won't have to worry about non-null terminated names
* later on.
*/
continue;
continue;
continue;
/*
* Save the file.
*/
}
return (0);
}
/*
* Copy file name into usrpath(preserve)/...
* If name is (char *) 0, then do the standard input.
* We make some checks on the input to make sure it is
* really an editor temporary, generate a name for the
* file (this is the slowest thing since we must stat
* to find a unique name), and finally copy the file.
*/
int
{
int i;
static int reenter;
int savfild;
/*
* The first time we put in the digits of our
* process number at the end of the pattern.
*/
if (reenter == 0) {
reenter++;
}
/*
* If a file name was given, make it the standard
* input if possible.
*/
if (name != 0) {
(void) close(0);
/*
* (see below).
*/
return (-1);
}
/*
* Get the header block.
*/
(void) lseek(0, 0l, 0);
if (read(0, (char *)&H, sizeof (H)) != sizeof (H)) {
if (name == 0)
else {
/*
* avoid having a bunch of NULL Ex* files
* hanging around
*/
}
return (-1);
}
/*
* Consistency checks so we don't copy out garbage.
*/
if (H.Flines < 0) {
#ifdef DEBUG
#endif
goto format;
}
#ifdef DEBUG
#endif
goto format;
}
#ifdef DEBUG
#endif
goto format;
}
if (lseek(0, 0l, 0)) {
#ifdef DEBUG
#endif
goto format;
}
/*
* If no name was assigned to the file, then give it the name
* LOST, by putting this in the header.
*/
if (H.Savedfile[0] == 0) {
(void) write(0, (char *) &H, sizeof (H));
H.Savedfile[0] = 0;
(void) lseek(0, 0l, 0);
}
/*
* See if preservation directory for user exists.
*/
if (pp)
else {
return (-1);
}
/* It doesn't exist or it isn't a directory, safe to unlink */
gettext("Unable to create directory \"%s\"\n"),
savdir);
perror("");
return (-1);
}
}
/*
* File is good. Get a name and create a file for the copy.
*/
(void) close(1);
if (name == 0)
return (1);
}
/*
* Make target owned by user.
*/
/*
* Copy the file.
*/
for (;;) {
if (i < 0) {
if (name)
return (-1);
}
if (i == 0) {
if (name)
return (0);
}
if (name == 0)
return (-1);
}
}
}
/*
* Blast the last 5 characters of cp to be the process number.
*/
void
{
pid_t i;
int j;
}
/*
* Make the name in cp be unique by clobbering up to
* three alphabetic characters into a sequence of the form 'aab', 'aac', etc.
* Mktemp gets weird names too quickly to be useful here.
*/
int
{
unsigned char *dcp;
int fd;
dcp--;
do {
if (dcp[0] == 'z') {
dcp[0] = 'a';
gettext("Can't find a name\t"));
return (-1);
}
dcp[-2]++;
} else
dcp[-1]++;
} else
dcp[0]++;
/* copy out patern */
return (fd);
}
/*
* Notify user uid that his file fname has been saved.
*/
void
{
return;
return;
return;
if (fname[0] == 0) {
"A copy of an editor buffer of yours was saved on %s when the system went down.\n" :
"A copy of an editor buffer of yours was saved on %s when the editor was killed\nor was unable to save your changes.\n", hostname);
"No name was associated with this buffer so it has been named \"LOST\".\n");
} else
"A copy of an editor buffer of your file \"%s\"%s was saved on %s\nwhen the system \
went down.\n" :
"A copy of an editor buffer of your file \"%s\"%s was saved on %s\nwhen the editor \
was killed or was unable to save your changes.\n", fname, (cryflag) ? "[ENCRYPTED]" : "", hostname);
/*
* "the editor was killed" is perhaps still not an ideal
* error message. Usually, either it was forceably terminated
* or the phone was hung up, but we don't know which.
*/
"This buffer can be retrieved using the \"recover\" command of the editor.\n");
"An easy way to do this is to give the command \"vi -r %s\".\n",
}