HPCToolkit
hpcio.h
Go to the documentation of this file.
1 // -*-Mode: C++;-*- // technically C99
2 
3 // * BeginRiceCopyright *****************************************************
4 //
5 // $HeadURL$
6 // $Id$
7 //
8 // --------------------------------------------------------------------------
9 // Part of HPCToolkit (hpctoolkit.org)
10 //
11 // Information about sources of support for research and development of
12 // HPCToolkit is at 'hpctoolkit.org' and in 'README.Acknowledgments'.
13 // --------------------------------------------------------------------------
14 //
15 // Copyright ((c)) 2002-2019, Rice University
16 // All rights reserved.
17 //
18 // Redistribution and use in source and binary forms, with or without
19 // modification, are permitted provided that the following conditions are
20 // met:
21 //
22 // * Redistributions of source code must retain the above copyright
23 // notice, this list of conditions and the following disclaimer.
24 //
25 // * Redistributions in binary form must reproduce the above copyright
26 // notice, this list of conditions and the following disclaimer in the
27 // documentation and/or other materials provided with the distribution.
28 //
29 // * Neither the name of Rice University (RICE) nor the names of its
30 // contributors may be used to endorse or promote products derived from
31 // this software without specific prior written permission.
32 //
33 // This software is provided by RICE and contributors "as is" and any
34 // express or implied warranties, including, but not limited to, the
35 // implied warranties of merchantability and fitness for a particular
36 // purpose are disclaimed. In no event shall RICE or contributors be
37 // liable for any direct, indirect, incidental, special, exemplary, or
38 // consequential damages (including, but not limited to, procurement of
39 // substitute goods or services; loss of use, data, or profits; or
40 // business interruption) however caused and on any theory of liability,
41 // whether in contract, strict liability, or tort (including negligence
42 // or otherwise) arising in any way out of the use of this software, even
43 // if advised of the possibility of such damage.
44 //
45 // ******************************************************* EndRiceCopyright *
46 
47 //***************************************************************************
48 //
49 // File:
50 // $HeadURL$
51 //
52 // Purpose:
53 // General and helper functions for reading/writing a HPC data
54 // files from/to a binary file.
55 //
56 // These routines *must not* allocate dynamic memory; if such memory
57 // is needed, callbacks to the user's allocator should be used.
58 //
59 // Description:
60 // [The set of functions, macros, etc. defined in the file]
61 //
62 //***************************************************************************
63 
64 #ifndef prof_lean_hpcio_h
65 #define prof_lean_hpcio_h
66 
67 //************************* System Include Files ****************************
68 
69 #include <stdio.h>
70 #include <inttypes.h>
71 
72 //*************************** User Include Files ****************************
73 
74 #include <include/uint.h>
75 
76 //*************************** Forward Declarations **************************
77 
78 #if defined(__cplusplus)
79 extern "C" {
80 #endif
81 
82 //***************************************************************************
83 
84 // Note: use #defines to (portably) avoid warnings about unused
85 // "static const char*" variables.
86 #define HPCIO_RWBufferSz (4 * 1024 * 1024)
87 
88 //***************************************************************************
89 
90 // Open and close a file stream for use with the library's read/write
91 // routines.
92 //
93 // hpcio_fopen_w, hpcio_open_r: Opens the file pointed to by 'fnm' and
94 // returns a file stream for buffered I/O. For writing, if
95 // 'overwrite' is 0, it is an error for the file to already exist; if
96 // 'overwrite' is 1 any existing file will be overwritten. For
97 // reading, it is an error if the file does not exist. For any of
98 // these errors, or other open errors, NULL is returned; otherwise a
99 // non-null FILE pointer is returned.
100 //
101 // hpcio_close: Close the file stream. Returns 0 upon success;
102 // non-zero on error.
103 FILE*
104 hpcio_fopen_w(const char* fnm, int overwrite);
105 
106 FILE*
107 hpcio_fopen_r(const char* fnm);
108 
109 FILE*
110 hpcio_fopen_rw(const char* fnm);
111 
112 int
113 hpcio_fclose(FILE* fs);
114 
115 
116 //***************************************************************************
117 
118 // hpcio_leX_fread: Reads 'X' number of little-endian bytes from the file
119 // stream 'fs', correctly orders them for the current architecture,
120 // and stores the result in 'val'. Returns the number of bytes read.
121 
122 size_t
123 hpcio_le2_fread(uint16_t* val, FILE* fs);
124 
125 size_t
126 hpcio_le4_fread(uint32_t* val, FILE* fs);
127 
128 size_t
129 hpcio_le8_fread(uint64_t* val, FILE* fs);
130 
131 
132 size_t
133 hpcio_le2_fwrite(uint16_t* val, FILE* fs);
134 
135 size_t
136 hpcio_le4_fwrite(uint32_t* val, FILE* fs);
137 
138 size_t
139 hpcio_le8_fwrite(uint64_t* val, FILE* fs);
140 
141 
142 //***************************************************************************
143 
144 // hpcio_beX_fwrite: Write 'X' number of bytes from 'val' to the
145 // big-endian file stream 'fs', correctly ordering the bytes before
146 // writing. Returns the number of bytes written.
147 
148 size_t
149 hpcio_be2_fread(uint16_t* val, FILE* fs);
150 
151 size_t
152 hpcio_be4_fread(uint32_t* val, FILE* fs);
153 
154 size_t
155 hpcio_be8_fread(uint64_t* val, FILE* fs);
156 
157 size_t
158 hpcio_beX_fread(uint8_t* val, size_t size, FILE* fs);
159 
160 
161 size_t
162 hpcio_be2_fwrite(uint16_t* val, FILE* fs);
163 
164 size_t
165 hpcio_be4_fwrite(uint32_t* val, FILE* fs);
166 
167 size_t
168 hpcio_be8_fwrite(uint64_t* val, FILE* fs);
169 
170 size_t
171 hpcio_beX_fwrite(uint8_t* val, size_t size, FILE* fs);
172 
173 
174 //***************************************************************************
175 
176 #if defined(__cplusplus)
177 } /* extern "C" */
178 #endif
179 
180 #endif /* prof_lean_hpcio_h */
FILE * hpcio_fopen_r(const char *fnm)
Definition: hpcio.c:134
size_t hpcio_be8_fread(uint64_t *val, FILE *fs)
Definition: hpcio.c:311
size_t hpcio_le4_fwrite(uint32_t *val, FILE *fs)
Definition: hpcio.c:243
FILE * hpcio_fopen_rw(const char *fnm)
Definition: hpcio.c:143
FILE * hpcio_fopen_w(const char *fnm, int overwrite)
Definition: hpcio.c:100
size_t hpcio_beX_fread(uint8_t *val, size_t size, FILE *fs)
Definition: hpcio.c:328
size_t hpcio_le8_fread(uint64_t *val, FILE *fs)
Definition: hpcio.c:209
size_t hpcio_le4_fread(uint32_t *val, FILE *fs)
Definition: hpcio.c:192
size_t hpcio_be2_fwrite(uint16_t *val, FILE *fs)
Definition: hpcio.c:348
size_t hpcio_le2_fwrite(uint16_t *val, FILE *fs)
Definition: hpcio.c:228
size_t hpcio_be4_fread(uint32_t *val, FILE *fs)
Definition: hpcio.c:294
size_t hpcio_be8_fwrite(uint64_t *val, FILE *fs)
Definition: hpcio.c:378
size_t hpcio_beX_fwrite(uint8_t *val, size_t size, FILE *fs)
Definition: hpcio.c:393
size_t hpcio_le2_fread(uint16_t *val, FILE *fs)
Definition: hpcio.c:175
size_t hpcio_le8_fwrite(uint64_t *val, FILE *fs)
Definition: hpcio.c:258
int hpcio_fclose(FILE *fs)
Definition: hpcio.c:152
size_t hpcio_be2_fread(uint16_t *val, FILE *fs)
Definition: hpcio.c:277
size_t hpcio_be4_fwrite(uint32_t *val, FILE *fs)
Definition: hpcio.c:363