3737#include <stddef.h>
3838#include <string.h>
3939
40+ #if defined(_WIN32 )
41+ # include <io.h>
42+ #endif
43+
4044#define STATE_ACTIVE 0xb01dbabe
4145#define STATE_STOPPED 0xdeadbeef
4246#define STATE_DELETED 0xdecea5ed
@@ -106,7 +110,7 @@ static rhash_context_ext* rhash_alloc_multi(size_t count, const unsigned hash_id
106110 }
107111 assert (IS_EXTENDED_HASH_ID (info -> info -> hash_id ));
108112 assert (IS_VALID_EXTENDED_HASH_ID (info -> info -> hash_id ));
109- hash_bitmask |= 1 << GET_EXTENDED_HASH_ID_INDEX (info -> info -> hash_id );
113+ hash_bitmask |= I64 ( 1 ) << GET_EXTENDED_HASH_ID_INDEX (info -> info -> hash_id );
110114
111115 /* align context sizes and sum up */
112116 ctx_size_sum += GET_CTX_ALIGNED (info -> context_size );
@@ -122,7 +126,7 @@ static rhash_context_ext* rhash_alloc_multi(size_t count, const unsigned hash_id
122126 rctx -> rc .hash_mask = hash_bitmask ;
123127 rctx -> flags = RCTX_AUTO_FINAL ; /* turn on auto-final by default */
124128 rctx -> state = STATE_ACTIVE ;
125- rctx -> hash_vector_size = count ;
129+ rctx -> hash_vector_size = ( unsigned ) count ;
126130
127131 /* calculate aligned pointer >= (&rctx->vector[count]) */
128132 phash_ctx = (char * )rctx + header_size ;
@@ -402,7 +406,7 @@ RHASH_API rhash rhash_import(const void* in, size_t size)
402406 item_size = rhash_import_alg (hash_ids [i ], dst_context , src_item , left_size );
403407 imported_size += item_size ;
404408 if (!item_size || size < imported_size ) {
405- ectx -> hash_vector_size = i + 1 ; /* clean only initialized contextes */
409+ ectx -> hash_vector_size = ( unsigned ) i + 1 ; /* clean only initialized contextes */
406410 rhash_free (& ectx -> rc );
407411 return import_error_einval ();
408412 }
@@ -411,7 +415,7 @@ RHASH_API rhash rhash_import(const void* in, size_t size)
411415 item_size = hash_info -> context_size ;
412416 imported_size += item_size ;
413417 if (size < imported_size ) {
414- ectx -> hash_vector_size = i + 1 ;
418+ ectx -> hash_vector_size = ( unsigned ) i + 1 ;
415419 rhash_free (& ectx -> rc );
416420 return import_error_einval ();
417421 }
@@ -528,6 +532,14 @@ struct file_update_context {
528532 size_t buffer_size ; /* Size of the data buffer */
529533};
530534
535+ #if defined(_WIN32 )
536+ /* For Windows define ssize_t, which is Posix, but not in standard C */
537+ # define ssize_t intptr_t
538+ # define READ_SIZE_TYPE unsigned
539+ #else
540+ # define READ_SIZE_TYPE size_t
541+ #endif
542+
531543/**
532544 * Read data from a C file stream into the context buffer using fread().
533545 *
@@ -555,7 +567,7 @@ static ssize_t read_file_fd_impl(struct file_update_context *fctx, size_t data_s
555567static ssize_t read_int_fd_impl (struct file_update_context * fctx , size_t data_size )
556568{
557569 assert (data_size <= fctx -> buffer_size );
558- return read (fctx -> int_fd , fctx -> buffer , data_size );
570+ return read (fctx -> int_fd , fctx -> buffer , ( READ_SIZE_TYPE ) data_size );
559571}
560572
561573/**
@@ -723,13 +735,13 @@ RHASH_API int rhash_get_hash_length(unsigned hash_id)
723735RHASH_API const char * rhash_get_name (unsigned hash_id )
724736{
725737 const rhash_info * info = rhash_info_by_id (hash_id );
726- return (info ? info -> name : 0 );
738+ return (info ? info -> name : NULL );
727739}
728740
729741RHASH_API const char * rhash_get_magnet_name (unsigned hash_id )
730742{
731743 const rhash_info * info = rhash_info_by_id (hash_id );
732- return (info ? info -> magnet_name : 0 );
744+ return (info ? info -> magnet_name : NULL );
733745}
734746
735747static size_t rhash_get_magnet_url_size (const char * filepath ,
0 commit comments