* Copyright (c) 1980 Regents of the University of California.
* All rights reserved. The Berkeley software License Agreement
* specifies the terms and conditions for redistribution.
static char *sccsid
= "@(#)fio.c 5.3 (Berkeley) %G%";
* Set up the input pointers while copying the mail file into
int maybe
, mestmp
, flag
, inhead
;
if ((mestmp
= opentemp(tempSet
)) < 0)
if (fgets(linebuf
, LINESIZE
, ibuf
) == NULL
) {
this.m_offset
= offsetof(offset
);
this.m_block
= blockof(offset
);
if (append(&this, mestmp
)) {
cp
= linebuf
+ (count
- 1);
if (maybe
&& linebuf
[0] == 'F' && ishead(linebuf
)) {
this.m_block
= blockof(offset
);
this.m_offset
= offsetof(offset
);
if (append(&this, mestmp
)) {
if (inhead
&& (cp
= index(linebuf
, ':'))) {
if (icequal(linebuf
, "status")) {
* Drop the passed line onto the passed output buffer.
* If a write error occurs, return -1, else the count of
* characters written, including the newline.
* Read up a line from the specified input into the line
* buffer. Return the number of characters read. Do not
* include the newline at the end.
if (fgets(linebuf
, LINESIZE
, ibuf
) == NULL
)
if (n
>= 1 && linebuf
[n
-1] == '\n')
* Return a file buffer all ready to read up the
* passed message pointer.
register struct message
*mp
;
if (fseek(itf
, off
, 0) < 0) {
panic("temporary file seek");
* Take the data out of the passed ghost file and toss it into
* a dynamically allocated message structure.
register struct message
*m
;
mp
= calloc((unsigned) (msgCount
+ 1), sizeof *m
);
printf("Insufficient memory for %d messages\n", msgCount
);
if (message
!= (struct message
*) 0)
message
= (struct message
*) mp
;
while (count
= read(f
, mp
, BUFSIZ
))
for (m
= &message
[0]; m
< &message
[msgCount
]; m
++) {
m
->m_size
= (m
+1)->m_size
;
m
->m_lines
= (m
+1)->m_lines
;
m
->m_flag
= (m
+1)->m_flag
;
message
[msgCount
].m_size
= 0L;
message
[msgCount
].m_lines
= 0;
* Append the passed message descriptor onto the temp file.
* If the write fails, return 1, else 0
if (write(f
, (char *) mp
, sizeof *mp
) != sizeof *mp
)
* Delete a file, but only if the file is a plain file.
if (stat(name
, &statb
) < 0)
if ((statb
.st_mode
& S_IFMT
) != S_IFREG
) {
* Terminate an editing session by attempting to write out the user's
* file from the temporary. Save any new stuff appended to the file.
register struct message
*mp
;
FILE *obuf
, *ibuf
, *readstat
;
if ((readstat
= fopen(Tflag
, "w")) == NULL
)
for (mp
= &message
[0], gotcha
= 0; mp
< &message
[msgCount
]; mp
++) {
if (mp
->m_flag
& (MODIFY
|MDELETED
|MSTATUS
))
if (Tflag
!= NOSTR
&& (mp
->m_flag
& (MREAD
|MDELETED
)) != 0) {
if ((id
= hfield("article-id", mp
)) != NOSTR
)
fprintf(readstat
, "%s\n", id
);
if (!gotcha
|| Tflag
!= NOSTR
)
if (stat(editfile
, &statb
) >= 0 && statb
.st_size
> mailsize
) {
strcpy(tempname
, "/tmp/mboxXXXXXX");
if ((obuf
= fopen(tempname
, "w")) == NULL
) {
if ((ibuf
= fopen(editfile
, "r")) == NULL
) {
fseek(ibuf
, mailsize
, 0);
while ((c
= getc(ibuf
)) != EOF
)
if ((ibuf
= fopen(tempname
, "r")) == NULL
) {
printf("\"%s\" ", editfile
);
if ((obuf
= fopen(editfile
, "r+")) == NULL
) {
for (mp
= &message
[0]; mp
< &message
[msgCount
]; mp
++) {
if ((mp
->m_flag
& MDELETED
) != 0)
if (send(mp
, obuf
, 0) < 0) {
gotcha
= (c
== 0 && ibuf
== NULL
);
while ((c
= getc(ibuf
)) != EOF
)
static int sigdepth
= 0; /* depth of holdsigs() */
* Hold signals SIGHUP - SIGQUIT.
omask
= sigblock(sigmask(SIGHUP
)|sigmask(SIGINT
)|sigmask(SIGQUIT
));
* Release signals SIGHUP - SIGQUIT
* Open a temp file by creating, closing, unlinking, and
* reopening. Return the open file descriptor.
if ((f
= creat(file
, 0600)) < 0) {
if ((f
= open(file
, 2)) < 0) {
* Determine the size of the file possessed by
* Take a file name, possibly with shell meta characters
* in it and expand it by using "sh -c echo filename"
* Return the file name as a dynamic string.
register char *cp
, *Shell
;
int s
, pivec
[2], (*sigint
)();
if (name
[0] == '+' && getfold(cmdbuf
) >= 0) {
sprintf(xname
, "%s/%s", cmdbuf
, name
+ 1);
return(expand(savestr(xname
)));
if (!anyof(name
, "~{[*?$`'\"\\"))
sprintf(cmdbuf
, "echo %s", name
);
if ((pid
= vfork()) == 0) {
execl(Shell
, Shell
, "-c", cmdbuf
, 0);
l
= read(pivec
[0], xname
, BUFSIZ
);
if (s
!= 0 && s
!= SIGPIPE
) {
fprintf(stderr
, "\"Echo\" failed\n");
fprintf(stderr
, "\"%s\": No match\n", name
);
fprintf(stderr
, "Buffer overflow expanding \"%s\"\n", name
);
for (cp
= &xname
[l
-1]; *cp
== '\n' && cp
> xname
; cp
--)
if (any(' ', xname
) && stat(xname
, &sbuf
) < 0) {
fprintf(stderr
, "\"%s\": Ambiguous\n", name
);
* Determine the current folder directory name.
if ((folder
= value("folder")) == NOSTR
)
sprintf(name
, "%s/%s", homedir
, folder
);
* A nicer version of Fdopen, which allows us to fclose
* without losing the open file.