SIONlib  1.7.7
Scalable I/O library for parallel access to task-local files
sion_tools.c
Go to the documentation of this file.
1 /****************************************************************************
2 ** SIONLIB http://www.fz-juelich.de/jsc/sionlib **
3 *****************************************************************************
4 ** Copyright (c) 2008-2019 **
5 ** Forschungszentrum Juelich, Juelich Supercomputing Centre **
6 ** **
7 ** See the file COPYRIGHT in the package base directory for details **
8 ****************************************************************************/
9 
14 #define _XOPEN_SOURCE 700
15 
16 #include <stdlib.h>
17 #include <stdio.h>
18 
19 #include "sion.h"
20 #include "sion_debug.h"
21 #include "sion_error_handler.h"
22 #include "sion_internal.h"
23 #include "sion_fd.h"
24 #include "sion_filedesc.h"
25 #include "sion_tools.h"
26 
33 {
34 
35  /* Are we little or big endian? From Harbison&Steele. */
36  union
37  {
38  long l;
39  char c[sizeof(long)];
40  } u;
41 
42  u.l = 1;
43  return (u.c[sizeof(long) - 1] == 1);
44 
45 }
46 
51 int sion_get_version(int *main_version,int *sub_version,int *patch_level,int *fileformat_version)
52 {
53  *main_version = SION_MAIN_VERSION;
54  *sub_version = SION_SUB_VERSION;
55  *patch_level = SION_VERSION_PATCHLEVEL;
56  *fileformat_version = SION_FILEFORMAT_VERSION;
57  return(SION_SUCCESS);
58 }
59 
60 FILE *sion_get_fp(int sid)
61 {
62  _sion_filedesc *sion_filedesc;
63 
64  if ((sid<0) || (_sion_vcdtype(sid) != SION_FILEDESCRIPTOR)
65  || !(sion_filedesc = _sion_vcdtovcon(sid))) {
66  _sion_errorprint(SION_NOT_SUCCESS,_SION_ERROR_RETURN,"sion_get_fp: invalid sion_filedesc sid=%d ...\n",sid);
67  return (NULL);
68  }
69 
70  if(sion_filedesc->fileptr->flags&SION_FILE_FLAG_ANSI) {
71  if(sion_filedesc->fileptr->flags&SION_FILE_FLAG_SCNDANSI) {
72  return(sion_filedesc->fileptr->second_fileptr);
73  } else {
74  return(sion_filedesc->fileptr->fileptr);
75  }
76  } else {
77  return(NULL);
78  }
79 }
80 
81 int sion_get_fd(int sid)
82 {
83  _sion_filedesc *sion_filedesc;
84 
85  if ((sid<0) || (_sion_vcdtype(sid) != SION_FILEDESCRIPTOR)
86  || !(sion_filedesc = _sion_vcdtovcon(sid))) {
87  _sion_errorprint(SION_NOT_SUCCESS,_SION_ERROR_RETURN,"sion_get_fp: invalid sion_filedesc sid=%d ...\n",sid);
88  return (SION_ID_UNDEF);
89  }
90 
91  if(sion_filedesc->fileptr->flags&SION_FILE_FLAG_POSIX) {
92  return(sion_filedesc->fileptr->fd);
93  } else {
94  return(SION_ID_UNDEF);
95  }
96 
97 }
98 
99 
100 _sion_filedesc *_sion_get_filedesc(int sid)
101 {
102  _sion_filedesc *sion_filedesc;
103 
104  if ((sid<0) || (_sion_vcdtype(sid) != SION_FILEDESCRIPTOR)
105  || !(sion_filedesc = _sion_vcdtovcon(sid))) {
106  _sion_errorprint(SION_NOT_SUCCESS,_SION_ERROR_RETURN,"sion_get_fp: invalid sion_filedesc sid=%d ...\n",sid);
107  return (NULL);
108  }
109 
110  return (sion_filedesc);
111 }
112 
113 
void * _sion_vcdtovcon(int sid)
Definition: sion_fd.c:53
int _sion_vcdtype(int sid)
Definition: sion_fd.c:58
#define SION_FILEDESCRIPTOR
Definition: sion_fd.h:17
#define SION_FILE_FLAG_ANSI
Definition: sion_file.h:25
#define SION_FILE_FLAG_SCNDANSI
Definition: sion_file.h:26
#define SION_FILE_FLAG_POSIX
Definition: sion_file.h:27
int sion_get_version(int *main_version, int *sub_version, int *patch_level, int *fileformat_version)
Return version numbers.
Definition: sion_tools.c:51
int sion_get_endianness(void)
Return endianness.
Definition: sion_tools.c:32
Sion File Descriptor Structure.
Definition: sion_filedesc.h:79
_sion_fileptr * fileptr
Definition: sion_filedesc.h:82