Fix ICC warnings
[alexxy/gromacs.git] / src / external / tng_io / src / lib / tng_io.c
index 001521b6c0efe32888d3dae45c12a5555b254489..7702d23846c5d12cd5aa2351c0a7a4fe2a4f193e 100644 (file)
@@ -9,6 +9,14 @@
  * modify it under the terms of the Revised BSD License.
  */
 
+#define _FILE_OFFSET_BITS 64
+/* Define to 1 to make fseeko visible on some hosts (e.g. glibc 2.2). */
+#define _LARGEFILE_SOURCE
+/* Define for large files, on AIX-style hosts. */
+#define _LARGE_FILES
+
+#include "tng/tng_io.h"
+
 #ifdef USE_STD_INTTYPES_H
 #include <inttypes.h>
 #endif
 #include <zlib.h>
 #endif
 
-#include "tng/tng_io.h"
 #include "tng/md5.h"
 #include "compression/tng_compress.h"
 #include "tng/version.h"
 
+#if defined( _WIN32 ) || defined( _WIN64 )
+    #ifndef fseeko
+        #define fseeko _fseeki64
+    #endif
+    #ifndef ftello
+        #ifdef __MINGW32__
+            #define ftello ftello64
+        #else
+            #define ftello _ftelli64
+        #endif
+    #endif
+#endif
 
 struct tng_bond {
     /** One of the atoms of the bond */
@@ -260,7 +279,7 @@ struct tng_trajectory {
     /** A handle to the input file */
     FILE *input_file;
     /** The length of the input file */
-    long input_file_len;
+    int64_t input_file_len;
     /** The path of the output trajectory file */
     char *output_file_path;
     /** A handle to the output file */
@@ -345,9 +364,9 @@ struct tng_trajectory {
     /** The currently active frame set */
     struct tng_trajectory_frame_set current_trajectory_frame_set;
     /** The pos in the src file of the current frame set */
-    long current_trajectory_frame_set_input_file_pos;
+    int64_t current_trajectory_frame_set_input_file_pos;
     /** The pos in the dest file of the current frame set */
-    long current_trajectory_frame_set_output_file_pos;
+    int64_t current_trajectory_frame_set_output_file_pos;
     /** The number of frame sets in the trajectory N.B. Not saved in file and
      *  cannot be trusted to be up-to-date */
     int64_t n_trajectory_frame_sets;
@@ -732,7 +751,7 @@ static tng_function_status tng_block_init(struct tng_gen_block **block_p)
     *block_p = malloc(sizeof(struct tng_gen_block));
     if(!*block_p)
     {
-        fprintf(stderr, "TNG library: Cannot allocate memory (%lu bytes). %s: %d\n",
+        fprintf(stderr, "TNG library: Cannot allocate memory (%"TNG_PRIsize" bytes). %s: %d\n",
                sizeof(struct tng_gen_block), __FILE__, __LINE__);
         return(TNG_CRITICAL);
     }
@@ -801,7 +820,8 @@ static tng_function_status tng_block_destroy(struct tng_gen_block **block_p)
 static tng_function_status tng_block_header_read
                 (tng_trajectory_t tng_data, tng_gen_block_t block)
 {
-    int len, offset = 0;
+    int len;
+    int64_t offset = 0;
 
     TNG_ASSERT(block != 0, "TNG library: Trying to read to uninitialized block (NULL pointer).");
 
@@ -826,7 +846,7 @@ static tng_function_status tng_block_header_read
     }
 
     /* If this was the size of the general info block check the endianness */
-    if(ftell(tng_data->input_file) < 9)
+    if(ftello(tng_data->input_file) < 9)
     {
         /* File is little endian */
         if ( *((const char*)&block->header_contents_size) != 0x00 &&
@@ -893,8 +913,8 @@ static tng_function_status tng_block_header_read
     }
 
     /* Move the reading position to the beginning of the header. */
-    fseek(tng_data->input_file, -(long)sizeof(block->header_contents_size),
-          SEEK_CUR);
+    fseeko(tng_data->input_file, -(int64_t)sizeof(block->header_contents_size),
+           SEEK_CUR);
 
     /* If there is already memory allocated for the contents free it (we do not
      * know if the size is correct). */
@@ -1061,7 +1081,7 @@ static tng_function_status tng_md5_hash_update(tng_trajectory_t tng_data,
         return(TNG_CRITICAL);
     }
 
-    fseek(tng_data->output_file, (long)contents_start_pos, SEEK_SET);
+    fseeko(tng_data->output_file, contents_start_pos, SEEK_SET);
     if(fread(block->block_contents, block->block_contents_size, 1,
             tng_data->output_file) == 0)
     {
@@ -1071,7 +1091,7 @@ static tng_function_status tng_md5_hash_update(tng_trajectory_t tng_data,
 
     tng_block_md5_hash_generate(block);
 
-    fseek(tng_data->output_file, (long)header_start_pos + 3 * sizeof(int64_t),
+    fseeko(tng_data->output_file, header_start_pos + 3 * sizeof(int64_t),
           SEEK_SET);
     fwrite(block->md5_hash, TNG_MD5_HASH_LEN, 1, tng_data->output_file);
 
@@ -1104,8 +1124,8 @@ static tng_function_status tng_header_pointers_update
 
     tng_block_init(&block);
 
-    output_file_pos = ftell(tng_data->output_file);
-    fseek(tng_data->output_file, 0, SEEK_SET);
+    output_file_pos = ftello(tng_data->output_file);
+    fseeko(tng_data->output_file, 0, SEEK_SET);
 
     if(tng_block_header_read(tng_data, block) != TNG_SUCCESS)
     {
@@ -1116,9 +1136,9 @@ static tng_function_status tng_header_pointers_update
         return(TNG_CRITICAL);
     }
 
-    contents_start_pos = ftell(tng_data->output_file);
+    contents_start_pos = ftello(tng_data->output_file);
 
-    fseek(tng_data->output_file, (long)block->block_contents_size - 5 *
+    fseeko(tng_data->output_file, block->block_contents_size - 5 *
           sizeof(int64_t), SEEK_CUR);
 
     tng_data->input_file = temp;
@@ -1169,7 +1189,7 @@ static tng_function_status tng_header_pointers_update
 
     tng_block_destroy(&block);
 
-    fseek(tng_data->output_file, (long)output_file_pos, SEEK_SET);
+    fseeko(tng_data->output_file, output_file_pos, SEEK_SET);
 
     return(TNG_SUCCESS);
 }
@@ -1199,7 +1219,7 @@ static tng_function_status tng_frame_set_pointers_update
     }
 
     tng_block_init(&block);
-    output_file_pos = ftell(tng_data->output_file);
+    output_file_pos = ftello(tng_data->output_file);
 
     tng_data->input_file = tng_data->output_file;
 
@@ -1210,7 +1230,7 @@ static tng_function_status tng_frame_set_pointers_update
     /* Update next frame set */
     if(frame_set->next_frame_set_file_pos > 0)
     {
-        fseek(tng_data->output_file, (long)frame_set->next_frame_set_file_pos,
+        fseeko(tng_data->output_file, frame_set->next_frame_set_file_pos,
               SEEK_SET);
 
         if(tng_block_header_read(tng_data, block) != TNG_SUCCESS)
@@ -1222,9 +1242,9 @@ static tng_function_status tng_frame_set_pointers_update
             return(TNG_CRITICAL);
         }
 
-        contents_start_pos = ftell(tng_data->output_file);
+        contents_start_pos = ftello(tng_data->output_file);
 
-        fseek(tng_data->output_file, (long)block->block_contents_size - (5 *
+        fseeko(tng_data->output_file, block->block_contents_size - (5 *
             sizeof(int64_t) + 2 * sizeof(double)), SEEK_CUR);
 
         if(tng_data->input_endianness_swap_func_64)
@@ -1250,12 +1270,12 @@ static tng_function_status tng_frame_set_pointers_update
             tng_md5_hash_update(tng_data, block, frame_set->next_frame_set_file_pos,
                                 contents_start_pos);
         }
-        fseek(tng_data->output_file, (long)output_file_pos, SEEK_SET);
+        fseeko(tng_data->output_file, output_file_pos, SEEK_SET);
     }
     /* Update previous frame set */
     if(frame_set->prev_frame_set_file_pos > 0)
     {
-        fseek(tng_data->output_file, (long)frame_set->prev_frame_set_file_pos,
+        fseeko(tng_data->output_file, frame_set->prev_frame_set_file_pos,
               SEEK_SET);
 
         if(tng_block_header_read(tng_data, block) != TNG_SUCCESS)
@@ -1267,9 +1287,9 @@ static tng_function_status tng_frame_set_pointers_update
             return(TNG_CRITICAL);
         }
 
-        contents_start_pos = ftell(tng_data->output_file);
+        contents_start_pos = ftello(tng_data->output_file);
 
-        fseek(tng_data->output_file, (long)block->block_contents_size - (6 *
+        fseeko(tng_data->output_file, block->block_contents_size - (6 *
             sizeof(int64_t) + 2 * sizeof(double)), SEEK_CUR);
 
         if(tng_data->input_endianness_swap_func_64)
@@ -1295,15 +1315,15 @@ static tng_function_status tng_frame_set_pointers_update
             tng_md5_hash_update(tng_data, block, frame_set->prev_frame_set_file_pos,
                                 contents_start_pos);
         }
-        fseek(tng_data->output_file, (long)output_file_pos, SEEK_SET);
+        fseeko(tng_data->output_file, output_file_pos, SEEK_SET);
     }
 
     /* Update the frame set one medium stride step after */
     if(frame_set->medium_stride_next_frame_set_file_pos > 0)
     {
-        fseek(tng_data->output_file,
-              (long)frame_set->medium_stride_next_frame_set_file_pos,
-              SEEK_SET);
+        fseeko(tng_data->output_file,
+               frame_set->medium_stride_next_frame_set_file_pos,
+               SEEK_SET);
 
         if(tng_block_header_read(tng_data, block) != TNG_SUCCESS)
         {
@@ -1314,9 +1334,9 @@ static tng_function_status tng_frame_set_pointers_update
             return(TNG_CRITICAL);
         }
 
-        contents_start_pos = ftell(tng_data->output_file);
+        contents_start_pos = ftello(tng_data->output_file);
 
-        fseek(tng_data->output_file, (long)block->block_contents_size - (3 *
+        fseeko(tng_data->output_file, block->block_contents_size - (3 *
             sizeof(int64_t) + 2 * sizeof(double)), SEEK_CUR);
 
         if(tng_data->input_endianness_swap_func_64)
@@ -1347,9 +1367,9 @@ static tng_function_status tng_frame_set_pointers_update
     /* Update the frame set one medium stride step before */
     if(frame_set->medium_stride_prev_frame_set_file_pos > 0)
     {
-        fseek(tng_data->output_file,
-              (long)frame_set->medium_stride_prev_frame_set_file_pos,
-              SEEK_SET);
+        fseeko(tng_data->output_file,
+               frame_set->medium_stride_prev_frame_set_file_pos,
+               SEEK_SET);
 
         if(tng_block_header_read(tng_data, block) != TNG_SUCCESS)
         {
@@ -1360,9 +1380,9 @@ static tng_function_status tng_frame_set_pointers_update
             return(TNG_CRITICAL);
         }
 
-        contents_start_pos = ftell(tng_data->output_file);
+        contents_start_pos = ftello(tng_data->output_file);
 
-        fseek(tng_data->output_file, (long)block->block_contents_size - (4 *
+        fseeko(tng_data->output_file, block->block_contents_size - (4 *
             sizeof(int64_t) + 2 * sizeof(double)), SEEK_CUR);
 
         if(tng_data->input_endianness_swap_func_64)
@@ -1394,9 +1414,9 @@ static tng_function_status tng_frame_set_pointers_update
     /* Update the frame set one long stride step after */
     if(frame_set->long_stride_next_frame_set_file_pos > 0)
     {
-        fseek(tng_data->output_file,
-              (long)frame_set->long_stride_next_frame_set_file_pos,
-              SEEK_SET);
+        fseeko(tng_data->output_file,
+               frame_set->long_stride_next_frame_set_file_pos,
+               SEEK_SET);
 
         if(tng_block_header_read(tng_data, block) != TNG_SUCCESS)
         {
@@ -1407,10 +1427,10 @@ static tng_function_status tng_frame_set_pointers_update
             return(TNG_CRITICAL);
         }
 
-        contents_start_pos = ftell(tng_data->output_file);
+        contents_start_pos = ftello(tng_data->output_file);
 
-        fseek(tng_data->output_file, (long)block->block_contents_size - (1 *
-            sizeof(int64_t) + 2 * sizeof(double)), SEEK_CUR);
+        fseeko(tng_data->output_file, block->block_contents_size - (1 *
+               sizeof(int64_t) + 2 * sizeof(double)), SEEK_CUR);
 
         if(tng_data->input_endianness_swap_func_64)
         {
@@ -1440,9 +1460,9 @@ static tng_function_status tng_frame_set_pointers_update
     /* Update the frame set one long stride step before */
     if(frame_set->long_stride_prev_frame_set_file_pos > 0)
     {
-        fseek(tng_data->output_file,
-              (long)frame_set->long_stride_prev_frame_set_file_pos,
-              SEEK_SET);
+        fseeko(tng_data->output_file,
+               frame_set->long_stride_prev_frame_set_file_pos,
+               SEEK_SET);
 
         if(tng_block_header_read(tng_data, block) != TNG_SUCCESS)
         {
@@ -1453,9 +1473,9 @@ static tng_function_status tng_frame_set_pointers_update
             return(TNG_CRITICAL);
         }
 
-        contents_start_pos = ftell(tng_data->output_file);
+        contents_start_pos = ftello(tng_data->output_file);
 
-        fseek(tng_data->output_file, (long)block->block_contents_size - (2 *
+        fseeko(tng_data->output_file, block->block_contents_size - (2 *
             sizeof(int64_t) + 2 * sizeof(double)), SEEK_CUR);
 
         if(tng_data->input_endianness_swap_func_64)
@@ -1484,7 +1504,7 @@ static tng_function_status tng_frame_set_pointers_update
         }
     }
 
-    fseek(tng_data->output_file, (long)output_file_pos, SEEK_SET);
+    fseeko(tng_data->output_file, output_file_pos, SEEK_SET);
 
     tng_data->input_file = temp;
 
@@ -1502,7 +1522,7 @@ static tng_function_status tng_reread_frame_set_at_file_pos
 
     tng_block_init(&block);
 
-    fseek(tng_data->input_file, pos, SEEK_SET);
+    fseeko(tng_data->input_file, pos, SEEK_SET);
     if(pos > 0)
     {
         stat = tng_block_header_read(tng_data, block);
@@ -1537,7 +1557,7 @@ static tng_function_status tng_file_pos_of_subsequent_trajectory_block_get
     tng_trajectory_frame_set_t frame_set =
     &tng_data->current_trajectory_frame_set;
 
-    orig_pos = ftell(tng_data->input_file);
+    orig_pos = ftello(tng_data->input_file);
     curr_frame_set_pos = tng_data->current_trajectory_frame_set_input_file_pos;
 
     *pos = tng_data->first_trajectory_frame_set_input_file_pos;
@@ -1547,7 +1567,7 @@ static tng_function_status tng_file_pos_of_subsequent_trajectory_block_get
         return(TNG_SUCCESS);
     }
 
-    fseek(tng_data->input_file, *pos, SEEK_SET);
+    fseeko(tng_data->input_file, *pos, SEEK_SET);
 
     tng_block_init(&block);
     /* Read block headers first to see that a frame set block is found. */
@@ -1570,7 +1590,7 @@ static tng_function_status tng_file_pos_of_subsequent_trajectory_block_get
     /* Read all frame set blocks (not the blocks between them) */
     while(frame_set->next_frame_set_file_pos > 0)
     {
-        fseek(tng_data->input_file, frame_set->next_frame_set_file_pos, SEEK_SET);
+        fseeko(tng_data->input_file, frame_set->next_frame_set_file_pos, SEEK_SET);
         stat = tng_block_header_read(tng_data, block);
         if(stat == TNG_CRITICAL)
         {
@@ -1601,7 +1621,7 @@ static tng_function_status tng_file_pos_of_subsequent_trajectory_block_get
     /* Re-read the frame set that used to be the current one */
     tng_reread_frame_set_at_file_pos(tng_data, curr_frame_set_pos);
 
-    fseek(tng_data->input_file, orig_pos, SEEK_SET);
+    fseeko(tng_data->input_file, orig_pos, SEEK_SET);
 
     tng_block_destroy(&block);
 
@@ -1624,7 +1644,7 @@ static tng_function_status tng_frame_set_complete_migrate
         return(TNG_CRITICAL);
     }
 
-    fseek(tng_data->input_file, block_start_pos, SEEK_SET);
+    fseeko(tng_data->input_file, block_start_pos, SEEK_SET);
 
     contents = malloc(block_len);
     if(!contents)
@@ -1641,7 +1661,7 @@ static tng_function_status tng_frame_set_complete_migrate
         free(contents);
         return(TNG_CRITICAL);
     }
-    fseek(tng_data->output_file, new_pos, SEEK_SET);
+    fseeko(tng_data->output_file, new_pos, SEEK_SET);
 
     if(fwrite(contents, block_len, 1, tng_data->output_file) != 1)
     {
@@ -1676,7 +1696,7 @@ static tng_function_status tng_frame_set_complete_migrate
     {
         contents[i] = '\0';
     }
-    fseek(tng_data->output_file, block_start_pos, SEEK_SET);
+    fseeko(tng_data->output_file, block_start_pos, SEEK_SET);
 
     /* FIXME: casting block_len to size_t is dangerous */
     fwrite(contents, 1, block_len, tng_data->output_file);
@@ -1694,12 +1714,12 @@ static tng_function_status tng_length_of_current_frame_set_contents_get
     tng_gen_block_t block;
     tng_function_status stat;
 
-    orig_pos = ftell(tng_data->input_file);
+    orig_pos = ftello(tng_data->input_file);
     curr_frame_set_pos = pos = tng_data->current_trajectory_frame_set_input_file_pos;
 
     *len = 0;
 
-    fseek(tng_data->input_file, curr_frame_set_pos, SEEK_SET);
+    fseeko(tng_data->input_file, curr_frame_set_pos, SEEK_SET);
 
     tng_block_init(&block);
     /* Read block headers first to see that a frame set block is found. */
@@ -1715,7 +1735,7 @@ static tng_function_status tng_length_of_current_frame_set_contents_get
     /* Read the headers of all blocks in the frame set (not the actual contents of them) */
     while(stat == TNG_SUCCESS)
     {
-        fseek(tng_data->input_file, block->block_contents_size, SEEK_CUR);
+        fseeko(tng_data->input_file, block->block_contents_size, SEEK_CUR);
         *len += block->header_contents_size + block->block_contents_size;
         pos += block->header_contents_size + block->block_contents_size;
         if(pos >= tng_data->input_file_len)
@@ -1732,7 +1752,7 @@ static tng_function_status tng_length_of_current_frame_set_contents_get
     /* Re-read the frame set that used to be the current one */
     tng_reread_frame_set_at_file_pos(tng_data, curr_frame_set_pos);
 
-    fseek(tng_data->input_file, orig_pos, SEEK_SET);
+    fseeko(tng_data->input_file, orig_pos, SEEK_SET);
 
     tng_block_destroy(&block);
 
@@ -1783,12 +1803,12 @@ static tng_function_status tng_migrate_data_in_file
         return(TNG_SUCCESS);
     }
 
-    orig_file_pos = ftell(tng_data->input_file);
+    orig_file_pos = ftello(tng_data->input_file);
     tng_block_init(&block);
 
     while(empty_space < offset)
     {
-        fseek(tng_data->input_file, traj_start_pos, SEEK_SET);
+        fseeko(tng_data->input_file, traj_start_pos, SEEK_SET);
         stat = tng_block_header_read(tng_data, block);
         if(stat == TNG_CRITICAL)
         {
@@ -1822,7 +1842,7 @@ static tng_function_status tng_migrate_data_in_file
 
         empty_space += frame_set_length;
     }
-    fseek(tng_data->input_file, orig_file_pos, SEEK_SET);
+    fseeko(tng_data->input_file, orig_file_pos, SEEK_SET);
     tng_block_destroy(&block);
 
     return(TNG_SUCCESS);
@@ -2410,7 +2430,7 @@ static tng_function_status tng_general_info_block_read
     if(tng_data->input_endianness_swap_func_64)
     {
         if(tng_data->input_endianness_swap_func_64(tng_data,
-                                                 &tng_data->long_stride_length)
+                                                   &tng_data->long_stride_length)
             != TNG_SUCCESS)
         {
             fprintf(stderr, "TNG library: Cannot swap byte order. %s: %d\n",
@@ -2462,7 +2482,7 @@ static tng_function_status tng_general_info_block_write
         return(TNG_CRITICAL);
     }
 
-    fseek(tng_data->output_file, 0, SEEK_SET);
+    fseeko(tng_data->output_file, 0, SEEK_SET);
 
     tng_block_init(&block);
 
@@ -3202,7 +3222,7 @@ static tng_function_status tng_molecules_block_read
                           sizeof(struct tng_molecule));
     if(!tng_data->molecules)
     {
-        fprintf(stderr, "TNG library: Cannot allocate memory (%"PRId64" bytes). %s: %d\n",
+        fprintf(stderr, "TNG library: Cannot allocate memory (%"PRIu64" bytes). %s: %d\n",
                tng_data->n_molecules * sizeof(struct tng_molecule),
                __FILE__, __LINE__);
         return(TNG_CRITICAL);
@@ -3218,7 +3238,7 @@ static tng_function_status tng_molecules_block_read
                                       tng_data->n_molecules);
         if(!tng_data->molecule_cnt_list)
         {
-            fprintf(stderr, "TNG library: Cannot allocate memory (%"PRId64" bytes). %s: %d\n",
+            fprintf(stderr, "TNG library: Cannot allocate memory (%"PRIu64" bytes). %s: %d\n",
                    tng_data->n_molecules * sizeof(struct tng_molecule),
                    __FILE__, __LINE__);
             return(TNG_CRITICAL);
@@ -3334,7 +3354,7 @@ static tng_function_status tng_molecules_block_read
                                     sizeof(struct tng_chain));
             if(!molecule->chains)
             {
-                fprintf(stderr, "TNG library: Cannot allocate memory (%"PRId64" bytes). %s: %d\n",
+                fprintf(stderr, "TNG library: Cannot allocate memory (%"PRIu64" bytes). %s: %d\n",
                     molecule->n_chains * sizeof(struct tng_chain),
                     __FILE__, __LINE__);
                 return(TNG_CRITICAL);
@@ -3353,7 +3373,7 @@ static tng_function_status tng_molecules_block_read
                                 sizeof(struct tng_residue));
             if(!molecule->residues)
             {
-                fprintf(stderr, "TNG library: Cannot allocate memory (%"PRId64" bytes). %s: %d\n",
+                fprintf(stderr, "TNG library: Cannot allocate memory (%"PRIu64" bytes). %s: %d\n",
                     molecule->n_residues * sizeof(struct tng_residue),
                     __FILE__, __LINE__);
                 if(molecule->chains)
@@ -3375,7 +3395,7 @@ static tng_function_status tng_molecules_block_read
                                  sizeof(struct tng_atom));
         if(!molecule->atoms)
         {
-            fprintf(stderr, "TNG library: Cannot allocate memory (%"PRId64" bytes). %s: %d\n",
+            fprintf(stderr, "TNG library: Cannot allocate memory (%"PRIu64" bytes). %s: %d\n",
                    molecule->n_atoms * sizeof(struct tng_atom),
                    __FILE__, __LINE__);
             if(molecule->chains)
@@ -3483,7 +3503,7 @@ static tng_function_status tng_molecules_block_read
                                            sizeof(struct tng_bond));
             if(!molecule->bonds)
             {
-                fprintf(stderr, "TNG library: Cannot allocate memory (%"PRId64" bytes). %s: %d\n",
+                fprintf(stderr, "TNG library: Cannot allocate memory (%"PRIu64" bytes). %s: %d\n",
                        molecule->n_bonds * sizeof(struct tng_bond),
                        __FILE__, __LINE__);
                 if(molecule->chains)
@@ -3870,9 +3890,8 @@ static tng_function_status tng_frame_set_block_read
                  tng_gen_block_t block,
                  const char hash_mode)
 {
-    long file_pos;
     int offset = 0;
-    int64_t i, prev_n_particles;
+    int64_t file_pos, i, prev_n_particles;
     tng_bool same_hash;
     tng_trajectory_frame_set_t frame_set =
     &tng_data->current_trajectory_frame_set;
@@ -3907,15 +3926,15 @@ static tng_function_status tng_frame_set_block_read
     /* FIXME: Does not check if the size of the contents matches the expected
      * size or if the contents can be read. */
 
-    file_pos = (int64_t)ftell(tng_data->input_file) -
-               (long)(block->block_contents_size + block->header_contents_size);
+    file_pos = (int64_t)ftello(tng_data->input_file) -
+               (block->block_contents_size + block->header_contents_size);
 
     if(hash_mode == TNG_USE_HASH)
     {
         tng_md5_hash_match_verify(block, &same_hash);
         if(same_hash != TNG_TRUE)
         {
-            fprintf(stderr, "TNG library: Frame set block contents corrupt. File pos %ld Hashes do not match. "
+            fprintf(stderr, "TNG library: Frame set block contents corrupt. File pos %"PRId64" Hashes do not match. "
                 "%s: %d\n",
                 file_pos, __FILE__, __LINE__);
     /*         return(TNG_FAILURE); */
@@ -3978,7 +3997,7 @@ static tng_function_status tng_frame_set_block_read
 
                 if(!frame_set->molecule_cnt_list)
                 {
-                    fprintf(stderr, "TNG library: Cannot allocate memory (%"PRId64" bytes). %s: %d\n",
+                    fprintf(stderr, "TNG library: Cannot allocate memory (%"PRIu64" bytes). %s: %d\n",
                            sizeof(int64_t) * tng_data->n_molecules,
                            __FILE__, __LINE__);
                     return(TNG_CRITICAL);
@@ -4180,7 +4199,7 @@ static tng_function_status tng_frame_set_block_write
         temp_name = realloc(block->name, name_len + 1);
         if(!temp_name)
         {
-            fprintf(stderr, "TNG library: Cannot allocate memory (%d bytes). %s: %d\n",
+            fprintf(stderr, "TNG library: Cannot allocate memory (%u bytes). %s: %d\n",
                    name_len+1, __FILE__, __LINE__);
             free(block->name);
             block->name = 0;
@@ -4519,7 +4538,7 @@ static tng_function_status tng_trajectory_mapping_block_read
                                             sizeof(int64_t));
     if(!mapping->real_particle_numbers)
     {
-        fprintf(stderr, "TNG library: Cannot allocate memory (%"PRId64" bytes). %s: %d\n",
+        fprintf(stderr, "TNG library: Cannot allocate memory (%"PRIu64" bytes). %s: %d\n",
                 mapping->n_particles * sizeof(int64_t), __FILE__, __LINE__);
         return(TNG_CRITICAL);
     }
@@ -4595,7 +4614,7 @@ static tng_function_status tng_trajectory_mapping_block_write
         temp_name = realloc(block->name, name_len + 1);
         if(!temp_name)
         {
-            fprintf(stderr, "TNG library: Cannot allocate memory (%d bytes). %s: %d\n",
+            fprintf(stderr, "TNG library: Cannot allocate memory (%u bytes). %s: %d\n",
                    name_len+1, __FILE__, __LINE__);
             free(block->name);
             block->name = 0;
@@ -4720,7 +4739,7 @@ static tng_function_status tng_particle_data_block_create
                     frame_set->n_particle_data_blocks);
         if(!data)
         {
-            fprintf(stderr, "TNG library: Cannot allocate memory (%lu bytes). %s: %d\n",
+            fprintf(stderr, "TNG library: Cannot allocate memory (%"TNG_PRIsize" bytes). %s: %d\n",
                 sizeof(struct tng_particle_data) *
                 frame_set->n_particle_data_blocks,
                 __FILE__, __LINE__);
@@ -4738,7 +4757,7 @@ static tng_function_status tng_particle_data_block_create
                         tng_data->n_particle_data_blocks);
         if(!data)
         {
-            fprintf(stderr, "TNG library: Cannot allocate memory (%lu bytes). %s: %d\n",
+            fprintf(stderr, "TNG library: Cannot allocate memory (%"TNG_PRIsize" bytes). %s: %d\n",
                     sizeof(struct tng_particle_data) *
                     tng_data->n_particle_data_blocks,
                     __FILE__, __LINE__);
@@ -4763,8 +4782,7 @@ static tng_function_status tng_compress(tng_trajectory_t tng_data,
     int new_len;
     int *alt_algo = 0;
     char *dest, *temp, *temp_data_contents;
-    int64_t algo_find_n_frames, compressed_len;
-    unsigned long offset;
+    int64_t algo_find_n_frames, compressed_len, offset;
     float f_precision;
     double d_precision;
 
@@ -4907,7 +4925,7 @@ static tng_function_status tng_compress(tng_trajectory_t tng_data,
         if(n_frames == 1 && tng_data->frame_set_n_frames > 1)
         {
             nalgo = tng_compress_nalgo();
-            alt_algo=malloc(nalgo * sizeof *tng_data->compress_algo_pos);
+            alt_algo=malloc(nalgo * sizeof *tng_data->compress_algo_vel);
             if(type == TNG_FLOAT_DATA)
             {
                 dest = tng_compress_vel_float_find_algo((float *)temp_data_contents, (int)n_particles,
@@ -5044,12 +5062,13 @@ static tng_function_status tng_uncompress(tng_trajectory_t tng_data,
                                           tng_gen_block_t block,
                                           const char type,
                                           void *start_pos,
-                                          const unsigned long uncompressed_len)
+                                          const int64_t uncompressed_len)
 {
     char *temp, *temp_data_contents;
+    int64_t compressed_len;
     double *d_dest = 0;
     float *f_dest = 0;
-    unsigned long offset;
+    int64_t offset;
     int result;
     (void)tng_data;
 
@@ -5068,22 +5087,23 @@ static tng_function_status tng_uncompress(tng_trajectory_t tng_data,
         return(TNG_FAILURE);
     }
 
-    temp_data_contents = malloc(uncompressed_len);
+    compressed_len = block->block_contents_size - (int64_t)((char *)start_pos - (char *)block->block_contents);
+    temp_data_contents = malloc(compressed_len);
     if(!temp_data_contents)
     {
-        fprintf(stderr, "TNG library: Cannot allocate memory (%lu bytes). %s: %d\n",
+        fprintf(stderr, "TNG library: Cannot allocate memory (%"PRId64" bytes). %s: %d\n",
                 uncompressed_len, __FILE__, __LINE__);
         return(TNG_CRITICAL);
     }
 
-    memcpy(temp_data_contents, (char *)start_pos, uncompressed_len);
+    memcpy(temp_data_contents, (char *)start_pos, compressed_len);
 
     if(type == TNG_FLOAT_DATA)
     {
         f_dest = malloc(uncompressed_len);
         if(!f_dest)
         {
-            fprintf(stderr, "TNG library: Cannot allocate memory (%lu bytes). %s: %d\n",
+            fprintf(stderr, "TNG library: Cannot allocate memory (%"PRId64" bytes). %s: %d\n",
                 uncompressed_len, __FILE__, __LINE__);
             free(temp_data_contents);
             return(TNG_CRITICAL);
@@ -5095,7 +5115,7 @@ static tng_function_status tng_uncompress(tng_trajectory_t tng_data,
         d_dest = malloc(uncompressed_len);
         if(!d_dest)
         {
-            fprintf(stderr, "TNG library: Cannot allocate memory (%lu bytes). %s: %d\n",
+            fprintf(stderr, "TNG library: Cannot allocate memory (%"PRId64" bytes). %s: %d\n",
                 uncompressed_len, __FILE__, __LINE__);
             free(temp_data_contents);
             return(TNG_CRITICAL);
@@ -5170,7 +5190,7 @@ static tng_function_status tng_gzip_compress(tng_trajectory_t tng_data,
     dest = malloc(max_len);
     if(!dest)
     {
-        fprintf(stderr, "TNG library: Cannot allocate memory (%ld bytes). %s: %d\n",
+        fprintf(stderr, "TNG library: Cannot allocate memory (%lu bytes). %s: %d\n",
                max_len, __FILE__, __LINE__);
         return(TNG_CRITICAL);
     }
@@ -5345,7 +5365,7 @@ static tng_function_status tng_allocate_particle_data_mem
                                     n_particles);
             if(!data->strings[i])
             {
-                fprintf(stderr, "TNG library: Cannot allocate memory (%"PRId64" bytes). %s: %d\n",
+                fprintf(stderr, "TNG library: Cannot allocate memory (%"PRIu64" bytes). %s: %d\n",
                     sizeof(union data_values *) * n_particles,
                     __FILE__, __LINE__);
                 return(TNG_CRITICAL);
@@ -5356,7 +5376,7 @@ static tng_function_status tng_allocate_particle_data_mem
                                             n_values_per_frame);
                 if(!data->strings[i][j])
                 {
-                    fprintf(stderr, "TNG library: Cannot allocate memory (%"PRId64" bytes). %s: %d\n",
+                    fprintf(stderr, "TNG library: Cannot allocate memory (%"PRIu64" bytes). %s: %d\n",
                         sizeof(union data_values) * n_values_per_frame,
                         __FILE__, __LINE__);
                     return(TNG_CRITICAL);
@@ -5662,7 +5682,7 @@ static tng_function_status tng_particle_data_read
 {
     int64_t i, j, k, tot_n_particles, n_frames_div;
     int size, len;
-    unsigned long data_size;
+    int64_t data_size;
     char ***first_dim_values, **second_dim_values;
     tng_particle_data_t data;
     tng_trajectory_frame_set_t frame_set =
@@ -5671,6 +5691,16 @@ static tng_function_status tng_particle_data_read
 
     TNG_ASSERT(offset != 0, "TNG library: offset must not be a NULL pointer.");
 
+    /* This must be caught early to avoid creating a data block if not necessary. */
+#ifndef USE_ZLIB
+    if(codec_id == TNG_GZIP_COMPRESSION)
+    {
+        fprintf(stderr, "TNG library: Cannot uncompress data block. %s: %d\n", __FILE__,
+                __LINE__);
+        return(TNG_FAILURE);
+    }
+#endif
+
     switch(datatype)
     {
     case TNG_CHAR_DATA:
@@ -5973,7 +6003,7 @@ static tng_function_status tng_particle_data_block_write
         temp_name = realloc(block->name, len);
         if(!temp_name)
         {
-            fprintf(stderr, "TNG library: Cannot allocate memory (%lud bytes). %s: %d\n", len,
+            fprintf(stderr, "TNG library: Cannot allocate memory (%"TNG_PRIsize" bytes). %s: %d\n", len,
                    __FILE__, __LINE__);
             free(block->name);
             block->name = 0;
@@ -6427,7 +6457,7 @@ static tng_function_status tng_data_block_create
                        frame_set->n_data_blocks);
         if(!data)
         {
-            fprintf(stderr, "TNG library: Cannot allocate memory (%lu bytes). %s: %d\n",
+            fprintf(stderr, "TNG library: Cannot allocate memory (%"TNG_PRIsize" bytes). %s: %d\n",
                 sizeof(struct tng_non_particle_data) * frame_set->n_data_blocks,
                 __FILE__, __LINE__);
             free(frame_set->tr_data);
@@ -6443,7 +6473,7 @@ static tng_function_status tng_data_block_create
                         tng_data->n_data_blocks);
         if(!data)
         {
-            fprintf(stderr, "TNG library: Cannot allocate memory (%lu bytes). %s: %d\n",
+            fprintf(stderr, "TNG library: Cannot allocate memory (%"TNG_PRIsize" bytes). %s: %d\n",
                 sizeof(struct tng_non_particle_data) * tng_data->n_data_blocks,
                 __FILE__, __LINE__);
             free(tng_data->non_tr_data);
@@ -6594,7 +6624,7 @@ static tng_function_status tng_data_read(tng_trajectory_t tng_data,
     int64_t i, j, n_frames_div;
     int size, len;
 #ifdef USE_ZLIB
-    unsigned long data_size;
+    int64_t data_size;
 #endif
     tng_non_particle_data_t data;
     tng_trajectory_frame_set_t frame_set =
@@ -6605,6 +6635,16 @@ static tng_function_status tng_data_read(tng_trajectory_t tng_data,
 
 /*     fprintf(stderr, "TNG library: %s\n", block->name);*/
 
+    /* This must be caught early to avoid creating a data block if not necessary. */
+#ifndef USE_ZLIB
+    if(codec_id == TNG_GZIP_COMPRESSION)
+    {
+        fprintf(stderr, "TNG library: Cannot uncompress data block. %s: %d\n", __FILE__,
+                __LINE__);
+        return(TNG_FAILURE);
+    }
+#endif
+
     switch(datatype)
     {
     case TNG_CHAR_DATA:
@@ -6867,7 +6907,7 @@ static tng_function_status tng_data_block_write(tng_trajectory_t tng_data,
         temp_name = realloc(block->name, len);
         if(!temp_name)
         {
-            fprintf(stderr, "TNG library: Cannot allocate memory (%d bytes). %s: %d\n", len+1,
+            fprintf(stderr, "TNG library: Cannot allocate memory (%u bytes). %s: %d\n", len+1,
                    __FILE__, __LINE__);
             free(block->name);
             block->name = 0;
@@ -7550,13 +7590,13 @@ static tng_function_status tng_data_block_contents_read
 //     }
 //
 //     tng_block_init(&block);
-// //     output_file_pos = ftell(tng_data->output_file);
+// //     output_file_pos = ftello(tng_data->output_file);
 //
 //     tng_data->input_file = tng_data->output_file;
 //
 //     pos = tng_data->current_trajectory_frame_set_output_file_pos;
 //
-//     fseek(tng_data->output_file, pos, SEEK_SET);
+//     fseeko(tng_data->output_file, pos, SEEK_SET);
 //     if(tng_block_header_read(tng_data, block) != TNG_SUCCESS)
 //     {
 //         fprintf(stderr, "TNG library: Cannot read frame set header. %s: %d\n",
@@ -7566,12 +7606,12 @@ static tng_function_status tng_data_block_contents_read
 //         return(TNG_CRITICAL);
 //     }
 //
-//     contents_start_pos = ftell(tng_data->output_file);
+//     contents_start_pos = ftello(tng_data->output_file);
 //
-//     fseek(tng_data->output_file, 0, SEEK_END);
-//     output_file_len = ftell(tng_data->output_file);
+//     fseeko(tng_data->output_file, 0, SEEK_END);
+//     output_file_len = ftello(tng_data->output_file);
 //     pos = contents_start_pos + block->block_contents_size;
-//     fseek(tng_data->output_file, pos,
+//     fseeko(tng_data->output_file, pos,
 //           SEEK_SET);
 //
 //     while(pos < output_file_len)
@@ -7585,7 +7625,7 @@ static tng_function_status tng_data_block_contents_read
 //             return(TNG_CRITICAL);
 //         }
 //         pos += block->header_contents_size + block->block_contents_size;
-//         fseek(tng_data->output_file, pos, SEEK_SET);
+//         fseeko(tng_data->output_file, pos, SEEK_SET);
 //     }
 //
 //     return(TNG_SUCCESS);
@@ -7623,13 +7663,13 @@ static tng_function_status tng_frame_set_finalize
     }
 
     tng_block_init(&block);
-/*     output_file_pos = ftell(tng_data->output_file); */
+/*     output_file_pos = ftello(tng_data->output_file); */
 
     tng_data->input_file = tng_data->output_file;
 
     pos = tng_data->current_trajectory_frame_set_output_file_pos;
 
-    fseek(tng_data->output_file, (long)pos, SEEK_SET);
+    fseeko(tng_data->output_file, pos, SEEK_SET);
 
     if(tng_block_header_read(tng_data, block) != TNG_SUCCESS)
     {
@@ -7640,9 +7680,9 @@ static tng_function_status tng_frame_set_finalize
         return(TNG_CRITICAL);
     }
 
-    contents_start_pos = ftell(tng_data->output_file);
+    contents_start_pos = ftello(tng_data->output_file);
 
-    fseek(tng_data->output_file, sizeof(frame_set->first_frame), SEEK_CUR);
+    fseeko(tng_data->output_file, sizeof(frame_set->first_frame), SEEK_CUR);
     if(fwrite(&frame_set->n_written_frames, sizeof(frame_set->n_frames),
               1, tng_data->output_file) != 1)
     {
@@ -7658,10 +7698,10 @@ static tng_function_status tng_frame_set_finalize
                             pos + block->header_contents_size);
     }
 
-    fseek(tng_data->output_file, 0, SEEK_END);
-    output_file_len = ftell(tng_data->output_file);
+    fseeko(tng_data->output_file, 0, SEEK_END);
+    output_file_len = ftello(tng_data->output_file);
     pos = contents_start_pos + block->block_contents_size;
-    fseek(tng_data->output_file, (long)pos, SEEK_SET);
+    fseeko(tng_data->output_file, pos, SEEK_SET);
 
     while(pos < output_file_len)
     {
@@ -7680,7 +7720,7 @@ static tng_function_status tng_frame_set_finalize
                                 pos + block->header_contents_size);
         }
         pos += block->header_contents_size + block->block_contents_size;
-        fseek(tng_data->output_file, (long)pos, SEEK_SET);
+        fseeko(tng_data->output_file, pos, SEEK_SET);
     }
 
     tng_data->input_file = temp;
@@ -7969,7 +8009,7 @@ tng_function_status DECLSPECDLLEXPORT tng_molecule_w_id_add
 
     if(!new_molecules)
     {
-        fprintf(stderr, "TNG library: Cannot allocate memory (%"PRId64" bytes). %s: %d\n",
+        fprintf(stderr, "TNG library: Cannot allocate memory (%"PRIu64" bytes). %s: %d\n",
                sizeof(struct tng_molecule) * (tng_data->n_molecules + 1),
                __FILE__, __LINE__);
         free(tng_data->molecules);
@@ -7983,7 +8023,7 @@ tng_function_status DECLSPECDLLEXPORT tng_molecule_w_id_add
 
     if(!new_molecule_cnt_list)
     {
-        fprintf(stderr, "TNG library: Cannot allocate memory (%"PRId64" bytes). %s: %d\n",
+        fprintf(stderr, "TNG library: Cannot allocate memory (%"PRIu64" bytes). %s: %d\n",
                sizeof(int64_t) * (tng_data->n_molecules + 1),
                __FILE__, __LINE__);
         free(tng_data->molecule_cnt_list);
@@ -8035,7 +8075,7 @@ tng_function_status DECLSPECDLLEXPORT tng_molecule_existing_add
 
     if(!new_molecules)
     {
-        fprintf(stderr, "TNG library: Cannot allocate memory (%"PRId64" bytes). %s: %d\n",
+        fprintf(stderr, "TNG library: Cannot allocate memory (%"PRIu64" bytes). %s: %d\n",
                sizeof(struct tng_molecule) * (tng_data->n_molecules + 1),
                __FILE__, __LINE__);
         free(tng_data->molecules);
@@ -8049,7 +8089,7 @@ tng_function_status DECLSPECDLLEXPORT tng_molecule_existing_add
 
     if(!new_molecule_cnt_list)
     {
-        fprintf(stderr, "TNG library: Cannot allocate memory (%"PRId64" bytes). %s: %d\n",
+        fprintf(stderr, "TNG library: Cannot allocate memory (%"PRIu64" bytes). %s: %d\n",
                sizeof(int64_t) * (tng_data->n_molecules + 1),
                __FILE__, __LINE__);
         free(tng_data->molecule_cnt_list);
@@ -8280,7 +8320,7 @@ tng_function_status DECLSPECDLLEXPORT tng_molecule_system_copy(tng_trajectory_t
                     sizeof(struct tng_molecule) * tng_data_src->n_molecules);
     if(!molecule_temp)
     {
-        fprintf(stderr, "TNG library: Cannot allocate memory (%"PRId64" bytes). %s: %d\n",
+        fprintf(stderr, "TNG library: Cannot allocate memory (%"PRIu64" bytes). %s: %d\n",
                sizeof(struct tng_molecule) * tng_data_src->n_molecules,
                __FILE__, __LINE__);
         free(tng_data_dest->molecules);
@@ -8291,7 +8331,7 @@ tng_function_status DECLSPECDLLEXPORT tng_molecule_system_copy(tng_trajectory_t
                                      sizeof(int64_t) * tng_data_src->n_molecules);
     if(!list_temp)
     {
-        fprintf(stderr, "TNG library: Cannot allocate memory (%"PRId64" bytes). %s: %d\n",
+        fprintf(stderr, "TNG library: Cannot allocate memory (%"PRIu64" bytes). %s: %d\n",
                sizeof(int64_t) * tng_data_src->n_molecules,
                __FILE__, __LINE__);
         free(tng_data_dest->molecule_cnt_list);
@@ -8355,21 +8395,24 @@ tng_function_status DECLSPECDLLEXPORT tng_molecule_system_copy(tng_trajectory_t
             }
         }
         molecule_temp->n_bonds = molecule->n_bonds;
-        bond_temp = realloc(molecule_temp->bonds, sizeof(struct tng_bond) *
-                            molecule->n_bonds);
-        if(!bond_temp)
-        {
-            fprintf(stderr, "TNG library: Cannot allocate memory (%"PRId64" bytes). %s: %d\n",
-                   sizeof(struct tng_bond) * molecule->n_bonds,
-                   __FILE__, __LINE__);
-            free(molecule_temp->bonds);
-            molecule_temp->n_bonds = 0;
-            return(TNG_CRITICAL);
-        }
-        molecule_temp->bonds = bond_temp;
-        for(j = 0; j < molecule->n_bonds; j++)
+        if(molecule->n_bonds > 0)
         {
-            molecule_temp->bonds[j] = molecule->bonds[j];
+            bond_temp = realloc(molecule_temp->bonds, sizeof(struct tng_bond) *
+                                molecule->n_bonds);
+            if(!bond_temp)
+            {
+                fprintf(stderr, "TNG library: Cannot allocate memory (%"PRIu64" bytes). %s: %d\n",
+                       sizeof(struct tng_bond) * molecule->n_bonds,
+                       __FILE__, __LINE__);
+                free(molecule_temp->bonds);
+                molecule_temp->n_bonds = 0;
+                return(TNG_CRITICAL);
+            }
+            molecule_temp->bonds = bond_temp;
+            for(j = 0; j < molecule->n_bonds; j++)
+            {
+                molecule_temp->bonds[j] = molecule->bonds[j];
+            }
         }
         stat = tng_molecule_cnt_set(tng_data_dest, molecule_temp,
                                     tng_data_src->molecule_cnt_list[i]);
@@ -8558,7 +8601,7 @@ tng_function_status DECLSPECDLLEXPORT tng_molecule_chain_w_id_add
 
     if(!new_chains)
     {
-        fprintf(stderr, "TNG library: Cannot allocate memory (%"PRId64" bytes). %s: %d\n",
+        fprintf(stderr, "TNG library: Cannot allocate memory (%"PRIu64" bytes). %s: %d\n",
                sizeof(struct tng_chain) * (molecule->n_chains + 1),
                __FILE__, __LINE__);
         free(molecule->chains);
@@ -8599,7 +8642,7 @@ tng_function_status DECLSPECDLLEXPORT tng_molecule_bond_add
 
     if(!new_bonds)
     {
-        fprintf(stderr, "TNG library: Cannot allocate memory (%"PRId64" bytes). %s: %d\n",
+        fprintf(stderr, "TNG library: Cannot allocate memory (%"PRIu64" bytes). %s: %d\n",
                sizeof(struct tng_bond) * (molecule->n_bonds + 1),
                __FILE__, __LINE__);
         *bond = 0;
@@ -8824,7 +8867,7 @@ tng_function_status DECLSPECDLLEXPORT tng_chain_residue_w_id_add
 
     if(!new_residues)
     {
-        fprintf(stderr, "TNG library: Cannot allocate memory (%"PRId64" bytes). %s: %d\n",
+        fprintf(stderr, "TNG library: Cannot allocate memory (%"PRIu64" bytes). %s: %d\n",
                sizeof(struct tng_residue) * (molecule->n_residues + 1),
                __FILE__, __LINE__);
         free(molecule->residues);
@@ -9036,7 +9079,7 @@ tng_function_status DECLSPECDLLEXPORT tng_residue_atom_w_id_add
 
     if(!new_atoms)
     {
-        fprintf(stderr, "TNG library: Cannot allocate memory (%"PRId64" bytes). %s: %d\n",
+        fprintf(stderr, "TNG library: Cannot allocate memory (%"PRIu64" bytes). %s: %d\n",
                sizeof(struct tng_atom) * (molecule->n_atoms + 1),
                __FILE__, __LINE__);
         free(molecule->atoms);
@@ -9068,7 +9111,7 @@ tng_function_status DECLSPECDLLEXPORT tng_molecule_alloc(const tng_trajectory_t
     *molecule_p = malloc(sizeof(struct tng_molecule));
     if(!*molecule_p)
     {
-        fprintf(stderr, "TNG library: Cannot allocate memory (%lu bytes). %s: %d\n",
+        fprintf(stderr, "TNG library: Cannot allocate memory (%"TNG_PRIsize" bytes). %s: %d\n",
                sizeof(struct tng_molecule), __FILE__, __LINE__);
         return(TNG_CRITICAL);
     }
@@ -9300,14 +9343,14 @@ tng_function_status DECLSPECDLLEXPORT tng_molsystem_bonds_get
     *from_atoms = malloc(sizeof(int64_t) * (*n_bonds));
     if(!*from_atoms)
     {
-        fprintf(stderr, "TNG library: Cannot allocate memory (%"PRId64" bytes). %s: %d\n",
+        fprintf(stderr, "TNG library: Cannot allocate memory (%"PRIu64" bytes). %s: %d\n",
                sizeof(int64_t) * (*n_bonds), __FILE__, __LINE__);
         return(TNG_CRITICAL);
     }
     *to_atoms = malloc(sizeof(int64_t) * (*n_bonds));
     if(!*to_atoms)
     {
-        fprintf(stderr, "TNG library: Cannot allocate memory (%"PRId64" bytes). %s: %d\n",
+        fprintf(stderr, "TNG library: Cannot allocate memory (%"PRIu64" bytes). %s: %d\n",
                sizeof(int64_t) * (*n_bonds), __FILE__, __LINE__);
         free(*from_atoms);
         *from_atoms = 0;
@@ -9689,7 +9732,7 @@ tng_function_status DECLSPECDLLEXPORT tng_particle_mapping_add
 
     if(!mapping)
     {
-        fprintf(stderr, "TNG library: Cannot allocate memory (%"PRId64" bytes). %s: %d\n",
+        fprintf(stderr, "TNG library: Cannot allocate memory (%"PRIu64" bytes). %s: %d\n",
                sizeof(struct tng_particle_mapping)*frame_set->n_mapping_blocks,
                __FILE__, __LINE__);
         free(frame_set->mappings);
@@ -9704,7 +9747,7 @@ tng_function_status DECLSPECDLLEXPORT tng_particle_mapping_add
     frame_set->mappings[frame_set->n_mapping_blocks - 1].real_particle_numbers = malloc(sizeof(int64_t) * n_particles);
     if(!frame_set->mappings[frame_set->n_mapping_blocks - 1].real_particle_numbers)
     {
-        fprintf(stderr, "TNG library: Cannot allocate memory (%"PRId64" bytes). %s: %d\n",
+        fprintf(stderr, "TNG library: Cannot allocate memory (%"PRIu64" bytes). %s: %d\n",
                sizeof(int64_t) * n_particles, __FILE__, __LINE__);
         return(TNG_CRITICAL);
     }
@@ -9755,7 +9798,7 @@ tng_function_status DECLSPECDLLEXPORT tng_trajectory_init(tng_trajectory_t *tng_
     *tng_data_p = malloc(sizeof(struct tng_trajectory));
     if(!*tng_data_p)
     {
-        fprintf(stderr, "TNG library: Cannot allocate memory (%lu bytes). %s: %d\n",
+        fprintf(stderr, "TNG library: Cannot allocate memory (%"TNG_PRIsize" bytes). %s: %d\n",
                sizeof(struct tng_trajectory), __FILE__, __LINE__);
         return(TNG_CRITICAL);
     }
@@ -10276,7 +10319,7 @@ tng_function_status DECLSPECDLLEXPORT tng_trajectory_init_from_src(tng_trajector
     *dest_p = malloc(sizeof(struct tng_trajectory));
     if(!*dest_p)
     {
-        fprintf(stderr, "TNG library: Cannot allocate memory (%lu bytes). %s: %d\n",
+        fprintf(stderr, "TNG library: Cannot allocate memory (%"TNG_PRIsize" bytes). %s: %d\n",
                sizeof(struct tng_trajectory), __FILE__, __LINE__);
         return(TNG_CRITICAL);
     }
@@ -10623,7 +10666,7 @@ tng_function_status DECLSPECDLLEXPORT tng_output_file_endianness_set
 
     /* Tne endianness cannot be changed if the data has already been written
      * to the output file. */
-    if(ftell(tng_data->output_file) > 0)
+    if(ftello(tng_data->output_file) > 0)
     {
         return(TNG_FAILURE);
     }
@@ -11247,14 +11290,13 @@ tng_function_status DECLSPECDLLEXPORT tng_num_frames_get
 {
     tng_gen_block_t block;
     tng_function_status stat;
-    long file_pos;
-    int64_t last_file_pos, first_frame, n_frames;
+    int64_t file_pos, last_file_pos, first_frame, n_frames;
 
     TNG_ASSERT(tng_data, "TNG library: Trajectory container not properly setup.");
     TNG_ASSERT(tng_data->input_file, "TNG library: An input file must be open to find the next frame set");
     TNG_ASSERT(n, "TNG library: n must not be a NULL pointer");
 
-    file_pos = ftell(tng_data->input_file);
+    file_pos = ftello(tng_data->input_file);
     last_file_pos = tng_data->last_trajectory_frame_set_input_file_pos;
 
     if(last_file_pos <= 0)
@@ -11263,9 +11305,9 @@ tng_function_status DECLSPECDLLEXPORT tng_num_frames_get
     }
 
     tng_block_init(&block);
-    fseek(tng_data->input_file,
-          (long)last_file_pos,
-          SEEK_SET);
+    fseeko(tng_data->input_file,
+           last_file_pos,
+           SEEK_SET);
     /* Read block headers first to see that a frame set block is found. */
     stat = tng_block_header_read(tng_data, block);
     if(stat == TNG_CRITICAL || block->id != TNG_TRAJECTORY_FRAME_SET)
@@ -11289,7 +11331,7 @@ tng_function_status DECLSPECDLLEXPORT tng_num_frames_get
                __FILE__, __LINE__);
         return(TNG_CRITICAL);
     }
-    fseek(tng_data->input_file, file_pos, SEEK_SET);
+    fseeko(tng_data->input_file, file_pos, SEEK_SET);
 
     *n = first_frame + n_frames;
 
@@ -11552,7 +11594,7 @@ tng_function_status DECLSPECDLLEXPORT tng_num_frame_sets_get
                  int64_t *n)
 {
     int64_t long_stride_length, medium_stride_length;
-    long file_pos, orig_frame_set_file_pos;
+    int64_t file_pos, orig_frame_set_file_pos;
     tng_trajectory_frame_set_t frame_set;
     struct tng_trajectory_frame_set orig_frame_set;
     tng_gen_block_t block;
@@ -11567,7 +11609,7 @@ tng_function_status DECLSPECDLLEXPORT tng_num_frame_sets_get
     frame_set = &tng_data->current_trajectory_frame_set;
 
     orig_frame_set_file_pos = tng_data->current_trajectory_frame_set_input_file_pos;
-    file_pos = (long)tng_data->first_trajectory_frame_set_input_file_pos;
+    file_pos = tng_data->first_trajectory_frame_set_input_file_pos;
 
     if(file_pos < 0)
     {
@@ -11576,7 +11618,7 @@ tng_function_status DECLSPECDLLEXPORT tng_num_frame_sets_get
     }
 
     tng_block_init(&block);
-    fseek(tng_data->input_file,
+    fseeko(tng_data->input_file,
           file_pos,
           SEEK_SET);
     tng_data->current_trajectory_frame_set_input_file_pos = file_pos;
@@ -11584,7 +11626,7 @@ tng_function_status DECLSPECDLLEXPORT tng_num_frame_sets_get
     stat = tng_block_header_read(tng_data, block);
     if(stat == TNG_CRITICAL || block->id != TNG_TRAJECTORY_FRAME_SET)
     {
-        fprintf(stderr, "TNG library: Cannot read block header at pos %ld. %s: %d\n", file_pos,
+        fprintf(stderr, "TNG library: Cannot read block header at pos %"PRId64". %s: %d\n", file_pos,
                 __FILE__, __LINE__);
         tng_block_destroy(&block);
         return(TNG_CRITICAL);
@@ -11604,18 +11646,18 @@ tng_function_status DECLSPECDLLEXPORT tng_num_frame_sets_get
 
     /* Take long steps forward until a long step forward would be too long or
      * the last frame set is found */
-    file_pos = (long)frame_set->long_stride_next_frame_set_file_pos;
+    file_pos = frame_set->long_stride_next_frame_set_file_pos;
     while(file_pos > 0)
     {
         if(file_pos > 0)
         {
             cnt += long_stride_length;
-            fseek(tng_data->input_file, file_pos, SEEK_SET);
+            fseeko(tng_data->input_file, file_pos, SEEK_SET);
             /* Read block headers first to see what block is found. */
             stat = tng_block_header_read(tng_data, block);
             if(stat == TNG_CRITICAL || block->id != TNG_TRAJECTORY_FRAME_SET)
             {
-                fprintf(stderr, "TNG library: Cannot read block header at pos %ld. %s: %d\n",
+                fprintf(stderr, "TNG library: Cannot read block header at pos %"PRId64". %s: %d\n",
                        file_pos, __FILE__, __LINE__);
                 tng_block_destroy(&block);
                 return(TNG_CRITICAL);
@@ -11628,25 +11670,25 @@ tng_function_status DECLSPECDLLEXPORT tng_num_frame_sets_get
                 return(TNG_CRITICAL);
             }
         }
-        file_pos = (long)frame_set->long_stride_next_frame_set_file_pos;
+        file_pos = frame_set->long_stride_next_frame_set_file_pos;
     }
 
     /* Take medium steps forward until a medium step forward would be too long
      * or the last frame set is found */
-    file_pos = (long)frame_set->medium_stride_next_frame_set_file_pos;
+    file_pos = frame_set->medium_stride_next_frame_set_file_pos;
     while(file_pos > 0)
     {
         if(file_pos > 0)
         {
             cnt += medium_stride_length;
-            fseek(tng_data->input_file,
+            fseeko(tng_data->input_file,
                   file_pos,
                   SEEK_SET);
             /* Read block headers first to see what block is found. */
             stat = tng_block_header_read(tng_data, block);
             if(stat == TNG_CRITICAL || block->id != TNG_TRAJECTORY_FRAME_SET)
             {
-                fprintf(stderr, "TNG library: Cannot read block header at pos %ld. %s: %d\n",
+                fprintf(stderr, "TNG library: Cannot read block header at pos %"PRId64". %s: %d\n",
                        file_pos, __FILE__, __LINE__);
                 tng_block_destroy(&block);
                 return(TNG_CRITICAL);
@@ -11659,24 +11701,24 @@ tng_function_status DECLSPECDLLEXPORT tng_num_frame_sets_get
                 return(TNG_CRITICAL);
             }
         }
-        file_pos = (long)frame_set->medium_stride_next_frame_set_file_pos;
+        file_pos = frame_set->medium_stride_next_frame_set_file_pos;
     }
 
     /* Take one step forward until the last frame set is found */
-    file_pos = (long)frame_set->next_frame_set_file_pos;
+    file_pos = frame_set->next_frame_set_file_pos;
     while(file_pos > 0)
     {
         if(file_pos > 0)
         {
             ++cnt;
-            fseek(tng_data->input_file,
+            fseeko(tng_data->input_file,
                   file_pos,
                   SEEK_SET);
             /* Read block headers first to see what block is found. */
             stat = tng_block_header_read(tng_data, block);
             if(stat == TNG_CRITICAL || block->id != TNG_TRAJECTORY_FRAME_SET)
             {
-                fprintf(stderr, "TNG library: Cannot read block header at pos %ld. %s: %d\n",
+                fprintf(stderr, "TNG library: Cannot read block header at pos %"PRId64". %s: %d\n",
                        file_pos, __FILE__, __LINE__);
                 tng_block_destroy(&block);
                 return(TNG_CRITICAL);
@@ -11689,7 +11731,7 @@ tng_function_status DECLSPECDLLEXPORT tng_num_frame_sets_get
                 return(TNG_CRITICAL);
             }
         }
-        file_pos = (long)frame_set->next_frame_set_file_pos;
+        file_pos = frame_set->next_frame_set_file_pos;
     }
 
     tng_block_destroy(&block);
@@ -11702,9 +11744,9 @@ tng_function_status DECLSPECDLLEXPORT tng_num_frame_sets_get
     frame_set->mappings = 0;
     frame_set->n_mapping_blocks = 0;
 
-    fseek(tng_data->input_file,
-          (long)tng_data->first_trajectory_frame_set_input_file_pos,
-          SEEK_SET);
+    fseeko(tng_data->input_file,
+           tng_data->first_trajectory_frame_set_input_file_pos,
+           SEEK_SET);
 
     tng_data->current_trajectory_frame_set_input_file_pos = orig_frame_set_file_pos;
 
@@ -11771,10 +11813,10 @@ tng_function_status DECLSPECDLLEXPORT tng_frame_set_nr_find
     }
 
     tng_block_init(&block);
-    fseek(tng_data->input_file,
-          (long)file_pos,
-          SEEK_SET);
-    tng_data->current_trajectory_frame_set_input_file_pos = (long)file_pos;
+    fseeko(tng_data->input_file,
+           file_pos,
+           SEEK_SET);
+    tng_data->current_trajectory_frame_set_input_file_pos = file_pos;
     /* Read block headers first to see what block is found. */
     stat = tng_block_header_read(tng_data, block);
     if(stat == TNG_CRITICAL || block->id != TNG_TRAJECTORY_FRAME_SET)
@@ -11808,7 +11850,7 @@ tng_function_status DECLSPECDLLEXPORT tng_frame_set_nr_find
         if(file_pos > 0)
         {
             curr_nr += long_stride_length;
-            fseek(tng_data->input_file, (long)file_pos, SEEK_SET);
+            fseeko(tng_data->input_file, file_pos, SEEK_SET);
             /* Read block headers first to see what block is found. */
             stat = tng_block_header_read(tng_data, block);
             if(stat == TNG_CRITICAL || block->id != TNG_TRAJECTORY_FRAME_SET)
@@ -11841,9 +11883,9 @@ tng_function_status DECLSPECDLLEXPORT tng_frame_set_nr_find
         if(file_pos > 0)
         {
             curr_nr += medium_stride_length;
-            fseek(tng_data->input_file,
-                  (long)file_pos,
-                  SEEK_SET);
+            fseeko(tng_data->input_file,
+                   file_pos,
+                   SEEK_SET);
             /* Read block headers first to see what block is found. */
             stat = tng_block_header_read(tng_data, block);
             if(stat == TNG_CRITICAL || block->id != TNG_TRAJECTORY_FRAME_SET)
@@ -11876,9 +11918,9 @@ tng_function_status DECLSPECDLLEXPORT tng_frame_set_nr_find
         if(file_pos > 0)
         {
             ++curr_nr;
-            fseek(tng_data->input_file,
-                  (long)file_pos,
-                  SEEK_SET);
+            fseeko(tng_data->input_file,
+                   file_pos,
+                   SEEK_SET);
             /* Read block headers first to see what block is found. */
             stat = tng_block_header_read(tng_data, block);
             if(stat == TNG_CRITICAL || block->id != TNG_TRAJECTORY_FRAME_SET)
@@ -11911,9 +11953,9 @@ tng_function_status DECLSPECDLLEXPORT tng_frame_set_nr_find
         if(file_pos > 0)
         {
             curr_nr -= long_stride_length;
-            fseek(tng_data->input_file,
-                  (long)file_pos,
-                  SEEK_SET);
+            fseeko(tng_data->input_file,
+                   file_pos,
+                   SEEK_SET);
             /* Read block headers first to see what block is found. */
             stat = tng_block_header_read(tng_data, block);
             if(stat == TNG_CRITICAL || block->id != TNG_TRAJECTORY_FRAME_SET)
@@ -11946,9 +11988,9 @@ tng_function_status DECLSPECDLLEXPORT tng_frame_set_nr_find
         if(file_pos > 0)
         {
             curr_nr -= medium_stride_length;
-            fseek(tng_data->input_file,
-                  (long)file_pos,
-                  SEEK_SET);
+            fseeko(tng_data->input_file,
+                   file_pos,
+                   SEEK_SET);
             /* Read block headers first to see what block is found. */
             stat = tng_block_header_read(tng_data, block);
             if(stat == TNG_CRITICAL || block->id != TNG_TRAJECTORY_FRAME_SET)
@@ -11980,9 +12022,9 @@ tng_function_status DECLSPECDLLEXPORT tng_frame_set_nr_find
         if(file_pos > 0)
         {
             --curr_nr;
-            fseek(tng_data->input_file,
-                  (long)file_pos,
-                  SEEK_SET);
+            fseeko(tng_data->input_file,
+                   file_pos,
+                   SEEK_SET);
             /* Read block headers first to see what block is found. */
             stat = tng_block_header_read(tng_data, block);
             if(stat == TNG_CRITICAL || block->id != TNG_TRAJECTORY_FRAME_SET)
@@ -12015,9 +12057,9 @@ tng_function_status DECLSPECDLLEXPORT tng_frame_set_nr_find
         if(file_pos > 0)
         {
             ++curr_nr;
-            fseek(tng_data->input_file,
-                  (long)file_pos,
-                  SEEK_SET);
+            fseeko(tng_data->input_file,
+                   file_pos,
+                   SEEK_SET);
             /* Read block headers first to see what block is found. */
             stat = tng_block_header_read(tng_data, block);
             if(stat == TNG_CRITICAL || block->id != TNG_TRAJECTORY_FRAME_SET)
@@ -12067,10 +12109,10 @@ tng_function_status DECLSPECDLLEXPORT tng_frame_set_of_frame_find
     if(tng_data->current_trajectory_frame_set_input_file_pos < 0)
     {
         file_pos = tng_data->first_trajectory_frame_set_input_file_pos;
-        fseek(tng_data->input_file,
-                (long)file_pos,
-                SEEK_SET);
-        tng_data->current_trajectory_frame_set_input_file_pos = (long)file_pos;
+        fseeko(tng_data->input_file,
+               file_pos,
+               SEEK_SET);
+        tng_data->current_trajectory_frame_set_input_file_pos = file_pos;
         /* Read block headers first to see what block is found. */
         stat = tng_block_header_read(tng_data, block);
         if(stat == TNG_CRITICAL || block->id != TNG_TRAJECTORY_FRAME_SET)
@@ -12150,10 +12192,10 @@ tng_function_status DECLSPECDLLEXPORT tng_frame_set_of_frame_find
 
         if(file_pos > 0)
         {
-            fseek(tng_data->input_file,
-                  (long)file_pos,
-                  SEEK_SET);
-            tng_data->current_trajectory_frame_set_input_file_pos = (long)file_pos;
+            fseeko(tng_data->input_file,
+                   file_pos,
+                   SEEK_SET);
+            tng_data->current_trajectory_frame_set_input_file_pos = file_pos;
             /* Read block headers first to see what block is found. */
             stat = tng_block_header_read(tng_data, block);
             if(stat == TNG_CRITICAL || block->id != TNG_TRAJECTORY_FRAME_SET)
@@ -12192,7 +12234,7 @@ tng_function_status DECLSPECDLLEXPORT tng_frame_set_of_frame_find
         file_pos = frame_set->long_stride_next_frame_set_file_pos;
         if(file_pos > 0)
         {
-            fseek(tng_data->input_file, (long)file_pos, SEEK_SET);
+            fseeko(tng_data->input_file, file_pos, SEEK_SET);
             /* Read block headers first to see what block is found. */
             stat = tng_block_header_read(tng_data, block);
             if(stat == TNG_CRITICAL || block->id != TNG_TRAJECTORY_FRAME_SET)
@@ -12227,9 +12269,9 @@ tng_function_status DECLSPECDLLEXPORT tng_frame_set_of_frame_find
         file_pos = frame_set->medium_stride_next_frame_set_file_pos;
         if(file_pos > 0)
         {
-            fseek(tng_data->input_file,
-                  (long)file_pos,
-                  SEEK_SET);
+            fseeko(tng_data->input_file,
+                   file_pos,
+                   SEEK_SET);
             /* Read block headers first to see what block is found. */
             stat = tng_block_header_read(tng_data, block);
             if(stat == TNG_CRITICAL || block->id != TNG_TRAJECTORY_FRAME_SET)
@@ -12262,9 +12304,9 @@ tng_function_status DECLSPECDLLEXPORT tng_frame_set_of_frame_find
         file_pos = frame_set->next_frame_set_file_pos;
         if(file_pos > 0)
         {
-            fseek(tng_data->input_file,
-                  (long)file_pos,
-                  SEEK_SET);
+            fseeko(tng_data->input_file,
+                   file_pos,
+                   SEEK_SET);
             /* Read block headers first to see what block is found. */
             stat = tng_block_header_read(tng_data, block);
             if(stat == TNG_CRITICAL || block->id != TNG_TRAJECTORY_FRAME_SET)
@@ -12299,9 +12341,9 @@ tng_function_status DECLSPECDLLEXPORT tng_frame_set_of_frame_find
         file_pos = frame_set->long_stride_prev_frame_set_file_pos;
         if(file_pos > 0)
         {
-            fseek(tng_data->input_file,
-                  (long)file_pos,
-                  SEEK_SET);
+            fseeko(tng_data->input_file,
+                   file_pos,
+                   SEEK_SET);
             /* Read block headers first to see what block is found. */
             stat = tng_block_header_read(tng_data, block);
             if(stat == TNG_CRITICAL || block->id != TNG_TRAJECTORY_FRAME_SET)
@@ -12336,9 +12378,9 @@ tng_function_status DECLSPECDLLEXPORT tng_frame_set_of_frame_find
         file_pos = frame_set->medium_stride_prev_frame_set_file_pos;
         if(file_pos > 0)
         {
-            fseek(tng_data->input_file,
-                  (long)file_pos,
-                  SEEK_SET);
+            fseeko(tng_data->input_file,
+                   file_pos,
+                   SEEK_SET);
             /* Read block headers first to see what block is found. */
             stat = tng_block_header_read(tng_data, block);
             if(stat == TNG_CRITICAL || block->id != TNG_TRAJECTORY_FRAME_SET)
@@ -12371,9 +12413,9 @@ tng_function_status DECLSPECDLLEXPORT tng_frame_set_of_frame_find
         file_pos = frame_set->prev_frame_set_file_pos;
         if(file_pos > 0)
         {
-            fseek(tng_data->input_file,
-                  (long)file_pos,
-                  SEEK_SET);
+            fseeko(tng_data->input_file,
+                   file_pos,
+                   SEEK_SET);
             /* Read block headers first to see what block is found. */
             stat = tng_block_header_read(tng_data, block);
             if(stat == TNG_CRITICAL || block->id != TNG_TRAJECTORY_FRAME_SET)
@@ -12407,9 +12449,9 @@ tng_function_status DECLSPECDLLEXPORT tng_frame_set_of_frame_find
         file_pos = frame_set->next_frame_set_file_pos;
         if(file_pos > 0)
         {
-            fseek(tng_data->input_file,
-                  (long)file_pos,
-                  SEEK_SET);
+            fseeko(tng_data->input_file,
+                   file_pos,
+                   SEEK_SET);
             /* Read block headers first to see what block is found. */
             stat = tng_block_header_read(tng_data, block);
             if(stat == TNG_CRITICAL || block->id != TNG_TRAJECTORY_FRAME_SET)
@@ -12576,14 +12618,14 @@ static tng_function_status tng_file_headers_len_get
 
     *len = 0;
 
-    orig_pos = ftell(tng_data->input_file);
+    orig_pos = ftello(tng_data->input_file);
 
     if(!tng_data->input_file_len)
     {
-        fseek(tng_data->input_file, 0, SEEK_END);
-        tng_data->input_file_len = ftell(tng_data->input_file);
+        fseeko(tng_data->input_file, 0, SEEK_END);
+        tng_data->input_file_len = ftello(tng_data->input_file);
     }
-    fseek(tng_data->input_file, 0, SEEK_SET);
+    fseeko(tng_data->input_file, 0, SEEK_SET);
 
     tng_block_init(&block);
     /* Read through the headers of non-trajectory blocks (they come before the
@@ -12594,10 +12636,10 @@ static tng_function_status tng_file_headers_len_get
            block->id != TNG_TRAJECTORY_FRAME_SET)
     {
         *len += block->header_contents_size + block->block_contents_size;
-        fseek(tng_data->input_file, block->block_contents_size, SEEK_CUR);
+        fseeko(tng_data->input_file, block->block_contents_size, SEEK_CUR);
     }
 
-    fseek(tng_data->input_file, orig_pos, SEEK_SET);
+    fseeko(tng_data->input_file, orig_pos, SEEK_SET);
 
     tng_block_destroy(&block);
 
@@ -12622,10 +12664,10 @@ tng_function_status DECLSPECDLLEXPORT tng_file_headers_read
 
     if(!tng_data->input_file_len)
     {
-        fseek(tng_data->input_file, 0, SEEK_END);
-        tng_data->input_file_len = ftell(tng_data->input_file);
+        fseeko(tng_data->input_file, 0, SEEK_END);
+        tng_data->input_file_len = ftello(tng_data->input_file);
     }
-    fseek(tng_data->input_file, 0, SEEK_SET);
+    fseeko(tng_data->input_file, 0, SEEK_SET);
 
     tng_block_init(&block);
     /* Non trajectory blocks (they come before the trajectory
@@ -12636,13 +12678,13 @@ tng_function_status DECLSPECDLLEXPORT tng_file_headers_read
            block->id != TNG_TRAJECTORY_FRAME_SET)
     {
         tng_block_read_next(tng_data, block, hash_mode);
-        prev_pos = ftell(tng_data->input_file);
+        prev_pos = ftello(tng_data->input_file);
     }
 
     /* Go back if a trajectory block was encountered */
     if(block->id == TNG_TRAJECTORY_FRAME_SET)
     {
-        fseek(tng_data->input_file, prev_pos, SEEK_SET);
+        fseeko(tng_data->input_file, prev_pos, SEEK_SET);
     }
 
     tng_block_destroy(&block);
@@ -12796,7 +12838,7 @@ tng_function_status DECLSPECDLLEXPORT tng_block_read_next(tng_trajectory_t tng_d
         else
         {
             /* Skip to the next block */
-            fseek(tng_data->input_file, (long)block->block_contents_size, SEEK_CUR);
+            fseeko(tng_data->input_file, block->block_contents_size, SEEK_CUR);
             return(TNG_FAILURE);
         }
     }
@@ -12806,7 +12848,7 @@ tng_function_status DECLSPECDLLEXPORT tng_frame_set_read
                 (tng_trajectory_t tng_data,
                  const char hash_mode)
 {
-    long file_pos;
+    int64_t file_pos;
     tng_gen_block_t block;
     tng_function_status stat;
 
@@ -12817,15 +12859,15 @@ tng_function_status DECLSPECDLLEXPORT tng_frame_set_read
         return(TNG_CRITICAL);
     }
 
-    file_pos = ftell(tng_data->input_file);
+    file_pos = ftello(tng_data->input_file);
 
     tng_block_init(&block);
 
     if(!tng_data->input_file_len)
     {
-        fseek(tng_data->input_file, 0, SEEK_END);
-        tng_data->input_file_len = ftell(tng_data->input_file);
-        fseek(tng_data->input_file, file_pos, SEEK_SET);
+        fseeko(tng_data->input_file, 0, SEEK_END);
+        tng_data->input_file_len = ftello(tng_data->input_file);
+        fseeko(tng_data->input_file, file_pos, SEEK_SET);
     }
 
     /* Read block headers first to see what block is found. */
@@ -12833,7 +12875,7 @@ tng_function_status DECLSPECDLLEXPORT tng_frame_set_read
     if(stat == TNG_CRITICAL || block->id != TNG_TRAJECTORY_FRAME_SET ||
        block->id == -1)
     {
-        fprintf(stderr, "TNG library: Cannot read block header at pos %ld. %s: %d\n",
+        fprintf(stderr, "TNG library: Cannot read block header at pos %"PRId64". %s: %d\n",
                file_pos, __FILE__, __LINE__);
         tng_block_destroy(&block);
         return(TNG_CRITICAL);
@@ -12845,7 +12887,7 @@ tng_function_status DECLSPECDLLEXPORT tng_frame_set_read
                            hash_mode) == TNG_SUCCESS)
     {
         tng_data->n_trajectory_frame_sets++;
-        file_pos = ftell(tng_data->input_file);
+        file_pos = ftello(tng_data->input_file);
         /* Read all blocks until next frame set block */
         stat = tng_block_header_read(tng_data, block);
         while(file_pos < tng_data->input_file_len &&
@@ -12857,7 +12899,7 @@ tng_function_status DECLSPECDLLEXPORT tng_frame_set_read
                                        hash_mode);
             if(stat != TNG_CRITICAL)
             {
-                file_pos = ftell(tng_data->input_file);
+                file_pos = ftello(tng_data->input_file);
                 if(file_pos < tng_data->input_file_len)
                 {
                     stat = tng_block_header_read(tng_data, block);
@@ -12866,7 +12908,7 @@ tng_function_status DECLSPECDLLEXPORT tng_frame_set_read
         }
         if(stat == TNG_CRITICAL)
         {
-            fprintf(stderr, "TNG library: Cannot read block header at pos %ld. %s: %d\n",
+            fprintf(stderr, "TNG library: Cannot read block header at pos %"PRId64". %s: %d\n",
                    file_pos, __FILE__, __LINE__);
             tng_block_destroy(&block);
             return(stat);
@@ -12874,7 +12916,7 @@ tng_function_status DECLSPECDLLEXPORT tng_frame_set_read
 
         if(block->id == TNG_TRAJECTORY_FRAME_SET)
         {
-            fseek(tng_data->input_file, file_pos, SEEK_SET);
+            fseeko(tng_data->input_file, file_pos, SEEK_SET);
         }
     }
 
@@ -12889,7 +12931,7 @@ tng_function_status DECLSPECDLLEXPORT tng_frame_set_read_current_only_data_from_
                  const char hash_mode,
                  const int64_t block_id)
 {
-    long file_pos;
+    int64_t file_pos;
     tng_gen_block_t block;
     tng_function_status stat;
     int found_flag = 1;
@@ -12901,19 +12943,19 @@ tng_function_status DECLSPECDLLEXPORT tng_frame_set_read_current_only_data_from_
         return(TNG_CRITICAL);
     }
 
-    file_pos = (long)tng_data->current_trajectory_frame_set_input_file_pos;
+    file_pos = tng_data->current_trajectory_frame_set_input_file_pos;
 
     if(file_pos < 0)
     {
         /* No current frame set. This means that the first frame set must be
          * read */
         found_flag = 0;
-        file_pos = (long)tng_data->first_trajectory_frame_set_input_file_pos;
+        file_pos = tng_data->first_trajectory_frame_set_input_file_pos;
     }
 
     if(file_pos > 0)
     {
-        fseek(tng_data->input_file,
+        fseeko(tng_data->input_file,
               file_pos,
               SEEK_SET);
     }
@@ -12926,16 +12968,16 @@ tng_function_status DECLSPECDLLEXPORT tng_frame_set_read_current_only_data_from_
 
     if(!tng_data->input_file_len)
     {
-        fseek(tng_data->input_file, 0, SEEK_END);
-        tng_data->input_file_len = ftell(tng_data->input_file);
-        fseek(tng_data->input_file, file_pos, SEEK_SET);
+        fseeko(tng_data->input_file, 0, SEEK_END);
+        tng_data->input_file_len = ftello(tng_data->input_file);
+        fseeko(tng_data->input_file, file_pos, SEEK_SET);
     }
 
     /* Read block headers first to see what block is found. */
     stat = tng_block_header_read(tng_data, block);
     if(stat == TNG_CRITICAL || block->id != TNG_TRAJECTORY_FRAME_SET)
     {
-        fprintf(stderr, "TNG library: Cannot read block header at pos %ld. %s: %d\n",
+        fprintf(stderr, "TNG library: Cannot read block header at pos %"PRId64". %s: %d\n",
                file_pos, __FILE__, __LINE__);
         tng_block_destroy(&block);
         return(TNG_CRITICAL);
@@ -12943,7 +12985,7 @@ tng_function_status DECLSPECDLLEXPORT tng_frame_set_read_current_only_data_from_
     /* If the current frame set had already been read skip its block contents */
     if(found_flag)
     {
-        fseek(tng_data->input_file, (long)block->block_contents_size, SEEK_CUR);
+        fseeko(tng_data->input_file, block->block_contents_size, SEEK_CUR);
     }
     /* Otherwiese read the frame set block */
     else
@@ -12957,7 +12999,7 @@ tng_function_status DECLSPECDLLEXPORT tng_frame_set_read_current_only_data_from_
             return(stat);
         }
     }
-    file_pos = ftell(tng_data->input_file);
+    file_pos = ftello(tng_data->input_file);
 
     found_flag = 0;
 
@@ -12975,7 +13017,7 @@ tng_function_status DECLSPECDLLEXPORT tng_frame_set_read_current_only_data_from_
                                        hash_mode);
             if(stat != TNG_CRITICAL)
             {
-                file_pos = ftell(tng_data->input_file);
+                file_pos = ftello(tng_data->input_file);
                 found_flag = 1;
                 if(file_pos < tng_data->input_file_len)
                 {
@@ -12985,8 +13027,8 @@ tng_function_status DECLSPECDLLEXPORT tng_frame_set_read_current_only_data_from_
         }
         else
         {
-            file_pos += (long)(block->block_contents_size + block->header_contents_size);
-            fseek(tng_data->input_file, (long)block->block_contents_size, SEEK_CUR);
+            file_pos += (block->block_contents_size + block->header_contents_size);
+            fseeko(tng_data->input_file, block->block_contents_size, SEEK_CUR);
             if(file_pos < tng_data->input_file_len)
             {
                 stat = tng_block_header_read(tng_data, block);
@@ -12995,7 +13037,7 @@ tng_function_status DECLSPECDLLEXPORT tng_frame_set_read_current_only_data_from_
     }
     if(stat == TNG_CRITICAL)
     {
-        fprintf(stderr, "TNG library: Cannot read block header at pos %ld. %s: %d\n",
+        fprintf(stderr, "TNG library: Cannot read block header at pos %"PRId64". %s: %d\n",
                 file_pos, __FILE__, __LINE__);
         tng_block_destroy(&block);
         return(stat);
@@ -13003,7 +13045,7 @@ tng_function_status DECLSPECDLLEXPORT tng_frame_set_read_current_only_data_from_
 
     if(block->id == TNG_TRAJECTORY_FRAME_SET)
     {
-        fseek(tng_data->input_file, file_pos, SEEK_SET);
+        fseeko(tng_data->input_file, file_pos, SEEK_SET);
     }
 
     tng_block_destroy(&block);
@@ -13022,7 +13064,7 @@ tng_function_status DECLSPECDLLEXPORT tng_frame_set_read_next
                 (tng_trajectory_t tng_data,
                  const char hash_mode)
 {
-    long file_pos;
+    int64_t file_pos;
 
     TNG_ASSERT(tng_data, "TNG library: Trajectory container not properly setup.");
 
@@ -13031,16 +13073,16 @@ tng_function_status DECLSPECDLLEXPORT tng_frame_set_read_next
         return(TNG_CRITICAL);
     }
 
-    file_pos = (long)tng_data->current_trajectory_frame_set.next_frame_set_file_pos;
+    file_pos = tng_data->current_trajectory_frame_set.next_frame_set_file_pos;
 
     if(file_pos < 0 && tng_data->current_trajectory_frame_set_input_file_pos <= 0)
     {
-        file_pos = (long)tng_data->first_trajectory_frame_set_input_file_pos;
+        file_pos = tng_data->first_trajectory_frame_set_input_file_pos;
     }
 
     if(file_pos > 0)
     {
-        fseek(tng_data->input_file,
+        fseeko(tng_data->input_file,
               file_pos,
               SEEK_SET);
     }
@@ -13057,7 +13099,7 @@ tng_function_status DECLSPECDLLEXPORT tng_frame_set_read_next_only_data_from_blo
                  const char hash_mode,
                  const int64_t block_id)
 {
-    long file_pos;
+    int64_t file_pos;
     tng_gen_block_t block;
     tng_function_status stat;
 
@@ -13068,16 +13110,16 @@ tng_function_status DECLSPECDLLEXPORT tng_frame_set_read_next_only_data_from_blo
         return(TNG_CRITICAL);
     }
 
-    file_pos = (long)tng_data->current_trajectory_frame_set.next_frame_set_file_pos;
+    file_pos = tng_data->current_trajectory_frame_set.next_frame_set_file_pos;
 
     if(file_pos < 0 && tng_data->current_trajectory_frame_set_input_file_pos <= 0)
     {
-        file_pos = (long)tng_data->first_trajectory_frame_set_input_file_pos;
+        file_pos = tng_data->first_trajectory_frame_set_input_file_pos;
     }
 
     if(file_pos > 0)
     {
-        fseek(tng_data->input_file,
+        fseeko(tng_data->input_file,
               file_pos,
               SEEK_SET);
     }
@@ -13090,16 +13132,16 @@ tng_function_status DECLSPECDLLEXPORT tng_frame_set_read_next_only_data_from_blo
 
     if(!tng_data->input_file_len)
     {
-        fseek(tng_data->input_file, 0, SEEK_END);
-        tng_data->input_file_len = ftell(tng_data->input_file);
-        fseek(tng_data->input_file, file_pos, SEEK_SET);
+        fseeko(tng_data->input_file, 0, SEEK_END);
+        tng_data->input_file_len = ftello(tng_data->input_file);
+        fseeko(tng_data->input_file, file_pos, SEEK_SET);
     }
 
     /* Read block headers first to see what block is found. */
     stat = tng_block_header_read(tng_data, block);
     if(stat == TNG_CRITICAL || block->id != TNG_TRAJECTORY_FRAME_SET)
     {
-        fprintf(stderr, "TNG library: Cannot read block header at pos %ld. %s: %d\n",
+        fprintf(stderr, "TNG library: Cannot read block header at pos %"PRId64". %s: %d\n",
                file_pos, __FILE__, __LINE__);
         tng_block_destroy(&block);
         return(TNG_CRITICAL);
@@ -13136,7 +13178,7 @@ tng_function_status tng_frame_set_write(tng_trajectory_t tng_data,
     }
 
     tng_data->current_trajectory_frame_set_output_file_pos =
-    ftell(tng_data->output_file);
+    ftello(tng_data->output_file);
     tng_data->last_trajectory_frame_set_output_file_pos =
     tng_data->current_trajectory_frame_set_output_file_pos;
 
@@ -13247,7 +13289,7 @@ tng_function_status DECLSPECDLLEXPORT tng_frame_set_new
 
     frame_set = &tng_data->current_trajectory_frame_set;
 
-    curr_pos = ftell(tng_data->output_file);
+    curr_pos = ftello(tng_data->output_file);
 
     if(curr_pos <= 10)
     {
@@ -13265,7 +13307,7 @@ tng_function_status DECLSPECDLLEXPORT tng_frame_set_new
     }
 
     tng_data->current_trajectory_frame_set_output_file_pos =
-    ftell(tng_data->output_file);
+    ftello(tng_data->output_file);
 
     tng_data->n_trajectory_frame_sets++;
 
@@ -13285,10 +13327,10 @@ tng_function_status DECLSPECDLLEXPORT tng_frame_set_new
             tng_block_init(&block);
             tng_data->input_file = tng_data->output_file;
 
-            curr_pos = ftell(tng_data->output_file);
-            fseek(tng_data->output_file,
-                  (long)frame_set->medium_stride_prev_frame_set_file_pos,
-                  SEEK_SET);
+            curr_pos = ftello(tng_data->output_file);
+            fseeko(tng_data->output_file,
+                   frame_set->medium_stride_prev_frame_set_file_pos,
+                   SEEK_SET);
 
             if(tng_block_header_read(tng_data, block) != TNG_SUCCESS)
             {
@@ -13301,7 +13343,7 @@ tng_function_status DECLSPECDLLEXPORT tng_frame_set_new
 
             /* Read the next frame set from the previous frame set and one
              * medium stride step back */
-            fseek(tng_data->output_file, (long)block->block_contents_size - (6 *
+            fseeko(tng_data->output_file, block->block_contents_size - (6 *
             sizeof(int64_t) + 2 * sizeof(double)), SEEK_CUR);
             if(fread(&frame_set->medium_stride_prev_frame_set_file_pos,
                sizeof(frame_set->medium_stride_prev_frame_set_file_pos),
@@ -13342,9 +13384,9 @@ tng_function_status DECLSPECDLLEXPORT tng_frame_set_new
                     tng_block_init(&block);
                     tng_data->input_file = tng_data->output_file;
 
-                    fseek(tng_data->output_file,
-                          (long)frame_set->long_stride_prev_frame_set_file_pos,
-                          SEEK_SET);
+                    fseeko(tng_data->output_file,
+                           frame_set->long_stride_prev_frame_set_file_pos,
+                           SEEK_SET);
 
                     if(tng_block_header_read(tng_data, block) != TNG_SUCCESS)
                     {
@@ -13357,7 +13399,7 @@ tng_function_status DECLSPECDLLEXPORT tng_frame_set_new
 
                     /* Read the next frame set from the previous frame set and one
                     * long stride step back */
-                    fseek(tng_data->output_file, (long)block->block_contents_size - (6 *
+                    fseeko(tng_data->output_file, block->block_contents_size - (6 *
                           sizeof(int64_t) + 2 * sizeof(double)), SEEK_CUR);
 
                     tng_block_destroy(&block);
@@ -13386,7 +13428,7 @@ tng_function_status DECLSPECDLLEXPORT tng_frame_set_new
             }
 
             tng_data->input_file = temp;
-            fseek(tng_data->output_file, (long)curr_pos, SEEK_SET);
+            fseeko(tng_data->output_file, curr_pos, SEEK_SET);
         }
     }
 
@@ -13456,7 +13498,7 @@ tng_function_status DECLSPECDLLEXPORT tng_first_frame_nr_of_next_frame_set_get
                 (const tng_trajectory_t tng_data,
                  int64_t *frame)
 {
-    long file_pos, next_frame_set_file_pos;
+    int64_t file_pos, next_frame_set_file_pos;
     tng_gen_block_t block;
     tng_function_status stat;
 
@@ -13466,16 +13508,16 @@ tng_function_status DECLSPECDLLEXPORT tng_first_frame_nr_of_next_frame_set_get
     TNG_ASSERT(tng_data->input_file, "TNG library: An input file must be open to find the next frame set");
     TNG_ASSERT(frame, "TNG library: frame must not be a NULL pointer");
 
-    file_pos = ftell(tng_data->input_file);
+    file_pos = ftello(tng_data->input_file);
 
     if(tng_data->current_trajectory_frame_set_input_file_pos <= 0)
     {
-        next_frame_set_file_pos = (long)tng_data->first_trajectory_frame_set_input_file_pos;
+        next_frame_set_file_pos = tng_data->first_trajectory_frame_set_input_file_pos;
     }
     else
     {
         frame_set = &tng_data->current_trajectory_frame_set;
-        next_frame_set_file_pos = (long)frame_set->next_frame_set_file_pos;
+        next_frame_set_file_pos = frame_set->next_frame_set_file_pos;
     }
 
     if(next_frame_set_file_pos <= 0)
@@ -13483,13 +13525,13 @@ tng_function_status DECLSPECDLLEXPORT tng_first_frame_nr_of_next_frame_set_get
         return(TNG_FAILURE);
     }
 
-    fseek(tng_data->input_file, (long)next_frame_set_file_pos, SEEK_SET);
+    fseeko(tng_data->input_file, next_frame_set_file_pos, SEEK_SET);
     /* Read block headers first to see that a frame set block is found. */
     tng_block_init(&block);
     stat = tng_block_header_read(tng_data, block);
     if(stat == TNG_CRITICAL || block->id != TNG_TRAJECTORY_FRAME_SET)
     {
-        fprintf(stderr, "TNG library: Cannot read block header at pos %ld. %s: %d\n",
+        fprintf(stderr, "TNG library: Cannot read block header at pos %"PRId64". %s: %d\n",
                file_pos, __FILE__, __LINE__);
         return(TNG_CRITICAL);
     }
@@ -13505,7 +13547,7 @@ tng_function_status DECLSPECDLLEXPORT tng_first_frame_nr_of_next_frame_set_get
                __FILE__, __LINE__);
         return(TNG_CRITICAL);
     }
-    fseek(tng_data->input_file, file_pos, SEEK_SET);
+    fseeko(tng_data->input_file, file_pos, SEEK_SET);
 
     return(TNG_SUCCESS);
 }
@@ -14085,8 +14127,7 @@ tng_function_status DECLSPECDLLEXPORT tng_frame_data_write
     int64_t header_pos, file_pos;
     int64_t output_file_len, n_values_per_frame, size, contents_size;
     int64_t header_size, temp_first, temp_last;
-    int64_t i, last_frame;
-    long temp_current;
+    int64_t i, last_frame, temp_current;
     tng_gen_block_t block;
     tng_trajectory_frame_set_t frame_set;
     FILE *temp = tng_data->input_file;
@@ -14141,10 +14182,10 @@ tng_function_status DECLSPECDLLEXPORT tng_frame_data_write
             tng_frame_set_new(tng_data,
                               last_frame+1,
                               tng_data->frame_set_n_frames);
-            file_pos = ftell(tng_data->output_file);
-            fseek(tng_data->output_file, 0, SEEK_END);
-            output_file_len = ftell(tng_data->output_file);
-            fseek(tng_data->output_file, (long)file_pos, SEEK_SET);
+            file_pos = ftello(tng_data->output_file);
+            fseeko(tng_data->output_file, 0, SEEK_END);
+            output_file_len = ftello(tng_data->output_file);
+            fseeko(tng_data->output_file, file_pos, SEEK_SET);
 
             /* Read mapping blocks from the last frame set */
             tng_block_init(&block);
@@ -14162,10 +14203,10 @@ tng_function_status DECLSPECDLLEXPORT tng_frame_data_write
                 }
                 else
                 {
-                    fseek(tng_data->output_file, (long)block->block_contents_size,
-                        SEEK_CUR);
+                    fseeko(tng_data->output_file, block->block_contents_size,
+                           SEEK_CUR);
                 }
-                file_pos = ftell(tng_data->output_file);
+                file_pos = ftello(tng_data->output_file);
                 if(file_pos < output_file_len)
                 {
                     stat = tng_block_header_read(tng_data, block);
@@ -14194,9 +14235,9 @@ tng_function_status DECLSPECDLLEXPORT tng_frame_data_write
 
     file_pos = tng_data->current_trajectory_frame_set_output_file_pos;
 
-    fseek(tng_data->output_file, 0, SEEK_END);
-    output_file_len = ftell(tng_data->output_file);
-    fseek(tng_data->output_file, (long)file_pos, SEEK_SET);
+    fseeko(tng_data->output_file, 0, SEEK_END);
+    output_file_len = ftello(tng_data->output_file);
+    fseeko(tng_data->output_file, file_pos, SEEK_SET);
 
     /* Read past the frame set block first */
     stat = tng_block_header_read(tng_data, block);
@@ -14212,8 +14253,8 @@ tng_function_status DECLSPECDLLEXPORT tng_frame_data_write
         tng_data->current_trajectory_frame_set_input_file_pos = temp_current;
         return(stat);
     }
-    fseek(tng_data->output_file, (long)block->block_contents_size,
-            SEEK_CUR);
+    fseeko(tng_data->output_file, block->block_contents_size,
+           SEEK_CUR);
 
     /* Read all block headers until next frame set block or
      * until the wanted block id is found */
@@ -14224,8 +14265,8 @@ tng_function_status DECLSPECDLLEXPORT tng_frame_data_write
             block->id != TNG_TRAJECTORY_FRAME_SET &&
             block->id != -1)
     {
-        fseek(tng_data->output_file, (long)block->block_contents_size, SEEK_CUR);
-        file_pos = ftell(tng_data->output_file);
+        fseeko(tng_data->output_file, block->block_contents_size, SEEK_CUR);
+        file_pos = ftello(tng_data->output_file);
         if(file_pos < output_file_len)
         {
             stat = tng_block_header_read(tng_data, block);
@@ -14246,7 +14287,7 @@ tng_function_status DECLSPECDLLEXPORT tng_frame_data_write
     contents_size = block->block_contents_size;
     header_size = block->header_contents_size;
 
-    header_pos = ftell(tng_data->output_file) - header_size;
+    header_pos = ftello(tng_data->output_file) - header_size;
     frame_set = &tng_data->current_trajectory_frame_set;
 
     if(fread(&datatype, sizeof(datatype), 1, tng_data->input_file) == 0)
@@ -14428,7 +14469,7 @@ tng_function_status DECLSPECDLLEXPORT tng_frame_data_write
         return(TNG_FAILURE);
     }
 
-    fseek(tng_data->output_file, (long)file_pos, SEEK_CUR);
+    fseeko(tng_data->output_file, file_pos, SEEK_CUR);
 
     /* If the endianness is not big endian the data needs to be swapped */
     if((data.datatype == TNG_INT_DATA ||
@@ -14511,8 +14552,7 @@ tng_function_status DECLSPECDLLEXPORT tng_frame_particle_data_write
     int64_t output_file_len, n_values_per_frame, size, contents_size;
     int64_t header_size, temp_first, temp_last;
     int64_t mapping_block_end_pos, num_first_particle, block_n_particles;
-    int64_t i, last_frame;
-    long temp_current;
+    int64_t i, last_frame, temp_current;
     tng_gen_block_t block;
     tng_trajectory_frame_set_t frame_set;
     FILE *temp = tng_data->input_file;
@@ -14571,10 +14611,10 @@ tng_function_status DECLSPECDLLEXPORT tng_frame_particle_data_write
                               last_frame+1,
                               tng_data->frame_set_n_frames);
 
-            file_pos = ftell(tng_data->output_file);
-            fseek(tng_data->output_file, 0, SEEK_END);
-            output_file_len = ftell(tng_data->output_file);
-            fseek(tng_data->output_file, (long)file_pos, SEEK_SET);
+            file_pos = ftello(tng_data->output_file);
+            fseeko(tng_data->output_file, 0, SEEK_END);
+            output_file_len = ftello(tng_data->output_file);
+            fseeko(tng_data->output_file, file_pos, SEEK_SET);
 
             /* Read mapping blocks from the last frame set */
             tng_block_init(&block);
@@ -14592,10 +14632,10 @@ tng_function_status DECLSPECDLLEXPORT tng_frame_particle_data_write
                 }
                 else
                 {
-                    fseek(tng_data->output_file, (long)block->block_contents_size,
+                    fseeko(tng_data->output_file, block->block_contents_size,
                         SEEK_CUR);
                 }
-                file_pos = ftell(tng_data->output_file);
+                file_pos = ftello(tng_data->output_file);
                 if(file_pos < output_file_len)
                 {
                     stat = tng_block_header_read(tng_data, block);
@@ -14625,9 +14665,9 @@ tng_function_status DECLSPECDLLEXPORT tng_frame_particle_data_write
 
     file_pos = tng_data->current_trajectory_frame_set_output_file_pos;
 
-    fseek(tng_data->output_file, 0, SEEK_END);
-    output_file_len = ftell(tng_data->output_file);
-    fseek(tng_data->output_file, (long)file_pos, SEEK_SET);
+    fseeko(tng_data->output_file, 0, SEEK_END);
+    output_file_len = ftello(tng_data->output_file);
+    fseeko(tng_data->output_file, file_pos, SEEK_SET);
 
     /* Read past the frame set block first */
     stat = tng_block_header_read(tng_data, block);
@@ -14643,7 +14683,7 @@ tng_function_status DECLSPECDLLEXPORT tng_frame_particle_data_write
         tng_data->current_trajectory_frame_set_input_file_pos = temp_current;
         return(stat);
     }
-    fseek(tng_data->output_file, (long)block->block_contents_size,
+    fseeko(tng_data->output_file, block->block_contents_size,
             SEEK_CUR);
 
     if(tng_data->var_num_atoms_flag)
@@ -14671,10 +14711,10 @@ tng_function_status DECLSPECDLLEXPORT tng_frame_particle_data_write
             }
             else
             {
-                fseek(tng_data->output_file, (long)block->block_contents_size,
+                fseeko(tng_data->output_file, block->block_contents_size,
                       SEEK_CUR);
             }
-            file_pos = ftell(tng_data->output_file);
+            file_pos = ftello(tng_data->output_file);
             if(block->id == TNG_PARTICLE_MAPPING)
             {
                 mapping = &frame_set->mappings[frame_set->n_mapping_blocks - 1];
@@ -14714,7 +14754,7 @@ tng_function_status DECLSPECDLLEXPORT tng_frame_particle_data_write
             tng_data->current_trajectory_frame_set_input_file_pos = temp_current;
             return(TNG_FAILURE);
         }
-        fseek(tng_data->output_file, (long)mapping_block_end_pos, SEEK_SET);
+        fseeko(tng_data->output_file, mapping_block_end_pos, SEEK_SET);
     }
 
     /* Read all block headers until next frame set block or
@@ -14727,8 +14767,8 @@ tng_function_status DECLSPECDLLEXPORT tng_frame_particle_data_write
             block->id != TNG_TRAJECTORY_FRAME_SET &&
             block->id != -1)
     {
-        fseek(tng_data->output_file, (long)block->block_contents_size, SEEK_CUR);
-        file_pos = ftell(tng_data->output_file);
+        fseeko(tng_data->output_file, block->block_contents_size, SEEK_CUR);
+        file_pos = ftello(tng_data->output_file);
         if(file_pos < output_file_len)
         {
             stat = tng_block_header_read(tng_data, block);
@@ -14750,7 +14790,7 @@ tng_function_status DECLSPECDLLEXPORT tng_frame_particle_data_write
     contents_size = block->block_contents_size;
     header_size = block->header_contents_size;
 
-    header_pos = ftell(tng_data->output_file) - header_size;
+    header_pos = ftello(tng_data->output_file) - header_size;
     frame_set = &tng_data->current_trajectory_frame_set;
 
     if(fread(&datatype, sizeof(datatype), 1, tng_data->input_file) == 0)
@@ -14974,7 +15014,7 @@ tng_function_status DECLSPECDLLEXPORT tng_frame_particle_data_write
         return(TNG_FAILURE);
     }
 
-    fseek(tng_data->output_file, (long)file_pos, SEEK_CUR);
+    fseeko(tng_data->output_file, file_pos, SEEK_CUR);
 
     /* If the endianness is not big endian the data needs to be swapped */
     if((data.datatype == TNG_INT_DATA ||
@@ -15073,7 +15113,7 @@ static tng_function_status tng_data_values_alloc
     *values = malloc(sizeof(union data_values *) * n_frames);
     if(!*values)
     {
-        fprintf(stderr, "TNG library: Cannot allocate memory (%"PRId64" bytes). %s: %d\n",
+        fprintf(stderr, "TNG library: Cannot allocate memory (%"PRIu64" bytes). %s: %d\n",
                sizeof(union data_values **) * n_frames,
                __FILE__, __LINE__);
         return(TNG_CRITICAL);
@@ -15086,7 +15126,7 @@ static tng_function_status tng_data_values_alloc
                            n_values_per_frame);
         if(!(*values)[i])
         {
-            fprintf(stderr, "TNG library: Cannot allocate memory (%"PRId64" bytes). %s: %d\n",
+            fprintf(stderr, "TNG library: Cannot allocate memory (%"PRIu64" bytes). %s: %d\n",
                    sizeof(union data_values) * n_values_per_frame,
                    __FILE__, __LINE__);
             free(values);
@@ -15167,7 +15207,7 @@ static tng_function_status tng_particle_data_values_alloc
     *values = malloc(sizeof(union data_values **) * n_frames);
     if(!*values)
     {
-        fprintf(stderr, "TNG library: Cannot allocate memory (%"PRId64" bytes). %s: %d\n",
+        fprintf(stderr, "TNG library: Cannot allocate memory (%"PRIu64" bytes). %s: %d\n",
                sizeof(union data_values **) * n_frames,
                __FILE__, __LINE__);
         return(TNG_CRITICAL);
@@ -15180,7 +15220,7 @@ static tng_function_status tng_particle_data_values_alloc
                            n_particles);
         if(!(*values)[i])
         {
-            fprintf(stderr, "TNG library: Cannot allocate memory (%"PRId64" bytes). %s: %d\n",
+            fprintf(stderr, "TNG library: Cannot allocate memory (%"PRIu64" bytes). %s: %d\n",
                    sizeof(union data_values *) * n_particles,
                    __FILE__, __LINE__);
             free(*values);
@@ -15193,7 +15233,7 @@ static tng_function_status tng_particle_data_values_alloc
                                   n_values_per_frame);
             if(!(*values)[i][j])
             {
-                fprintf(stderr, "TNG library: Cannot allocate memory (%"PRId64" bytes). %s: %d\n",
+                fprintf(stderr, "TNG library: Cannot allocate memory (%"PRIu64" bytes). %s: %d\n",
                     sizeof(union data_values *) * n_particles,
                     __FILE__, __LINE__);
                 tng_particle_data_values_free(tng_data, *values, n_frames,
@@ -15282,7 +15322,7 @@ tng_function_status DECLSPECDLLEXPORT tng_data_get
     if(tng_data_find(tng_data, block_id, &data) != TNG_SUCCESS)
     {
         tng_block_init(&block);
-        file_pos = ftell(tng_data->input_file);
+        file_pos = ftello(tng_data->input_file);
         /* Read all blocks until next frame set block */
         stat = tng_block_header_read(tng_data, block);
         while(file_pos < tng_data->input_file_len &&
@@ -15295,7 +15335,7 @@ tng_function_status DECLSPECDLLEXPORT tng_data_get
                                     TNG_USE_HASH);
             if(stat != TNG_CRITICAL)
             {
-                file_pos = ftell(tng_data->input_file);
+                file_pos = ftello(tng_data->input_file);
                 if(file_pos < tng_data->input_file_len)
                 {
                     stat = tng_block_header_read(tng_data, block);
@@ -15423,7 +15463,7 @@ tng_function_status tng_data_vector_get(tng_trajectory_t tng_data,
     if(tng_data_find(tng_data, block_id, &data) != TNG_SUCCESS)
     {
         tng_block_init(&block);
-        file_pos = ftell(tng_data->input_file);
+        file_pos = ftello(tng_data->input_file);
         /* Read all blocks until next frame set block */
         stat = tng_block_header_read(tng_data, block);
         while(file_pos < tng_data->input_file_len &&
@@ -15436,7 +15476,7 @@ tng_function_status tng_data_vector_get(tng_trajectory_t tng_data,
                                     TNG_USE_HASH);
             if(stat != TNG_CRITICAL)
             {
-                file_pos = ftell(tng_data->input_file);
+                file_pos = ftello(tng_data->input_file);
                 if(file_pos < tng_data->input_file_len)
                 {
                     stat = tng_block_header_read(tng_data, block);
@@ -15552,7 +15592,7 @@ tng_function_status DECLSPECDLLEXPORT tng_data_interval_get
        frame_set->n_data_blocks <= 0)
     {
         tng_block_init(&block);
-        file_pos = ftell(tng_data->input_file);
+        file_pos = ftello(tng_data->input_file);
         /* Read all blocks until next frame set block */
         stat = tng_block_header_read(tng_data, block);
         while(file_pos < tng_data->input_file_len &&
@@ -15564,7 +15604,7 @@ tng_function_status DECLSPECDLLEXPORT tng_data_interval_get
                                     hash_mode);
             if(stat != TNG_CRITICAL)
             {
-                file_pos = ftell(tng_data->input_file);
+                file_pos = ftello(tng_data->input_file);
                 if(file_pos < tng_data->input_file_len)
                 {
                     stat = tng_block_header_read(tng_data, block);
@@ -15759,9 +15799,9 @@ tng_function_status DECLSPECDLLEXPORT tng_data_vector_interval_get
         tng_block_init(&block);
         if(stat != TNG_SUCCESS)
         {
-            fseek(tng_data->input_file,
-                  (long)tng_data->current_trajectory_frame_set_input_file_pos,
-                  SEEK_SET);
+            fseeko(tng_data->input_file,
+                   tng_data->current_trajectory_frame_set_input_file_pos,
+                   SEEK_SET);
             stat = tng_block_header_read(tng_data, block);
             if(stat != TNG_SUCCESS)
             {
@@ -15770,9 +15810,9 @@ tng_function_status DECLSPECDLLEXPORT tng_data_vector_interval_get
                 return(stat);
             }
 
-            fseek(tng_data->input_file, (long)block->block_contents_size, SEEK_CUR);
+            fseeko(tng_data->input_file, block->block_contents_size, SEEK_CUR);
         }
-        file_pos = ftell(tng_data->input_file);
+        file_pos = ftello(tng_data->input_file);
         /* Read until next frame set block */
         stat = tng_block_header_read(tng_data, block);
         while(file_pos < tng_data->input_file_len &&
@@ -15786,7 +15826,7 @@ tng_function_status DECLSPECDLLEXPORT tng_data_vector_interval_get
                                         hash_mode);
                 if(stat != TNG_CRITICAL)
                 {
-                    file_pos = ftell(tng_data->input_file);
+                    file_pos = ftello(tng_data->input_file);
                     if(file_pos < tng_data->input_file_len)
                     {
                         stat = tng_block_header_read(tng_data, block);
@@ -15796,7 +15836,7 @@ tng_function_status DECLSPECDLLEXPORT tng_data_vector_interval_get
             else
             {
                 file_pos += block->block_contents_size + block->header_contents_size;
-                fseek(tng_data->input_file, (long)block->block_contents_size, SEEK_CUR);
+                fseeko(tng_data->input_file, block->block_contents_size, SEEK_CUR);
                 if(file_pos < tng_data->input_file_len)
                 {
                     stat = tng_block_header_read(tng_data, block);
@@ -15996,7 +16036,7 @@ tng_function_status DECLSPECDLLEXPORT tng_particle_data_get
         }
 
         tng_block_init(&block);
-        file_pos = ftell(tng_data->input_file);
+        file_pos = ftello(tng_data->input_file);
         /* Read all blocks until next frame set block */
         stat = tng_block_header_read(tng_data, block);
         while(file_pos < tng_data->input_file_len &&
@@ -16009,7 +16049,7 @@ tng_function_status DECLSPECDLLEXPORT tng_particle_data_get
                                     TNG_USE_HASH);
             if(stat != TNG_CRITICAL)
             {
-                file_pos = ftell(tng_data->input_file);
+                file_pos = ftello(tng_data->input_file);
                 if(file_pos < tng_data->input_file_len)
                 {
                     stat = tng_block_header_read(tng_data, block);
@@ -16192,7 +16232,7 @@ tng_function_status DECLSPECDLLEXPORT tng_particle_data_vector_get
     if(tng_particle_data_find(tng_data, block_id, &data) != TNG_SUCCESS)
     {
         tng_block_init(&block);
-        file_pos = ftell(tng_data->input_file);
+        file_pos = ftello(tng_data->input_file);
         /* Read all blocks until next frame set block */
         stat = tng_block_header_read(tng_data, block);
         while(file_pos < tng_data->input_file_len &&
@@ -16205,7 +16245,7 @@ tng_function_status DECLSPECDLLEXPORT tng_particle_data_vector_get
                                     TNG_USE_HASH);
             if(stat != TNG_CRITICAL)
             {
-                file_pos = ftell(tng_data->input_file);
+                file_pos = ftello(tng_data->input_file);
                 if(file_pos < tng_data->input_file_len)
                 {
                     stat = tng_block_header_read(tng_data, block);
@@ -16363,7 +16403,7 @@ tng_function_status DECLSPECDLLEXPORT tng_particle_data_interval_get
        frame_set->n_particle_data_blocks <= 0)
     {
         tng_block_init(&block);
-        file_pos = ftell(tng_data->input_file);
+        file_pos = ftello(tng_data->input_file);
         /* Read all blocks until next frame set block */
         stat = tng_block_header_read(tng_data, block);
         while(file_pos < tng_data->input_file_len &&
@@ -16375,7 +16415,7 @@ tng_function_status DECLSPECDLLEXPORT tng_particle_data_interval_get
                                     hash_mode);
             if(stat != TNG_CRITICAL)
             {
-                file_pos = ftell(tng_data->input_file);
+                file_pos = ftello(tng_data->input_file);
                 if(file_pos < tng_data->input_file_len)
                 {
                     stat = tng_block_header_read(tng_data, block);
@@ -16607,9 +16647,9 @@ tng_function_status DECLSPECDLLEXPORT tng_particle_data_vector_interval_get
         tng_block_init(&block);
         if(stat != TNG_SUCCESS)
         {
-            fseek(tng_data->input_file,
-                  (long)tng_data->current_trajectory_frame_set_input_file_pos,
-                  SEEK_SET);
+            fseeko(tng_data->input_file,
+                   tng_data->current_trajectory_frame_set_input_file_pos,
+                   SEEK_SET);
             stat = tng_block_header_read(tng_data, block);
             if(stat != TNG_SUCCESS)
             {
@@ -16618,9 +16658,9 @@ tng_function_status DECLSPECDLLEXPORT tng_particle_data_vector_interval_get
                 return(stat);
             }
 
-            fseek(tng_data->input_file, (long)block->block_contents_size, SEEK_CUR);
+            fseeko(tng_data->input_file, block->block_contents_size, SEEK_CUR);
         }
-        file_pos = ftell(tng_data->input_file);
+        file_pos = ftello(tng_data->input_file);
         /* Read until next frame set block */
         stat = tng_block_header_read(tng_data, block);
         while(file_pos < tng_data->input_file_len &&
@@ -16634,7 +16674,7 @@ tng_function_status DECLSPECDLLEXPORT tng_particle_data_vector_interval_get
                                         hash_mode);
                 if(stat != TNG_CRITICAL)
                 {
-                    file_pos = ftell(tng_data->input_file);
+                    file_pos = ftello(tng_data->input_file);
                     if(file_pos < tng_data->input_file_len)
                     {
                         stat = tng_block_header_read(tng_data, block);
@@ -16644,7 +16684,7 @@ tng_function_status DECLSPECDLLEXPORT tng_particle_data_vector_interval_get
             else
             {
                 file_pos += block->block_contents_size + block->header_contents_size;
-                fseek(tng_data->input_file, (long)block->block_contents_size, SEEK_CUR);
+                fseeko(tng_data->input_file, block->block_contents_size, SEEK_CUR);
                 if(file_pos < tng_data->input_file_len)
                 {
                     stat = tng_block_header_read(tng_data, block);
@@ -16811,7 +16851,7 @@ tng_function_status DECLSPECDLLEXPORT tng_data_get_stride_length
     tng_function_status stat;
     tng_non_particle_data_t np_data;
     tng_particle_data_t p_data;
-    long orig_file_pos, file_pos;
+    int64_t orig_file_pos, file_pos;
     int is_particle_data;
 
     if(tng_data->current_trajectory_frame_set_input_file_pos <= 0)
@@ -16838,11 +16878,11 @@ tng_function_status DECLSPECDLLEXPORT tng_data_get_stride_length
             /* If no specific frame was required read until this data block is found */
             if(frame < 0)
             {
-                file_pos = ftell(tng_data->input_file);
+                file_pos = ftello(tng_data->input_file);
                 while(stat != TNG_SUCCESS && file_pos < tng_data->input_file_len)
                 {
                     stat = tng_frame_set_read_next_only_data_from_block_id(tng_data, TNG_USE_HASH, block_id);
-                    file_pos = ftell(tng_data->input_file);
+                    file_pos = ftello(tng_data->input_file);
                 }
             }
             if(stat != TNG_SUCCESS)
@@ -16961,9 +17001,9 @@ tng_function_status DECLSPECDLLEXPORT tng_util_trajectory_open
             fclose((*tng_data_p)->output_file);
         }
         (*tng_data_p)->output_file = (*tng_data_p)->input_file;
-        fseek((*tng_data_p)->input_file,
-                (long)(*tng_data_p)->last_trajectory_frame_set_input_file_pos,
-                SEEK_SET);
+        fseeko((*tng_data_p)->input_file,
+               (*tng_data_p)->last_trajectory_frame_set_input_file_pos,
+               SEEK_SET);
 
         stat = tng_frame_set_read(*tng_data_p, TNG_USE_HASH);
         if(stat != TNG_SUCCESS)
@@ -16991,7 +17031,7 @@ tng_function_status DECLSPECDLLEXPORT tng_util_trajectory_open
         }
         tng_output_append_file_set(*tng_data_p, filename);
 
-        fseek((*tng_data_p)->output_file, 0, SEEK_END);
+        fseeko((*tng_data_p)->output_file, 0, SEEK_END);
     }
 
     return(TNG_SUCCESS);
@@ -17339,9 +17379,8 @@ tng_function_status DECLSPECDLLEXPORT tng_util_particle_data_next_frame_read
     tng_particle_data_t data = 0;
     tng_function_status stat;
     int size;
-    int64_t i, data_size, n_particles;
+    int64_t i, data_size, n_particles, file_pos;
     void *temp;
-    long file_pos;
 
     TNG_ASSERT(tng_data, "TNG library: Trajectory container not properly setup.");
     TNG_ASSERT(values, "TNG library: The pointer to the values array must not be a NULL pointer");
@@ -17355,11 +17394,11 @@ tng_function_status DECLSPECDLLEXPORT tng_util_particle_data_next_frame_read
     if(stat != TNG_SUCCESS)
     {
         stat = tng_frame_set_read_current_only_data_from_block_id(tng_data, TNG_USE_HASH, block_id);
-        file_pos = ftell(tng_data->input_file);
+        file_pos = ftello(tng_data->input_file);
         while(stat != TNG_SUCCESS && file_pos < tng_data->input_file_len)
         {
             stat = tng_frame_set_read_next_only_data_from_block_id(tng_data, TNG_USE_HASH, block_id);
-            file_pos = ftell(tng_data->input_file);
+            file_pos = ftello(tng_data->input_file);
         }
         if(stat != TNG_SUCCESS)
         {
@@ -17373,9 +17412,9 @@ tng_function_status DECLSPECDLLEXPORT tng_util_particle_data_next_frame_read
     }
     if(data->last_retrieved_frame < 0)
     {
-        fseek(tng_data->input_file,
-              (long)tng_data->first_trajectory_frame_set_input_file_pos,
-              SEEK_SET);
+        fseeko(tng_data->input_file,
+               tng_data->first_trajectory_frame_set_input_file_pos,
+               SEEK_SET);
         stat = tng_frame_set_read(tng_data, TNG_USE_HASH);
         if(stat != TNG_SUCCESS)
         {
@@ -17503,9 +17542,8 @@ tng_function_status DECLSPECDLLEXPORT tng_util_non_particle_data_next_frame_read
     tng_non_particle_data_t data = 0;
     tng_function_status stat;
     int size;
-    int64_t i, data_size;
+    int64_t i, data_size, file_pos;
     void *temp;
-    long file_pos;
 
     TNG_ASSERT(tng_data, "TNG library: Trajectory container not properly setup.");
     TNG_ASSERT(values, "TNG library: The pointer to the values array must not be a NULL pointer");
@@ -17519,11 +17557,11 @@ tng_function_status DECLSPECDLLEXPORT tng_util_non_particle_data_next_frame_read
     if(stat != TNG_SUCCESS)
     {
         stat = tng_frame_set_read_current_only_data_from_block_id(tng_data, TNG_USE_HASH, block_id);
-        file_pos = ftell(tng_data->input_file);
+        file_pos = ftello(tng_data->input_file);
         while(stat != TNG_SUCCESS && file_pos < tng_data->input_file_len)
         {
             stat = tng_frame_set_read_next_only_data_from_block_id(tng_data, TNG_USE_HASH, block_id);
-            file_pos = ftell(tng_data->input_file);
+            file_pos = ftello(tng_data->input_file);
         }
         if(stat != TNG_SUCCESS)
         {
@@ -17537,9 +17575,9 @@ tng_function_status DECLSPECDLLEXPORT tng_util_non_particle_data_next_frame_read
     }
     if(data->last_retrieved_frame < 0)
     {
-        fseek(tng_data->input_file,
-                (long)tng_data->first_trajectory_frame_set_input_file_pos,
-                SEEK_SET);
+        fseeko(tng_data->input_file,
+               tng_data->first_trajectory_frame_set_input_file_pos,
+               SEEK_SET);
         stat = tng_frame_set_read(tng_data, TNG_USE_HASH);
         if(stat != TNG_SUCCESS)
         {
@@ -19110,9 +19148,8 @@ tng_function_status DECLSPECDLLEXPORT tng_util_trajectory_next_frame_present_dat
     tng_gen_block_t block;
     int64_t i, j, block_id, *temp;
     int64_t data_frame, frame_diff, min_diff;
-    int64_t size, frame_set_file_pos;
+    int64_t size, frame_set_file_pos, file_pos;
     int found, read_all = 0;
-    long file_pos;
 
     TNG_ASSERT(tng_data, "TNG library: Trajectory container not properly setup.");
     TNG_ASSERT(next_frame, "TNG library: The pointer to the next frame must not be NULL.");
@@ -19126,7 +19163,7 @@ tng_function_status DECLSPECDLLEXPORT tng_util_trajectory_next_frame_present_dat
         temp = realloc(*data_block_ids_in_next_frame, size);
         if(!temp)
         {
-            fprintf(stderr, "TNG library: Cannot allocate memory (%"PRId64" bytes). %s: %d\n",
+            fprintf(stderr, "TNG library: Cannot allocate memory (%"PRIu64" bytes). %s: %d\n",
                     sizeof(int64_t) * (*n_data_blocks_in_next_frame),
                     __FILE__, __LINE__);
             free(*data_block_ids_in_next_frame);
@@ -19163,7 +19200,7 @@ tng_function_status DECLSPECDLLEXPORT tng_util_trajectory_next_frame_present_dat
     /* Check for data blocks only if they have not already been found. */
     if(frame_set->n_particle_data_blocks <= 0 && frame_set->n_data_blocks <= 0)
     {
-        file_pos = ftell(tng_data->input_file);
+        file_pos = ftello(tng_data->input_file);
         if(file_pos < tng_data->input_file_len)
         {
             tng_block_init(&block);
@@ -19177,7 +19214,7 @@ tng_function_status DECLSPECDLLEXPORT tng_util_trajectory_next_frame_present_dat
                                         TNG_USE_HASH);
                 if(stat != TNG_CRITICAL)
                 {
-                    file_pos = ftell(tng_data->input_file);
+                    file_pos = ftello(tng_data->input_file);
                     if(file_pos < tng_data->input_file_len)
                     {
                         stat = tng_block_header_read(tng_data, block);
@@ -19187,7 +19224,7 @@ tng_function_status DECLSPECDLLEXPORT tng_util_trajectory_next_frame_present_dat
             tng_block_destroy(&block);
             if(stat == TNG_CRITICAL)
             {
-                fprintf(stderr, "TNG library: Cannot read block header at pos %ld. %s: %d\n",
+                fprintf(stderr, "TNG library: Cannot read block header at pos %"PRId64". %s: %d\n",
                         file_pos, __FILE__, __LINE__);
                 return(stat);
             }
@@ -19268,7 +19305,7 @@ tng_function_status DECLSPECDLLEXPORT tng_util_trajectory_next_frame_present_dat
                 temp = realloc(*data_block_ids_in_next_frame, size);
                 if(!temp)
                 {
-                    fprintf(stderr, "TNG library: Cannot allocate memory (%"PRId64" bytes). %s: %d\n",
+                    fprintf(stderr, "TNG library: Cannot allocate memory (%"PRIu64" bytes). %s: %d\n",
                            sizeof(int64_t) * (*n_data_blocks_in_next_frame),
                            __FILE__, __LINE__);
                     free(*data_block_ids_in_next_frame);
@@ -19355,7 +19392,7 @@ tng_function_status DECLSPECDLLEXPORT tng_util_trajectory_next_frame_present_dat
                 temp = realloc(*data_block_ids_in_next_frame, size);
                 if(!temp)
                 {
-                    fprintf(stderr, "TNG library: Cannot allocate memory (%"PRId64" bytes). %s: %d\n",
+                    fprintf(stderr, "TNG library: Cannot allocate memory (%"PRIu64" bytes). %s: %d\n",
                            sizeof(int64_t) * (*n_data_blocks_in_next_frame),
                            __FILE__, __LINE__);
                     free(*data_block_ids_in_next_frame);
@@ -19395,7 +19432,7 @@ tng_function_status DECLSPECDLLEXPORT tng_util_trajectory_all_data_block_types_g
                  char **compressions)
 {
     tng_gen_block_t block;
-    long orig_file_pos, file_pos;
+    int64_t orig_file_pos, file_pos;
 
     TNG_ASSERT(tng_data, "TNG library: Trajectory container not properly setup.");
     TNG_ASSERT(n_data_blocks, "TNG library: The pointer to n_data_blocks must not be NULL.");
@@ -19403,15 +19440,15 @@ tng_function_status DECLSPECDLLEXPORT tng_util_trajectory_all_data_block_types_g
     TNG_ASSERT(data_block_names, "TNG library: The pointer to the list of data block names must not be NULL.");
     TNG_ASSERT(stride_lengths, "TNG library: The pointer to the list of stride lengths must not be NULL.");
 
-    orig_file_pos = ftell(tng_data->input_file);
+    orig_file_pos = ftello(tng_data->input_file);
 
     if(!tng_data->input_file_len)
     {
-        fseek(tng_data->input_file, 0, SEEK_END);
-        tng_data->input_file_len = ftell(tng_data->input_file);
+        fseeko(tng_data->input_file, 0, SEEK_END);
+        tng_data->input_file_len = ftello(tng_data->input_file);
     }
 
-    fseek(tng_data->input_file, 0, SEEK_SET);
+    fseeko(tng_data->input_file, 0, SEEK_SET);
     file_pos = 0;
 
     *n_data_blocks = 0;
@@ -19425,11 +19462,11 @@ tng_function_status DECLSPECDLLEXPORT tng_util_trajectory_all_data_block_types_g
         {
 
         }
-        file_pos += (long)(block->block_contents_size + block->header_contents_size);
-        fseek(tng_data->input_file, (long)block->block_contents_size, SEEK_CUR);
+        file_pos += (block->block_contents_size + block->header_contents_size);
+        fseeko(tng_data->input_file, block->block_contents_size, SEEK_CUR);
     }
 
-    fseek(tng_data->input_file, orig_file_pos, SEEK_SET);
+    fseeko(tng_data->input_file, orig_file_pos, SEEK_SET);
 
     return(TNG_SUCCESS);
 }