From 4a3b25cfb67b765fd3ac66b4974ff99bb93a3890 Mon Sep 17 00:00:00 2001 From: Nils Freydank Date: Sun, 29 Apr 2018 17:43:30 +0200 Subject: [PATCH 1/1] Import old fixes from Charles Clark. This patch incorporates old patches by Chales Clark to his own fork. --- hash.c | 10 +++++----- hash_pthreads.c | 15 ++++++++------- init.c | 4 +++- main.c | 3 +++ mktorrent.h | 4 ++-- prefix.c | 25 +++++++++++++++++++------ 6 files changed, 40 insertions(+), 21 deletions(-) diff --git a/hash.c b/hash.c index 6ac1ddf..e61dfce 100644 --- a/hash.c +++ b/hash.c @@ -24,11 +24,11 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA #include /* printf() etc. */ #include /* open() */ #include /* read(), close() */ +#include /* PRId64 etc. */ #ifdef USE_OPENSSL #include /* SHA1() */ #else -#include #include "sha1.h" #endif @@ -60,11 +60,11 @@ EXPORT unsigned char *make_hash(metafile_t *m) unsigned char *pos; /* position in the hash string */ unsigned char *read_buf; /* read buffer */ int fd; /* file descriptor */ - ssize_t r; /* number of bytes read from file(s) into + size_t r; /* number of bytes read from file(s) into the read buffer */ SHA_CTX c; /* SHA1 hashing context */ #ifndef NO_HASH_CHECK - off_t counter = 0; /* number of bytes hashed + int64_t counter = 0; /* number of bytes hashed should match size when done */ #endif @@ -144,8 +144,8 @@ EXPORT unsigned char *make_hash(metafile_t *m) #ifndef NO_HASH_CHECK counter += r; if (counter != m->size) { - fprintf(stderr, "Counted %" PRIoff " bytes, " - "but hashed %" PRIoff " bytes. " + fprintf(stderr, "Counted %" PRId64 " bytes, " + "but hashed %" PRId64 " bytes. " "Something is wrong...\n", m->size, counter); exit(EXIT_FAILURE); } diff --git a/hash_pthreads.c b/hash_pthreads.c index 84143b6..d563ccf 100644 --- a/hash_pthreads.c +++ b/hash_pthreads.c @@ -24,10 +24,11 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA #include /* printf() etc. */ #include /* open() */ #include /* access(), read(), close() */ +#include /* PRId64 etc. */ + #ifdef USE_OPENSSL #include /* SHA1() */ #else -#include #include "sha1.h" #endif #include /* pthread functions and data structures */ @@ -212,11 +213,11 @@ static void read_files(metafile_t *m, queue_t *q, unsigned char *pos) { int fd; /* file descriptor */ flist_t *f; /* pointer to a place in the file list */ - ssize_t r = 0; /* number of bytes read from file(s) + size_t r = 0; /* number of bytes read from file(s) into the read buffer */ #ifndef NO_HASH_CHECK - off_t counter = 0; /* number of bytes hashed - should match size when done */ + int64_t counter = 0; /* number of bytes hashed + should match size when done */ #endif piece_t *p = get_free(q, m->piece_length); @@ -276,8 +277,8 @@ static void read_files(metafile_t *m, queue_t *q, unsigned char *pos) #ifndef NO_HASH_CHECK counter += r; if (counter != m->size) { - fprintf(stderr, "Counted %" PRIoff " bytes, " - "but hashed %" PRIoff " bytes. " + fprintf(stderr, "Counted %" PRId64 " bytes, " + "but hashed %" PRId64 " bytes. " "Something is wrong...\n", m->size, counter); exit(EXIT_FAILURE); } @@ -297,7 +298,7 @@ EXPORT unsigned char *make_hash(metafile_t *m) pthread_t print_progress_thread; /* progress printer thread */ pthread_t *workers; unsigned char *hash_string; /* the hash string */ - unsigned int i; + int i; int err; workers = malloc(m->threads * sizeof(pthread_t)); diff --git a/init.c b/init.c index c07714c..3e8ccd8 100644 --- a/init.c +++ b/init.c @@ -21,10 +21,12 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA #include /* off_t */ #include /* errno */ #include /* strerror() */ -#include /* printf() etc. */ +#include /* perror(), printf() etc. */ #include /* the stat structure */ #include /* getopt(), getcwd(), sysconf() */ #include /* strcmp(), strlen(), strncpy() */ +#include /* strcasecmp() */ +#include /* PRId64 etc. */ #ifdef USE_LONG_OPTIONS #include /* getopt_long() */ #endif diff --git a/main.c b/main.c index 511d036..d0488a0 100644 --- a/main.c +++ b/main.c @@ -28,6 +28,9 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA #ifdef ALLINONE #include #include /* access(), read(), close(), getcwd(), sysconf() */ +#include /* strcasecmp() */ +#include /* PRId64 etc. */ +#include /* isdigit */ #ifdef USE_LONG_OPTIONS #include /* getopt_long() */ #endif diff --git a/mktorrent.h b/mktorrent.h index 5f07a66..1e347b0 100644 --- a/mktorrent.h +++ b/mktorrent.h @@ -30,7 +30,7 @@ struct flist_s; typedef struct flist_s flist_t; struct flist_s { char *path; - off_t size; + int64_t size; flist_t *next; }; @@ -52,7 +52,7 @@ typedef struct { #endif /* information calculated by read_dir() */ - off_t size; /* combined size of all files */ + int64_t size; /* combined size of all files */ flist_t *file_list; /* list of files and their sizes */ unsigned int pieces; /* number of pieces */ } metafile_t; diff --git a/prefix.c b/prefix.c index 447772e..20f9895 100644 --- a/prefix.c +++ b/prefix.c @@ -20,12 +20,19 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA #include #include #include +#include #ifndef TYPE #define TYPE off_t #endif -int main(int argc, char *argv[]) +#if __WORDSIZE == 32 && _FILE_OFFSET_BITS == 64 +# define PRIdOFF_T PRId64 +#else +# define PRIdOFF_T PRIdPTR +#endif + +int main() { unsigned int i; char *prefix[9]; @@ -45,16 +52,22 @@ int main(int argc, char *argv[]) #define str(s) #s #ifdef _LARGEFILE_SOURCE - printf("_LARGEFILE_SOURCE is set\n"); + fprintf(stderr, "_LARGEFILE_SOURCE is set\n"); #endif #ifdef _FILE_OFFSET_BITS - printf("_FILE_OFFSET_BITS = %lu\n", _FILE_OFFSET_BITS); + fprintf(stderr, "_FILE_OFFSET_BITS = %u\n", _FILE_OFFSET_BITS); #endif - printf("sizeof(" xstr(TYPE) ") = %lu, %lu bits\n", - sizeof(TYPE), 8*sizeof(TYPE)); -#endif /* DEBUG */ + fprintf(stderr, "__WORDSIZE is %d\n", __WORDSIZE); + fprintf(stderr, "PRIdOFF_T is " PRIdOFF_T "\n"); + fprintf(stderr, "sizeof(int) = %u, %u bits\n", + (u_int) sizeof(int), 8 * (u_int) sizeof(int)); + fprintf(stderr, "sizeof(long int) = %u, %u bits\n", + (u_int) sizeof(long int), 8 * (u_int) sizeof(long int)); + fprintf(stderr, "sizeof(" xstr(TYPE) ") = %u, %u bits\n", + (u_int) sizeof(TYPE), 8 * (u_int) sizeof(TYPE)); +#endif /* DEBUG */ printf("%s\n", prefix[sizeof(TYPE)]); -- 2.17.0