* Copyright (c) 1980 Regents of the University of California.
* Redistribution and use in source and binary forms are permitted
* provided that this notice is preserved and that due credit is given
* to the University of California at Berkeley. The name of the University
* may not be used to endorse or promote products derived from this
* software without specific prior written permission. This software
* is provided ``as is'' without express or implied warranty.
static char sccsid
[] = "@(#)fio.c 5.6 (Berkeley) 2/18/88";
* Set up the input pointers while copying the mail file into
if ((c
= opentemp(tempSet
)) < 0)
if ((mestmp
= fdopen(c
, "r+")) == NULL
)
panic("Can't open temporary");
this.m_flag
= MUSED
|MNEW
;
if (fgets(linebuf
, LINESIZE
, ibuf
) == NULL
) {
if (append(&this, mestmp
)) {
fwrite(linebuf
, sizeof *linebuf
, count
, otf
);
if (maybe
&& linebuf
[0] == 'F' && ishead(linebuf
)) {
if (append(&this, mestmp
)) {
this.m_flag
= MUSED
|MNEW
;
this.m_block
= blockof(offset
);
this.m_offset
= offsetof(offset
);
} else if (linebuf
[0] == 0) {
for (cp
= linebuf
, cp2
= "status";; cp
++) {
if (*cp
!= c
&& *cp
!= toupper(c
))
* 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.
fwrite(linebuf
, sizeof *linebuf
, c
, obuf
);
* 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
> 0 && linebuf
[n
- 1] == '\n')
* Return a file buffer all ready to read up the
* passed message pointer.
register struct message
*mp
;
if (fseek(itf
, positionof(mp
->m_block
, mp
->m_offset
), 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 size
= (msgCount
+ 1) * sizeof (struct message
);
if ((message
= (struct message
*) malloc((unsigned) size
)) == 0)
panic("Insufficient memory for %d messages", msgCount
);
size
-= sizeof (struct message
);
lseek(fileno(f
), (long) sizeof *message
, 0);
if (read(fileno(f
), (char *) message
, size
) != size
)
panic("Message temporary file corrupted");
message
[msgCount
].m_size
= 0;
message
[msgCount
].m_lines
= 0;
* Append the passed message descriptor onto the temp file.
* If the write fails, return 1, else 0
return fwrite((char *) mp
, sizeof *mp
, 1, f
) != 1;
* 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, SIGINT, and SIGQUIT.
omask
= sigblock(sigmask(SIGHUP
)|sigmask(SIGINT
)|sigmask(SIGQUIT
));
* Release signals SIGHUP, SIGINT, and SIGQUIT.
* Open a temp file by creating and unlinking.
* Return the open file descriptor.
if ((f
= open(file
, O_CREAT
|O_EXCL
|O_RDWR
, 0600)) < 0)
* Determine the size of the file possessed by
if (fstat(fileno(iob
), &sbuf
) < 0)
* 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
;
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
.w_status
!= 0 && s
.w_termsig
!= 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.
if ((f
= dup(fildes
)) < 0) {