Skip to content

Commit

Permalink
Merge pull request #205 from DenverM80/win_dist_fix
Browse files Browse the repository at this point in the history
Print unsigned long long Platform independent
  • Loading branch information
GraciesPadre authored Jul 11, 2017
2 parents 083ef2c + 13c7823 commit 1c10a5c
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 29 deletions.
4 changes: 3 additions & 1 deletion src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,10 @@ add_library(ds3 SHARED
ds3_connection.h ds3_connection.c)

if (WIN32)
#set(WINDOWS_VS_OUTPUT_DIR ${PROJECT_SOURCE_DIR}/win32/src/Debug)
set(CMAKE_BUILD_TYPE Release)
set(WINDOWS_VS_OUTPUT_DIR ${PROJECT_SOURCE_DIR}/win32/src/Release)
#set(CMAKE_BUILD_TYPE Debug)
#set(WINDOWS_VS_OUTPUT_DIR ${PROJECT_SOURCE_DIR}/win32/src/Debug)

set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${WINDOWS_VS_OUTPUT_DIR})
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${WINDOWS_VS_OUTPUT_DIR})
Expand Down
28 changes: 16 additions & 12 deletions src/ds3_init_requests.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,16 @@
#include "ds3_request.h"
#include "ds3_net.h"

//The max size of an uint32_t should be 10 characters + NULL
static const char UNSIGNED_LONG_BASE_10[] = "4294967296";
static const unsigned int UNSIGNED_LONG_BASE_10_STR_LEN = sizeof(UNSIGNED_LONG_BASE_10) + 1;
//The max size of an uint64_t should be 20 characters + NULL
static const char UNSIGNED_LONG_LONG_BASE_10[] = "18446744073709551615";
static const unsigned int UNSIGNED_LONG_LONG_BASE_10_STR_LEN = sizeof(UNSIGNED_LONG_LONG_BASE_10) + 1;
#ifdef _WIN32
#include <io.h>
#ifndef PRIu64
#define PRIu64 "I64u"
#endif
#else
#include <inttypes.h>
#endif

#define STRING_BUFFER_SIZE 32

static char* _get_ds3_bucket_acl_permission_str(ds3_bucket_acl_permission input) {
if (input == DS3_BUCKET_ACL_PERMISSION_LIST) {
Expand Down Expand Up @@ -857,23 +861,23 @@ static void _set_query_param_flag(const ds3_request* _request, const char* key,
}

static void _set_query_param_uint64_t(const ds3_request* _request, const char* key, uint64_t value) {
char string_buffer[UNSIGNED_LONG_LONG_BASE_10_STR_LEN];
char string_buffer[STRING_BUFFER_SIZE];
memset(string_buffer, 0, sizeof(string_buffer));
snprintf(string_buffer, sizeof(string_buffer), "%" PRIu64, value);
g_snprintf(string_buffer, sizeof(string_buffer), "%" PRIu64, value);
_set_query_param(_request, key, string_buffer);
}

static void _set_query_param_int(const ds3_request* _request, const char* key, int value) {
char string_buffer[UNSIGNED_LONG_BASE_10_STR_LEN];
char string_buffer[STRING_BUFFER_SIZE];
memset(string_buffer, 0, sizeof(string_buffer));
snprintf(string_buffer, sizeof(string_buffer), "%d", value);
g_snprintf(string_buffer, sizeof(string_buffer), "%d", value);
_set_query_param(_request, key, string_buffer);
}

static void _set_query_param_float(const ds3_request* _request, const char* key, float value) {
char string_buffer[UNSIGNED_LONG_BASE_10_STR_LEN];
char string_buffer[STRING_BUFFER_SIZE];
memset(string_buffer, 0, sizeof(string_buffer));
snprintf(string_buffer, sizeof(string_buffer), "%f", value);
g_snprintf(string_buffer, sizeof(string_buffer), "%f", value);
_set_query_param(_request, key, string_buffer);
}

Expand Down
26 changes: 13 additions & 13 deletions src/ds3_requests.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,19 +28,18 @@
#include "ds3_utils.h"

#ifdef _WIN32
#include <io.h>
#include <io.h>
#ifndef PRIu64
#define PRIu64 "I64u"
#endif
#else
#include <inttypes.h>
#include <inttypes.h>
#endif


//The max size of an uint32_t should be 10 characters + NULL
static const char UNSIGNED_LONG_BASE_10[] = "4294967296";
static const unsigned int UNSIGNED_LONG_BASE_10_STR_LEN = sizeof(UNSIGNED_LONG_BASE_10) + 1;
//The max size of an uint64_t should be 20 characters + NULL
static const char UNSIGNED_LONG_LONG_BASE_10[] = "18446744073709551615";
static const unsigned int UNSIGNED_LONG_LONG_BASE_10_STR_LEN = sizeof(UNSIGNED_LONG_LONG_BASE_10) + 1;

//The max size of an uint32_t is 10 characters + NULL
//The max size of an uint64_t is 20 characters + NULL
#define STRING_BUFFER_SIZE 32


struct _ds3_metadata {
Expand Down Expand Up @@ -408,7 +407,7 @@ static ds3_error* _get_request_xml_nodes(
}

static xmlDocPtr _generate_xml_bulk_objects_list(const ds3_bulk_object_list_response* obj_list, object_list_type list_type, ds3_job_chunk_client_processing_order_guarantee order) {
char size_buff[UNSIGNED_LONG_LONG_BASE_10_STR_LEN];
char size_buff[STRING_BUFFER_SIZE];
xmlDocPtr doc;
ds3_bulk_object_response* obj;
xmlNodePtr objects_node, object_node;
Expand All @@ -431,7 +430,8 @@ static xmlDocPtr _generate_xml_bulk_objects_list(const ds3_bulk_object_list_resp

for (obj_index = 0; obj_index < obj_list->num_objects; obj_index++) {
obj = obj_list->objects[obj_index];
g_snprintf(size_buff, sizeof(char) * UNSIGNED_LONG_LONG_BASE_10_STR_LEN, "%" PRIu64, obj->length);
memset(size_buff, 0, sizeof(size_buff));
g_snprintf(size_buff, STRING_BUFFER_SIZE, "%" PRIu64, obj->length);

object_node = xmlNewNode(NULL, (xmlChar*) "Object");
xmlAddChild(objects_node, object_node);
Expand All @@ -448,7 +448,7 @@ static xmlDocPtr _generate_xml_bulk_objects_list(const ds3_bulk_object_list_resp
}

static xmlDocPtr _generate_xml_complete_mpu(const ds3_complete_multipart_upload_response* mpu_list) {
char size_buff[UNSIGNED_LONG_LONG_BASE_10_STR_LEN];
char size_buff[STRING_BUFFER_SIZE];
xmlDocPtr doc;
ds3_multipart_upload_part_response* part;
xmlNodePtr parts_node, part_node;
Expand All @@ -464,7 +464,7 @@ static xmlDocPtr _generate_xml_complete_mpu(const ds3_complete_multipart_upload_
part_node = xmlNewNode(NULL, (xmlChar*) "Part");
xmlAddChild(parts_node, part_node);

g_snprintf(size_buff, sizeof(char) * UNSIGNED_LONG_LONG_BASE_10_STR_LEN, "%d", part->part_number);
g_snprintf(size_buff, STRING_BUFFER_SIZE, "%d", part->part_number);
xmlNewTextChild(part_node, NULL, (xmlChar*) "PartNumber", (xmlChar*) size_buff);

xmlNewTextChild(part_node, NULL, (xmlChar*) "ETag", (xmlChar*) part->etag->value);
Expand Down
20 changes: 17 additions & 3 deletions test/bucket_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,23 @@

#include <stdio.h>
#include "ds3.h"
#include "ds3_request.h"
#include "test.h"
#include <boost/test/unit_test.hpp>
#include <glib.h>
#include <limits.h>

BOOST_AUTO_TEST_CASE( init_put_object_offset_unsigned_long_long ) {
printf("-----Testing init PUT_OBJECT with max unsigned long long offset-------\n");

struct _ds3_request* request = ds3_init_put_object_request("Test_bucket", "test_object", 1024 * 1024);
ds3_request_set_offset(request, ULLONG_MAX);

char* value = (char*)g_hash_table_lookup(request->query_params, "offset");
printf(" request->query_params[\"offset\"]:%s\n", value);
BOOST_CHECK(value != NULL);
BOOST_CHECK(g_strcmp0(value, "18446744073709551615") == 0);
}

BOOST_AUTO_TEST_CASE( bulk_put ) {
printf("-----Testing Bulk PUT-------\n");
Expand Down Expand Up @@ -63,15 +77,15 @@ BOOST_AUTO_TEST_CASE( empty_folder ) {
const char* objects[1] = {"empty-folder/"};
ds3_bulk_object_list_response* object_list = ds3_convert_object_list_from_strings(objects, 1);
ds3_request* request = ds3_init_put_bulk_job_spectra_s3_request(bucket_name, object_list);
ds3_master_object_list_response* bulk_response = NULL;
ds3_master_object_list_response* bulk_response;
error = ds3_put_bulk_job_spectra_s3_request(client, request, &bulk_response);
handle_error(error);
ds3_master_object_list_response_free(bulk_response);

request = ds3_init_put_object_request(bucket_name, objects[0], 0);
ds3_request_set_job(request, bulk_response->job_id->value);
error = ds3_put_object_request(client, request, NULL, NULL);
error = ds3_put_object_request(client, request, NULL, NULL);
ds3_request_free(request);
ds3_master_object_list_response_free(bulk_response);
handle_error(error);

ds3_list_bucket_result_response* response;
Expand Down

0 comments on commit 1c10a5c

Please sign in to comment.