Annotation of 41BSD/lib/libI77/endfile.c, revision 1.1.1.1

1.1       root        1: #include "fio.h"
                      2: static alist *ax;
                      3: extern char *mktemp(), *strcpy();
                      4: f_end(a) alist *a;
                      5: {
                      6:        unit *b;
                      7:        if(a->aunit>=MXUNIT || a->aunit<0) err(a->aerr,101,"endfile");
                      8:        b = &units[a->aunit];
                      9:        if(b->ufd==NULL) return(0);
                     10:        b->uend=1;
                     11:        if( b->useek==0) return(0);
                     12:        ax=a;
                     13:        if(b->uwrt) (void) nowreading(b);
                     14:        return(t_runc(b));
                     15: }
                     16: t_runc(b) unit *b;
                     17: {
                     18:        char buf[128],nm[16];
                     19:        FILE *tmp;
                     20:        int n,m;
                     21:        long loc,len;
                     22:        if(b->url) return(0);   /*don't truncate direct files*/
                     23:        loc=ftell(b->ufd);
                     24:        (void) fseek(b->ufd,0L,2);
                     25:        len=ftell(b->ufd);
                     26:        if(loc==len || b->useek==0 || b->ufnm==NULL) return(0);
                     27:        (void) strcpy(nm,"tmp.FXXXXXX");
                     28:        if(b->uwrt) (void) nowreading(b);
                     29:        (void) mktemp(nm);
                     30:        tmp=fopen(nm,"w");
                     31:        (void) fseek(b->ufd,0L,0);
                     32:        for(;loc>0;)
                     33:        {
                     34:                n=fread(buf,1,loc>128?128:(int)loc,b->ufd);
                     35:                if(n>loc) n=loc;
                     36:                loc -= n;
                     37:                (void) fwrite(buf,1,n,tmp);
                     38:        }
                     39:        (void) fflush(tmp);
                     40:        for(n=0;n<10;n++)
                     41:        {
                     42:                if((m=fork())==-1) continue;
                     43:                else if(m==0)
                     44:                {
                     45:                        (void) execl("/bin/cp","cp",nm,b->ufnm,0);
                     46:                        (void) execl("/usr/bin/cp","cp",nm,b->ufnm,0);
                     47:                        fprintf(stdout,"no cp\n");
                     48:                        exit(1);
                     49:                }
                     50:                (void) wait(&m);
                     51:                if(m!=0) err(ax->aerr,111,"endfile");
                     52:                (void) fclose(tmp);
                     53:                (void) unlink(nm);
                     54:                return(0);
                     55:        }
                     56:        err(ax->aerr,111,"endfile");
                     57: }

unix.superglobalmegacorp.com

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