Implemented support for working with remote repositories.

libfetch from NetBSD's pkgsrc has been imported into lib/fetch, but
the objects are embedded into libxbps. Only a public function to fetch
files has been implemented: xbps_fetch_file().

The library now is built with -fvisibility=hidden by default, and
exported symbols are the ones that use the SYMEXPORT macro.

The code works well enough, but will need many more cleanups.

--HG--
extra : convert_revision : xtraeme%40gmail.com-20091027004600-0lq9aao67lisbzxv
This commit is contained in:
Juan RP
2009-10-27 01:46:00 +01:00
parent 6a855c0272
commit 7aebea684b
41 changed files with 6039 additions and 308 deletions

View File

@ -1,5 +1,5 @@
/*-
* Copyright (c) 2008 Juan Romero Pardines.
* Copyright (c) 2008-2009 Juan Romero Pardines.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@ -30,7 +30,6 @@
#include <string.h>
#include <xbps_api.h>
#include "sha256.h"
static void
usage(void)
@ -42,35 +41,21 @@ usage(void)
int
main(int argc, char **argv)
{
SHA256_CTX ctx;
uint8_t buffer[BUFSIZ * 20], *digest;
ssize_t bytes;
int i, fd;
char *hash;
int i;
if (argc < 2)
usage();
for (i = 1; i < argc; i++) {
if ((fd = open(argv[i], O_RDONLY)) == -1) {
printf("xbps-digest: cannot open %s (%s)\n", argv[i],
strerror(errno));
hash = xbps_get_file_hash(argv[i]);
if (hash == NULL) {
printf("Couldn't get hash for %s (%s)\n",
argv[i], strerror(errno));
exit(EXIT_FAILURE);
}
digest = malloc(SHA256_DIGEST_STRING_LENGTH);
if (digest == NULL) {
printf("xbps-digest: malloc failed (%s)\n",
strerror(errno));
exit(EXIT_FAILURE);
}
SHA256_Init(&ctx);
while ((bytes = read(fd, buffer, sizeof(buffer))) > 0)
SHA256_Update(&ctx, buffer, (size_t)bytes);
printf("%s\n", SHA256_End(&ctx, digest));
free(digest);
close(fd);
printf("%s\n", hash);
free(hash);
}
exit(EXIT_SUCCESS);