FreeBSD/usr.sbin/ctm/ctm_rmail/ctm_rmail.c
/*
 * Put the pieces together to form a delta, if they are all present.
 * Returns 1 on success (even if we didn't do anything), and 0 on failure.
 */
Put the pieces together to form a delta, if they are all present.
Returns 1 on success (even if we didn't do anything), and 0 on failure.
Put the pieces together to form a delta if they are all present . Returns 1 on success ( even if we didn ' t do anything ) and 0 on failure .
int
combine_if_complete(char *delta, int pce, int npieces)
    {
    int i, e;
    int lfd;
    struct stat sb;
    char pname[PATH_MAX];
    char dname[PATH_MAX];
    char tname[PATH_MAX];
    if (npieces == 1)
	{
	mk_delta_name(dname, delta);
	mk_piece_name(pname, delta, 1, 1);
	if (rename(pname, dname) == 0)
	    {
	    chmod(dname, 0666 & ~mask);
	    err("%s complete", delta);
	    return 1;
	    }
	}
    strcpy(tname, delta_dir);
    strcat(tname, "/.mutex_build");
    if ((lfd = lock_file(tname)) < 0)
	return 0;
    for (i = 1; i <= npieces; i++)
	{
	if (i == pce)
	    continue;
	mk_piece_name(pname, delta, i, npieces);
	if (stat(pname, &sb) < 0)
	    {
	    close(lfd);
	    return 1;
	    }
	}
    e = combine(delta, npieces, dname, pname, tname);
    close(lfd);
    return e;
    }
int combine_if_complete ( char * delta , int pce , int npieces ) { int i , e ; int lfd ; struct stat sb ; char pname [ PATH_MAX ] ; char dname [ PATH_MAX ] ; char tname [ PATH_MAX ] ; if ( npieces == 1 ) { mk_delta_name ( dname , delta ) ; mk_piece_name ( pname , delta , 1 , 1 ) ; if ( rename ( pname , dname ) == 0 ) { chmod ( dname , 0666 & ~ mask ) ; err ( " " , delta ) ; return 1 ; } } strcpy ( tname , delta_dir ) ; strcat ( tname , " " ) ; if ( ( lfd = lock_file ( tname ) ) < 0 ) return 0 ; for ( i = 1 ; i <= npieces ; i ++ ) { if ( i == pce ) continue ; mk_piece_name ( pname , delta , i , npieces ) ; if ( stat ( pname , & sb ) < 0 ) { close ( lfd ) ; return 1 ; } } e = combine ( delta , npieces , dname , pname , tname ) ; close ( lfd ) ; return e ; }
Put the pieces together to form a delta, if they are all present.
Put the pieces together to form a delta if they are all present .
/*
     * We can probably just rename() it into place if it is a small delta.
     */ /*
     * Grab a lock on the reassembly mutex file so that we can be sure we are
     * working alone, not fighting another ctm_rmail!
     */ /*
     * Are all of the pieces present?  Of course the current one is,
     * unless all pieces are missing because another ctm_rmail has
     * processed them already.
     */ /*
     * Stick them together.  Let combine() use our file name buffers, since
     * we're such good buddies. :-)
     */