version 1.19, 2001/11/20 20:50:00 |
version 1.20, 2001/11/21 15:26:39 |
|
|
|
|
#ifndef lint |
#ifndef lint |
#if 0 |
#if 0 |
static char sccsid[] = "@(#)fio.c 8.2 (Berkeley) 4/20/95"; |
static const char sccsid[] = "@(#)fio.c 8.2 (Berkeley) 4/20/95"; |
#else |
#else |
static char rcsid[] = "$OpenBSD$"; |
static const char rcsid[] = "$OpenBSD$"; |
#endif |
#endif |
#endif /* not lint */ |
#endif /* not lint */ |
|
|
|
|
* Wrapper for read() to catch EINTR. |
* Wrapper for read() to catch EINTR. |
*/ |
*/ |
ssize_t |
ssize_t |
myread(fd, buf, len) |
myread(int fd, char *buf, int len) |
int fd; |
|
char *buf; |
|
int len; |
|
{ |
{ |
ssize_t nread; |
ssize_t nread; |
|
|
|
|
* Set up the input pointers while copying the mail file into /tmp. |
* Set up the input pointers while copying the mail file into /tmp. |
*/ |
*/ |
void |
void |
setptr(ibuf, offset) |
setptr(FILE *ibuf, off_t offset) |
FILE *ibuf; |
|
off_t offset; |
|
{ |
{ |
int c, count; |
int c, count; |
char *cp, *cp2; |
char *cp, *cp2; |
|
|
* characters written, including the newline if requested. |
* characters written, including the newline if requested. |
*/ |
*/ |
int |
int |
putline(obuf, linebuf, outlf) |
putline(FILE *obuf, char *linebuf, int outlf) |
FILE *obuf; |
|
char *linebuf; |
|
int outlf; |
|
{ |
{ |
int c; |
int c; |
|
|
|
|
* include the newline (or carriage return) at the end. |
* include the newline (or carriage return) at the end. |
*/ |
*/ |
int |
int |
readline(ibuf, linebuf, linesize, signo) |
readline(FILE *ibuf, char *linebuf, int linesize, int *signo) |
FILE *ibuf; |
|
char *linebuf; |
|
int linesize; |
|
int *signo; |
|
{ |
{ |
struct sigaction act; |
struct sigaction act; |
struct sigaction savetstp; |
struct sigaction savetstp; |
|
|
* passed message pointer. |
* passed message pointer. |
*/ |
*/ |
FILE * |
FILE * |
setinput(mp) |
setinput(struct message *mp) |
struct message *mp; |
|
{ |
{ |
|
|
fflush(otf); |
fflush(otf); |
|
|
* a dynamically allocated message structure. |
* a dynamically allocated message structure. |
*/ |
*/ |
void |
void |
makemessage(f, omsgCount) |
makemessage(FILE *f, int omsgCount) |
FILE *f; |
|
int omsgCount; |
|
{ |
{ |
size_t size = (msgCount + 1) * sizeof(struct message); |
size_t size = (msgCount + 1) * sizeof(struct message); |
|
|
|
|
* If the write fails, return 1, else 0 |
* If the write fails, return 1, else 0 |
*/ |
*/ |
int |
int |
append(mp, f) |
append(struct message *mp, FILE *f) |
struct message *mp; |
|
FILE *f; |
|
{ |
{ |
|
|
return(fwrite((char *) mp, sizeof(*mp), 1, f) != 1); |
return(fwrite((char *) mp, sizeof(*mp), 1, f) != 1); |
} |
} |
|
|
|
|
* Delete or truncate a file, but only if the file is a plain file. |
* Delete or truncate a file, but only if the file is a plain file. |
*/ |
*/ |
int |
int |
rm(name) |
rm(char *name) |
char *name; |
|
{ |
{ |
struct stat sb; |
struct stat sb; |
|
|
|
|
* Hold signals SIGHUP, SIGINT, and SIGQUIT. |
* Hold signals SIGHUP, SIGINT, and SIGQUIT. |
*/ |
*/ |
void |
void |
holdsigs() |
holdsigs(void) |
{ |
{ |
|
|
if (sigdepth++ == 0) { |
if (sigdepth++ == 0) { |
|
|
* Release signals SIGHUP, SIGINT, and SIGQUIT. |
* Release signals SIGHUP, SIGINT, and SIGQUIT. |
*/ |
*/ |
void |
void |
relsesigs() |
relsesigs(void) |
{ |
{ |
|
|
if (--sigdepth == 0) |
if (--sigdepth == 0) |
|
|
* Unblock and ignore a signal |
* Unblock and ignore a signal |
*/ |
*/ |
int |
int |
ignoresig(sig, oact, oset) |
ignoresig(int sig, struct sigaction *oact, sigset_t *oset) |
int sig; |
|
struct sigaction *oact; |
|
sigset_t *oset; |
|
{ |
{ |
struct sigaction act; |
struct sigaction act; |
sigset_t nset; |
sigset_t nset; |
|
|
* the passed buffer. |
* the passed buffer. |
*/ |
*/ |
off_t |
off_t |
fsize(iob) |
fsize(FILE *iob) |
FILE *iob; |
|
{ |
{ |
struct stat sbuf; |
struct stat sbuf; |
|
|
|
|
* Return the file name as a dynamic string. |
* Return the file name as a dynamic string. |
*/ |
*/ |
char * |
char * |
expand(name) |
expand(char *name) |
char *name; |
|
{ |
{ |
char xname[PATHSIZE]; |
char xname[PATHSIZE]; |
char cmdbuf[PATHSIZE]; /* also used for file names */ |
char cmdbuf[PATHSIZE]; /* also used for file names */ |
int pid, l; |
pid_t pid; |
|
int l; |
char *cp, *shell; |
char *cp, *shell; |
int pivec[2]; |
int pivec[2]; |
struct stat sbuf; |
struct stat sbuf; |
|
|
(void)snprintf(xname, sizeof(xname), "%s%s", homedir, name + 1); |
(void)snprintf(xname, sizeof(xname), "%s%s", homedir, name + 1); |
name = savestr(xname); |
name = savestr(xname); |
} |
} |
if (!anyof(name, "~{[*?$`'\"\\")) |
if (strpbrk(name, "~{[*?$`'\"\\") == NULL) |
return(name); |
return(name); |
|
/* XXX - just use glob(3) and env expansion instead? */ |
if (pipe(pivec) < 0) { |
if (pipe(pivec) < 0) { |
warn("pipe"); |
warn("pipe"); |
return(name); |
return(name); |
|
|
* Determine the current folder directory name. |
* Determine the current folder directory name. |
*/ |
*/ |
int |
int |
getfold(name, namelen) |
getfold(char *name, int namelen) |
char *name; |
|
int namelen; |
|
{ |
{ |
char *folder; |
char *folder; |
|
|
if ((folder = value("folder")) == NULL) |
if ((folder = value("folder")) == NULL) |
return(-1); |
return(-1); |
if (*folder == '/') { |
if (*folder == '/') |
strncpy(name, folder, namelen-1); |
strlcpy(name, folder, namelen); |
name[namelen-1] = '\0'; |
else |
} else |
|
(void)snprintf(name, namelen, "%s/%s", homedir ? homedir : ".", |
(void)snprintf(name, namelen, "%s/%s", homedir ? homedir : ".", |
folder); |
folder); |
return(0); |
return(0); |
|
|
* Return the name of the dead.letter file. |
* Return the name of the dead.letter file. |
*/ |
*/ |
char * |
char * |
getdeadletter() |
getdeadletter(void) |
{ |
{ |
char *cp; |
char *cp; |
|
|
|
|
* SIGTTOU, SIGTTIN. |
* SIGTTOU, SIGTTIN. |
*/ |
*/ |
void |
void |
fioint(s) |
fioint(int s) |
int s; |
|
{ |
{ |
|
|
fiosignal = s; |
fiosignal = s; |