Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
O
OBITools3
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
23
Issues
23
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
Operations
Operations
Incidents
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
OBITools
OBITools3
Commits
0dfd67ec
Commit
0dfd67ec
authored
Oct 10, 2016
by
Celine Mercier
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
The endianness of binary taxonomy files is now correctly checked
parent
0faaac49
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
50 additions
and
27 deletions
+50
-27
src/obidms_taxonomy.c
src/obidms_taxonomy.c
+46
-27
src/obidms_taxonomy.h
src/obidms_taxonomy.h
+4
-0
No files found.
src/obidms_taxonomy.c
View file @
0dfd67ec
...
...
@@ -18,6 +18,7 @@
#include "obidms_taxonomy.h"
#include "obidms.h"
#include "obilittlebigman.h" // TODO the function from this checking the endianness does not seem to work properly
#include "obidebug.h"
#include "obierrno.h"
#include "utils.h"
...
...
@@ -25,7 +26,23 @@
#define DEBUG_LEVEL 0 // TODO has to be defined somewhere else (cython compil flag?)
// TODO : the malloc aren't checked but won't exist for long because mapping instead
// TODO : the malloc aren't checked but shouldn't exist for long because mapping instead
// error checking and file closing in general aren't done properly yet
// The endianness eventually shouldn't need checking too, as the machine will write the taxonomy with its endianness.
int32_t
is_big_endian
()
{
int32_t
i
=
1
;
return
(
int32_t
)((
char
*
)
&
i
)[
0
];
}
int32_t
swap_int32_t
(
int32_t
i
)
{
return
SWAPINT32
(
i
);
}
int
compareRankLabel
(
const
void
*
label1
,
const
void
*
label2
)
...
...
@@ -61,22 +78,23 @@ void* read_ecorecord(FILE* f, int32_t* record_size)
}
read
=
fread
(
record_size
,
1
,
sizeof
(
int32_t
),
1
,
f
);
if
(
feof
(
f
))
return
NULL
;
if
(
read
!=
sizeof
(
int32_t
)
)
if
(
read
!=
1
)
{
obi_set_errno
(
OBI_TAXONOMY_ERROR
);
obidebug
(
1
,
"
\n
Error reading a taxonomy file: error reading record size"
);
return
NULL
;
}
// if (is_big_endian()) // TODO
// *recordSize=swap_int32_t(*recordSize);
// if (!(obi_is_little_endian())) // TODO
if
(
is_big_endian
())
*
record_size
=
swap_int32_t
(
*
record_size
);
if
(
buffer_size
<
*
record_size
)
{
...
...
@@ -93,11 +111,11 @@ void* read_ecorecord(FILE* f, int32_t* record_size)
}
read
=
fread
(
buffer
,
1
,
*
record_size
,
1
,
f
);
if
(
read
!=
*
record_size
)
if
(
read
!=
1
)
{
obi_set_errno
(
OBI_TAXONOMY_ERROR
);
obidebug
(
1
,
"
\n
Error reading a taxonomy file: error reading a record %d, %d"
,
read
,
*
record_size
);
...
...
@@ -118,13 +136,14 @@ ecotx_t* readnext_ecotaxon(FILE* f, ecotx_t* taxon)
if
(
!
raw
)
return
NULL
;
// if (is_big_endian()) // TODO
// {
// raw->namelength = swap_int32_t(raw->namelength);
// raw->parent = swap_int32_t(raw->parent);
// raw->rank = swap_int32_t(raw->rank);
// raw->taxid = swap_int32_t(raw->taxid);
// }
// if (!(obi_is_little_endian())) // TODO
if
(
is_big_endian
())
{
raw
->
name_length
=
swap_int32_t
(
raw
->
name_length
);
raw
->
parent
=
swap_int32_t
(
raw
->
parent
);
raw
->
rank
=
swap_int32_t
(
raw
->
rank
);
raw
->
taxid
=
swap_int32_t
(
raw
->
taxid
);
}
taxon
->
parent
=
(
ecotx_t
*
)
((
size_t
)
raw
->
parent
);
taxon
->
taxid
=
raw
->
taxid
;
...
...
@@ -146,8 +165,6 @@ FILE* open_ecorecorddb(const char* file_name,
FILE
*
f
;
int32_t
read
;
fprintf
(
stderr
,
"
\n
%s
\n
"
,
file_name
);
f
=
fopen
(
file_name
,
"rb"
);
if
(
!
f
)
...
...
@@ -166,19 +183,20 @@ FILE* open_ecorecorddb(const char* file_name,
}
read
=
fread
(
count
,
1
,
sizeof
(
int32_t
),
1
,
f
);
if
(
read
!=
sizeof
(
int32_t
)
)
if
(
read
!=
1
)
{
obi_set_errno
(
OBI_TAXONOMY_ERROR
);
obidebug
(
1
,
"
\n
Error reading taxonomy record size"
);
return
NULL
;
}
// if (!obi_is_little_endian()) // TODO
// *count = swap_int32_t(*count);
// if (!(obi_is_little_endian())) // TODO
if
(
is_big_endian
())
*
count
=
swap_int32_t
(
*
count
);
return
f
;
}
...
...
@@ -302,13 +320,14 @@ econame_t* readnext_econame(FILE* f, econame_t* name, OBIDMS_taxonomy_p taxonomy
if
(
!
raw
)
return
NULL
;
// if (is_big_endian()) // TODO
// {
// raw->is_scientificname = swap_int32_t(raw->is_scientificname);
// raw->namelength = swap_int32_t(raw->namelength);
// raw->classlength = swap_int32_t(raw->classlength);
// raw->taxid = swap_int32_t(raw->taxid);
// }
// if (!(obi_is_little_endian())) // TODO
if
(
is_big_endian
())
{
raw
->
is_scientific_name
=
swap_int32_t
(
raw
->
is_scientific_name
);
raw
->
name_length
=
swap_int32_t
(
raw
->
name_length
);
raw
->
class_length
=
swap_int32_t
(
raw
->
class_length
);
raw
->
taxid
=
swap_int32_t
(
raw
->
taxid
);
}
name
->
is_scientific_name
=
raw
->
is_scientific_name
;
...
...
src/obidms_taxonomy.h
View file @
0dfd67ec
...
...
@@ -17,6 +17,10 @@
#include "obidms.h"
#define SWAPINT32(x) ((((x) << 24) & 0xFF000000) | (((x) << 8) & 0xFF0000) | \
(((x) >> 8) & 0xFF00) | (((x) >> 24) & 0xFF))
typedef
struct
{
int32_t
taxid
;
int32_t
rank
;
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a 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