Annotation of 3BSD/new/libI77uc/endfile.c, revision 1.1.1.1

1.1       root        1: /*
                      2:  * endfile
                      3:  */
                      4: 
                      5: #include "fio.h"
                      6: 
                      7: char *endf = "endfile";
                      8: extern char *tmplate;
                      9: 
                     10: f_end(a) alist *a;
                     11: {
                     12:        unit *b;
                     13:        lfname = NULL;
                     14:        elist = NO;
                     15:        errflag = a->aerr;
                     16:        lunit = a->aunit;
                     17:        if (not_legal(lunit)) err(errflag,101,endf)
                     18:        b = &units[lunit];
                     19:        if(!b->ufd) err(errflag,114,endf)
                     20:        if(b->uend) return(0);
                     21:        lfname = b->ufnm;
                     22:        b->uend = YES;
                     23:        return(t_runc(b,errflag));
                     24: }
                     25: 
                     26: t_runc(b,flag) unit *b; ioflag flag;
                     27: {
                     28:        char buf[128],nm[16];
                     29:        FILE *tmp;
                     30:        int n,m;
                     31:        long loc,len;
                     32:        fflush(b->ufd);
                     33:        if(b->uwrt) nowreading(b);
                     34:        if(b->url || !b->useek || !b->ufnm) return(OK); /*don't trunc dir files*/
                     35:        loc=ftell(b->ufd);
                     36:        fseek(b->ufd,0L,2);
                     37:        len=ftell(b->ufd);
                     38:        if (loc==len) return(OK);
                     39:        strcpy(nm,tmplate);
                     40:        mktemp(nm);
                     41:        if(!(tmp=fopen(nm,"w"))) err(flag,errno,endf);
                     42:        fseek(b->ufd,0L,0);
                     43:        while (loc)
                     44:        {
                     45:                n=fread(buf,1,loc>sizeof(buf)?sizeof(buf):(int)loc,b->ufd);
                     46:                loc -= n;
                     47:                fwrite(buf,1,n,tmp);
                     48:        }
                     49:        fflush(tmp);
                     50:        for(n=0;n<10;n++)
                     51:        {
                     52:                if((m=fork())==-1) continue;
                     53:                else if(m==0)
                     54:                {
                     55:                        execl("/bin/cp","cp",nm,b->ufnm,0);
                     56:                        execl("/usr/bin/cp","cp",nm,b->ufnm,0);
                     57:                        fatal(119,"no cp for trunc");
                     58:                }
                     59:                wait(&m);
                     60:                if(m) err(flag,111,endf);
                     61:                fclose(tmp);
                     62:                unlink(nm);
                     63:                return(OK);
                     64:        }
                     65:        err(flag,111,endf);
                     66: }

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.