67 # define _POSIX_SOURCE // fdopen() 70 # define _SVID_SOURCE // fputc_unlocked() 102 mode_t mode = S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH;
106 if (overwrite == 0) {
108 fd = open(fnm, O_WRONLY | O_CREAT | O_EXCL, mode);
110 else if (overwrite == 1) {
112 fd = open(fnm, O_WRONLY | O_CREAT | O_TRUNC, mode);
114 else if (overwrite == 2) {
116 fd = open(fnm, O_WRONLY);
125 fs = fdopen(fd,
"w");
136 FILE* fs = fopen(fnm,
"r");
145 FILE* fs = fopen(fnm,
"r+");
155 if (fclose(fs) == EOF) {
178 int shift = 0, num_read = 0, c;
180 for (shift = 0; shift < 16; shift += 8) {
181 if ( (c = fgetc(fs)) == EOF ) {
break; }
183 v = (uint16_t)(v | ((c & 0xff) << shift));
195 int shift = 0, num_read = 0, c;
197 for (shift = 0; shift < 32; shift += 8) {
198 if ( (c = fgetc(fs)) == EOF ) {
break; }
200 v |= ((uint32_t)(c & 0xff) << shift);
212 int shift = 0, num_read = 0, c;
214 for (shift = 0; shift < 64; shift += 8) {
215 if ( (c = fgetc(fs)) == EOF ) {
break; }
217 v |= ((uint64_t)(c & 0xff) << shift);
231 int shift = 0, num_write = 0, c;
233 for (shift = 0; shift < 16; shift += 8) {
234 c = fputc( ((v >> shift) & 0xff) , fs);
235 if (c == EOF) {
break; }
246 int shift = 0, num_write = 0, c;
248 for (shift = 0; shift < 32; shift += 8) {
249 c = fputc( ((v >> shift) & 0xff) , fs);
250 if (c == EOF) {
break; }
261 int shift = 0, num_write = 0, c;
263 for (shift = 0; shift < 64; shift += 8) {
264 c = fputc( ((v >> shift) & 0xff) , fs);
265 if (c == EOF) {
break; }
280 int shift = 0, num_read = 0, c;
282 for (shift = 8; shift >= 0; shift -= 8) {
283 if ( (c = fgetc(fs)) == EOF ) {
break; }
285 v = (uint16_t)(v | ((c & 0xff) << shift));
297 int shift = 0, num_read = 0, c;
299 for (shift = 24; shift >= 0; shift -= 8) {
300 if ( (c = fgetc(fs)) == EOF ) {
break; }
302 v |= ((uint32_t)(c & 0xff) << shift);
314 int shift = 0, num_read = 0, c;
316 for (shift = 56; shift >= 0; shift -= 8) {
317 if ( (c = fgetc(fs)) == EOF ) {
break; }
319 v |= ((uint64_t)(c & 0xff) << shift);
332 for (
uint i = 0; i < size; ++i) {
337 val[i] = (uint8_t) c;
351 int shift = 0, num_write = 0, c;
353 for (shift = 8; shift >= 0; shift -= 8) {
354 c = fputc( ((v >> shift) & 0xff) , fs);
355 if (c == EOF) {
break; }
366 int shift = 0, num_write = 0, c;
368 for (shift = 24; shift >= 0; shift -= 8) {
369 c = fputc( ((v >> shift) & 0xff) , fs);
370 if (c == EOF) {
break; }
381 int shift = 0, num_write = 0, c;
383 for (shift = 56; shift >= 0; shift -= 8) {
384 c = fputc( ((v >> shift) & 0xff) , fs);
385 if (c == EOF) {
break; }
395 size_t num_write = 0;
397 for (
uint i = 0; i < size; ++i) {
398 int c = fputc(val[i], fs);
415 #define LITTLE_ENDIAN 1 419 hpcio_get_endianness()
421 uint16_t val = 0x0001;
422 char* bite = (
char*) &val;
423 if (bite[0] == 0x00) {
427 return LITTLE_ENDIAN;
size_t hpcio_be2_fread(uint16_t *val, FILE *fs)
size_t hpcio_le4_fwrite(uint32_t *val, FILE *fs)
size_t hpcio_le2_fwrite(uint16_t *val, FILE *fs)
size_t hpcio_be2_fwrite(uint16_t *val, FILE *fs)
size_t hpcio_le8_fread(uint64_t *val, FILE *fs)
size_t hpcio_be8_fwrite(uint64_t *val, FILE *fs)
size_t hpcio_le2_fread(uint16_t *val, FILE *fs)
size_t hpcio_be4_fwrite(uint32_t *val, FILE *fs)
FILE * hpcio_fopen_r(const char *fnm)
size_t hpcio_le8_fwrite(uint64_t *val, FILE *fs)
size_t hpcio_le4_fread(uint32_t *val, FILE *fs)
size_t hpcio_be4_fread(uint32_t *val, FILE *fs)
int hpcio_fclose(FILE *fs)
size_t hpcio_be8_fread(uint64_t *val, FILE *fs)
FILE * hpcio_fopen_rw(const char *fnm)
size_t hpcio_beX_fread(uint8_t *val, size_t size, FILE *fs)
FILE * hpcio_fopen_w(const char *fnm, int overwrite)
size_t hpcio_beX_fwrite(uint8_t *val, size_t size, FILE *fs)