Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
mpim-sw
libcdi
Commits
31b8b25a
Commit
31b8b25a
authored
May 31, 2017
by
Uwe Schulzweida
Browse files
cdiGetFiletype: check whether file is empty or a directory.
parent
d1c0158c
Changes
3
Hide whitespace changes
Inline
Side-by-side
src/cdi.h
View file @
31b8b25a
...
...
@@ -36,11 +36,13 @@ extern "C" {
#define CDI_EEOF -1 // The end of file was encountered
#define CDI_ESYSTEM -10 // Operating system error
#define CDI_EINVAL -20 // Invalid argument
#define CDI_EUFTYPE -21 // Unsupported file type
#define CDI_ELIBNAVAIL -22 // xxx library not available
#define CDI_EUFSTRUCT -23 // Unsupported file structure
#define CDI_EUNC4 -24 // Unsupported NetCDF4 structure
#define CDI_EDIMSIZE -25 // Invalid dimension size
#define CDI_EISDIR -21 // Is a directory
#define CDI_EISEMPTY -22 // Is empty
#define CDI_EUFTYPE -23 // Unsupported file type
#define CDI_ELIBNAVAIL -24 // xxx library not available
#define CDI_EUFSTRUCT -25 // Unsupported file structure
#define CDI_EUNC4 -26 // Unsupported NetCDF4 structure
#define CDI_EDIMSIZE -27 // Invalid dimension size
#define CDI_ELIMIT -99 // Internal limits exceeded
/* File types */
...
...
src/cdi_error.c
View file @
31b8b25a
#if defined (HAVE_CONFIG_H)
#
include "config.h"
#include
"config.h"
#endif
#include
<stdio.h>
...
...
@@ -10,6 +10,8 @@
const
char
*
cdiStringError
(
int
cdiErrno
)
{
static
const
char
UnknownError
[]
=
"Unknown Error"
;
static
const
char
_EISDIR
[]
=
"Is a directory"
;
static
const
char
_EISEMPTY
[]
=
"File is empty"
;
static
const
char
_EUFTYPE
[]
=
"Unsupported file type"
;
static
const
char
_ELIBNAVAIL
[]
=
"Unsupported file type (library support not compiled in)"
;
static
const
char
_EUFSTRUCT
[]
=
"Unsupported file structure"
;
...
...
@@ -24,6 +26,8 @@ const char *cdiStringError(int cdiErrno)
if
(
cp
==
NULL
)
break
;
return
cp
;
}
case
CDI_EISDIR
:
return
_EISDIR
;
case
CDI_EISEMPTY
:
return
_EISEMPTY
;
case
CDI_EUFTYPE
:
return
_EUFTYPE
;
case
CDI_ELIBNAVAIL
:
return
_ELIBNAVAIL
;
case
CDI_EUFSTRUCT
:
return
_EUFSTRUCT
;
...
...
src/stream.c
View file @
31b8b25a
...
...
@@ -6,6 +6,7 @@
#define _XOPEN_SOURCE 600
#endif
#include
<sys/stat.h>
// struct stat
#include
<ctype.h>
#include
"binary.h"
...
...
@@ -78,7 +79,6 @@ int cdiGetFiletype(const char *filename, int *byteorder)
int
swap
=
0
;
int
version
;
long
recpos
;
char
buffer
[
8
];
int
fileID
=
fileOpen
(
filename
,
"r"
);
...
...
@@ -90,7 +90,18 @@ int cdiGetFiletype(const char *filename, int *byteorder)
return
CDI_ESYSTEM
;
}
if
(
fileRead
(
fileID
,
buffer
,
8
)
!=
8
)
return
CDI_EUFTYPE
;
char
buffer
[
8
];
if
(
fileRead
(
fileID
,
buffer
,
8
)
!=
8
)
{
struct
stat
buf
;
if
(
stat
(
filename
,
&
buf
)
==
0
)
{
if
(
buf
.
st_size
==
0
)
return
CDI_EISEMPTY
;
if
(
buf
.
st_mode
&
S_IFDIR
)
return
CDI_EISDIR
;
}
return
CDI_EUFTYPE
;
}
fileRewind
(
fileID
);
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment