usr.bin/ranlib/build.c
/*
 * symobj --
 *	Write the symbol table into the archive, computing offsets as
 *	writing.
 */
symobj
Write the symbol table into the archive, computing offsets as
writing.
symobj Write the symbol table into the archive computing offsets as writing .
static void
symobj()
{
	register RLIB *rp;
	struct ranlib rn;
	off_t ransize;
	long size, stroff;
	char hb[sizeof(struct ar_hdr) + 1], pad;
	if (fseek(fp, (long)SARMAG, SEEK_SET))
		error(archive);
	ransize = sizeof(long) +
	    symcnt * sizeof(struct ranlib) + sizeof(long) + tsymlen;
	if (ransize & 01) {
		++ransize;
		pad = '\n';
	} else
		pad = '\0';
#define	DEFMODE	(S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP|S_IROTH|S_IWOTH)
	(void)sprintf(hb, HDR2, RANLIBMAG, 0L, getuid(), getgid(),
	    DEFMODE & ~umask(0), ransize, ARFMAG);
	if (!fwrite(hb, sizeof(struct ar_hdr), 1, fp))
		error(tname);
	size = symcnt * sizeof(struct ranlib);
	if (!fwrite(&size, sizeof(size), 1, fp))
		error(tname);
	size = SARMAG + sizeof(struct ar_hdr) + ransize;
	for (rp = rhead, stroff = 0; rp; rp = rp->next) {
		rn.ran_un.ran_strx = stroff;
		stroff += rp->symlen;
		rn.ran_off = size + rp->pos;
		if (!fwrite(&rn, sizeof(struct ranlib), 1, fp))
			error(archive);
	}
	if (!fwrite(&tsymlen, sizeof(tsymlen), 1, fp))
		error(tname);
	for (rp = rhead; rp; rp = rp->next)
		if (!fwrite(rp->sym, rp->symlen, 1, fp))
			error(tname);
	if (pad && !fwrite(&pad, sizeof(pad), 1, fp))
		error(tname);
	(void)fflush(fp);
}
static void symobj ( ) { register RLIB * rp ; struct ranlib rn ; off_t ransize ; long size , stroff ; char hb [ sizeof ( struct ar_hdr ) + 1 ] , pad ; if ( fseek ( fp , ( long ) SARMAG , SEEK_SET ) ) error ( archive ) ; ransize = sizeof ( long ) + symcnt * sizeof ( struct ranlib ) + sizeof ( long ) + tsymlen ; if ( ransize & 01 ) { ++ ransize ; pad = ' \n ' ; } else pad = ' \0 ' ; #define DEFMODE 	(S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP|S_IROTH|S_IWOTH) ( void ) sprintf ( hb , HDR2 , RANLIBMAG , 0L , getuid ( ) , getgid ( ) , DEFMODE & ~ umask ( 0 ) , ransize , ARFMAG ) ; if ( ! fwrite ( hb , sizeof ( struct ar_hdr ) , 1 , fp ) ) error ( tname ) ; size = symcnt * sizeof ( struct ranlib ) ; if ( ! fwrite ( & size , sizeof ( size ) , 1 , fp ) ) error ( tname ) ; size = SARMAG + sizeof ( struct ar_hdr ) + ransize ; for ( rp = rhead , stroff = 0 ; rp ; rp = rp -> next ) { rn . ran_un . ran_strx = stroff ; stroff += rp -> symlen ; rn . ran_off = size + rp -> pos ; if ( ! fwrite ( & rn , sizeof ( struct ranlib ) , 1 , fp ) ) error ( archive ) ; } if ( ! fwrite ( & tsymlen , sizeof ( tsymlen ) , 1 , fp ) ) error ( tname ) ; for ( rp = rhead ; rp ; rp = rp -> next ) if ( ! fwrite ( rp -> sym , rp -> symlen , 1 , fp ) ) error ( tname ) ; if ( pad && ! fwrite ( & pad , sizeof ( pad ) , 1 , fp ) ) error ( tname ) ; ( void ) fflush ( fp ) ; }
symobj
      Write the symbol table into the archive, computing offsets as
      writing.
symobj Write the symbol table into the archive computing offsets as writing .
/* Rewind the archive, leaving the magic number. */ /* Size of the ranlib archive file, pad if necessary. */ /* Put out the ranlib archive file header. */ /* First long is the size of the ranlib structure section. */ /* Offset of the first archive file. */ /*
	 * Write out the ranlib structures.  The offset into the string
	 * table is cumulative, the offset into the archive is the value
	 * set in rexec() plus the offset to the first archive file.
	 */ /* Second long is the size of the string table. */ /* Write out the string table. */