예제 #1
0
파일: low_level.c 프로젝트: 2asoft/freebsd
svn_stringbuf_t *
svn_fs_fs__unparse_representation(representation_t *rep,
                                  int format,
                                  svn_boolean_t mutable_rep_truncated,
                                  apr_pool_t *result_pool,
                                  apr_pool_t *scratch_pool)
{
  char buffer[SVN_INT64_BUFFER_SIZE];
  if (svn_fs_fs__id_txn_used(&rep->txn_id) && mutable_rep_truncated)
    return svn_stringbuf_ncreate("-1", 2, result_pool);

  if (format < SVN_FS_FS__MIN_REP_SHARING_FORMAT || !rep->has_sha1)
    return svn_stringbuf_createf
            (result_pool, "%ld %" APR_UINT64_T_FMT " %" SVN_FILESIZE_T_FMT
             " %" SVN_FILESIZE_T_FMT " %s",
             rep->revision, rep->item_index, rep->size,
             rep->expanded_size,
             format_digest(rep->md5_digest, svn_checksum_md5, FALSE,
                           scratch_pool));

  svn__ui64tobase36(buffer, rep->uniquifier.number);
  return svn_stringbuf_createf
          (result_pool, "%ld %" APR_UINT64_T_FMT " %" SVN_FILESIZE_T_FMT
           " %" SVN_FILESIZE_T_FMT " %s %s %s/_%s",
           rep->revision, rep->item_index, rep->size,
           rep->expanded_size,
           format_digest(rep->md5_digest, svn_checksum_md5,
                         FALSE, scratch_pool),
           format_digest(rep->sha1_digest, svn_checksum_sha1,
                         !rep->has_sha1, scratch_pool),
           svn_fs_fs__id_txn_unparse(&rep->uniquifier.noderev_txn_id,
                                     scratch_pool),
           buffer);
}
예제 #2
0
svn_stringbuf_t *
svn_fs_x__unparse_representation(svn_fs_x__representation_t *rep,
                                 svn_boolean_t mutable_rep_truncated,
                                 apr_pool_t *result_pool,
                                 apr_pool_t *scratch_pool)
{
  if (!rep->has_sha1)
    return svn_stringbuf_createf
            (result_pool,
             "%" APR_INT64_T_FMT " %" APR_UINT64_T_FMT " %" SVN_FILESIZE_T_FMT
             " %" SVN_FILESIZE_T_FMT " %s",
             rep->id.change_set, rep->id.number, rep->size,
             rep->expanded_size,
             format_digest(rep->md5_digest, svn_checksum_md5, FALSE,
                           scratch_pool));

  return svn_stringbuf_createf
          (result_pool,
           "%" APR_INT64_T_FMT " %" APR_UINT64_T_FMT " %" SVN_FILESIZE_T_FMT
           " %" SVN_FILESIZE_T_FMT " %s %s",
           rep->id.change_set, rep->id.number, rep->size,
           rep->expanded_size,
           format_digest(rep->md5_digest, svn_checksum_md5,
                         FALSE, scratch_pool),
           format_digest(rep->sha1_digest, svn_checksum_sha1,
                         !rep->has_sha1, scratch_pool));
}
예제 #3
0
파일: digest.c 프로젝트: calyx/darwinbuild
char* calculate_digest(int fd) {
	unsigned char md[CC_SHA1_DIGEST_LENGTH];
	CC_SHA1_CTX c;
	CC_SHA1_Init(&c);
	
	memset(md, 0, CC_SHA1_DIGEST_LENGTH);
	
	ssize_t len;
	const unsigned int blocklen = 8192;
	unsigned char* block = (unsigned char*)malloc(blocklen);
	if (!block) {
		errno = ENOMEM;
		return NULL;
	}
	while(1) {
		len = read(fd, block, blocklen);
		if (len == 0) { close(fd); break; }
		if ((len < 0) && (errno == EINTR)) continue;
		if (len < 0) { close(fd); return NULL; }
		CC_SHA1_Update(&c, block, (CC_LONG)len);
	}
	
	CC_SHA1_Final(md, &c);
	free(block);
	return format_digest(md);
}