[med-svn] [Git][med-team/edflib][upstream] New upstream version 1.23
Étienne Mollier (@emollier)
gitlab at salsa.debian.org
Sat Oct 22 11:19:54 BST 2022
Étienne Mollier pushed to branch upstream at Debian Med / edflib
Commits:
529a35ac by Étienne Mollier at 2022-10-22T11:19:34+02:00
New upstream version 1.23
- - - - -
4 changed files:
- README.md
- edflib.c
- edflib.h
- unittest/unittest.c
Changes:
=====================================
README.md
=====================================
@@ -22,6 +22,8 @@ For example:
Compilation has been tested using GCC on Linux, Mingw-w64 on Windows, and LLVM GCC on OS X (Yosemite).
+Big-endian systems are not supported.
+
To understand how to use the library, read the comments in `edflib.h`.
=====================================
edflib.c
=====================================
@@ -35,7 +35,7 @@
#include "edflib.h"
-#define EDFLIB_VERSION (122)
+#define EDFLIB_VERSION (123)
#define EDFLIB_MAXFILES (64)
#if defined(__APPLE__) || defined(__MACH__) || defined(__APPLE_CC__) || defined(__HAIKU__) || defined(__ANDROID__)
@@ -200,10 +200,7 @@ int edflib_is_file_used(const char *path)
{
if(hdrlist[i]!=NULL)
{
- if(!(strcmp(path, hdrlist[i]->path)))
- {
- return 1;
- }
+ if(!(strcmp(path, hdrlist[i]->path))) return 1;
}
}
@@ -225,10 +222,7 @@ int edflib_get_handle(int file_number)
{
if(hdrlist[i]!=NULL)
{
- if(file_count++ == file_number)
- {
- return i;
- }
+ if(file_count++ == file_number) return i;
}
}
@@ -246,22 +240,45 @@ int edfopen_file_readonly(const char *path, struct edf_hdr_struct *edfhdr, int r
struct edfhdrblock *hdr;
+ union
+ {
+ char four[4];
+ int one;
+ } byte_order_test_var;
+
+ memset(edfhdr, 0, sizeof(struct edf_hdr_struct));
- if(read_annotations_mode<0)
+ /* avoid surprises! */
+ if((sizeof(char) != 1) ||
+ (sizeof(short) != 2) ||
+ (sizeof(int) != 4) ||
+ (sizeof(long long) != 8) ||
+ (sizeof(float) != 4) ||
+ (sizeof(double) != 8))
{
- edfhdr->filetype = EDFLIB_INVALID_READ_ANNOTS_VALUE;
+ edfhdr->filetype = EDFLIB_ARCH_ERROR;
return -1;
}
- if(read_annotations_mode>2)
+ /* check endianness! */
+ byte_order_test_var.one = 0x03020100;
+ if((byte_order_test_var.four[0] != 0) ||
+ (byte_order_test_var.four[1] != 1) ||
+ (byte_order_test_var.four[2] != 2) ||
+ (byte_order_test_var.four[3] != 3))
{
- edfhdr->filetype = EDFLIB_INVALID_READ_ANNOTS_VALUE;
+ edfhdr->filetype = EDFLIB_ARCH_ERROR;
return -1;
}
- memset(edfhdr, 0, sizeof(struct edf_hdr_struct));
+ if((read_annotations_mode<0)||(read_annotations_mode>2))
+ {
+ edfhdr->filetype = EDFLIB_INVALID_READ_ANNOTS_VALUE;
+
+ return -1;
+ }
if(edf_files_open>=EDFLIB_MAXFILES)
{
@@ -313,8 +330,6 @@ int edfopen_file_readonly(const char *path, struct edf_hdr_struct *edfhdr, int r
return -1;
}
- hdr->writemode = 0;
-
for(i=0; i<EDFLIB_MAXFILES; i++)
{
if(hdrlist[i]==NULL)
@@ -371,23 +386,9 @@ int edfopen_file_readonly(const char *path, struct edf_hdr_struct *edfhdr, int r
{
edflib_strlcpy(edfhdr->patient, hdr->patient, 81);
edflib_strlcpy(edfhdr->recording, hdr->recording, 81);
- edfhdr->patientcode[0] = 0;
- edfhdr->gender[0] = 0;
- edfhdr->birthdate[0] = 0;
- edfhdr->birthdate_day = 0;
- edfhdr->birthdate_month = 0;
- edfhdr->birthdate_year = 0;
- edfhdr->patient_name[0] = 0;
- edfhdr->patient_additional[0] = 0;
- edfhdr->admincode[0] = 0;
- edfhdr->technician[0] = 0;
- edfhdr->equipment[0] = 0;
- edfhdr->recording_additional[0] = 0;
}
else
{
- edfhdr->patient[0] = 0;
- edfhdr->recording[0] = 0;
edflib_strlcpy(edfhdr->patientcode, hdr->plus_patientcode, 81);
edflib_strlcpy(edfhdr->gender, hdr->plus_gender, 16);
edflib_strlcpy(edfhdr->birthdate, hdr->plus_birthdate, 16);
@@ -473,20 +474,9 @@ int edfclose_file(int handle)
struct edfhdrblock *hdr;
- if(handle<0)
- {
- return -1;
- }
-
- if(handle>=EDFLIB_MAXFILES)
- {
- return -1;
- }
+ if((handle<0)||(handle>=EDFLIB_MAXFILES)) return -1;
- if(hdrlist[handle]==NULL)
- {
- return -1;
- }
+ if(hdrlist[handle]==NULL) return -1;
hdr = hdrlist[handle];
@@ -692,36 +682,15 @@ long long edfseek(int handle, int edfsignal, long long offset, int whence)
int channel;
+ if((handle<0)||(handle>=EDFLIB_MAXFILES)) return -1;
- if(handle<0)
- {
- return -1;
- }
-
- if(handle>=EDFLIB_MAXFILES)
- {
- return -1;
- }
-
- if(hdrlist[handle]==NULL)
- {
- return -1;
- }
+ if(hdrlist[handle]==NULL) return -1;
- if(edfsignal<0)
- {
- return -1;
- }
+ if(edfsignal<0) return -1;
- if(hdrlist[handle]->writemode)
- {
- return -1;
- }
+ if(hdrlist[handle]->writemode) return -1;
- if(edfsignal>=(hdrlist[handle]->edfsignals - hdrlist[handle]->nr_annot_chns))
- {
- return -1;
- }
+ if(edfsignal>=(hdrlist[handle]->edfsignals - hdrlist[handle]->nr_annot_chns)) return -1;
channel = hdrlist[handle]->mapped_signals[edfsignal];
@@ -761,36 +730,15 @@ long long edftell(int handle, int edfsignal)
{
int channel;
+ if((handle<0)||(handle>=EDFLIB_MAXFILES)) return -1;
- if(handle<0)
- {
- return -1;
- }
-
- if(handle>=EDFLIB_MAXFILES)
- {
- return -1;
- }
-
- if(hdrlist[handle]==NULL)
- {
- return -1;
- }
+ if(hdrlist[handle]==NULL) return -1;
- if(edfsignal<0)
- {
- return -1;
- }
+ if(edfsignal<0) return -1;
- if(hdrlist[handle]->writemode)
- {
- return -1;
- }
+ if(hdrlist[handle]->writemode) return -1;
- if(edfsignal>=(hdrlist[handle]->edfsignals - hdrlist[handle]->nr_annot_chns))
- {
- return -1;
- }
+ if(edfsignal>=(hdrlist[handle]->edfsignals - hdrlist[handle]->nr_annot_chns)) return -1;
channel = hdrlist[handle]->mapped_signals[edfsignal];
@@ -802,36 +750,15 @@ void edfrewind(int handle, int edfsignal)
{
int channel;
+ if((handle<0)||(handle>=EDFLIB_MAXFILES)) return;
- if(handle<0)
- {
- return;
- }
-
- if(handle>=EDFLIB_MAXFILES)
- {
- return;
- }
-
- if(hdrlist[handle]==NULL)
- {
- return;
- }
+ if(hdrlist[handle]==NULL) return;
- if(edfsignal<0)
- {
- return;
- }
+ if(edfsignal<0) return;
- if(hdrlist[handle]->writemode)
- {
- return;
- }
+ if(hdrlist[handle]->writemode) return;
- if(edfsignal>=(hdrlist[handle]->edfsignals - hdrlist[handle]->nr_annot_chns))
- {
- return;
- }
+ if(edfsignal>=(hdrlist[handle]->edfsignals - hdrlist[handle]->nr_annot_chns)) return;
channel = hdrlist[handle]->mapped_signals[edfsignal];
@@ -867,48 +794,21 @@ int edfread_physical_samples(int handle, int edfsignal, int n, double *buf)
FILE *file;
+ if((handle<0)||(handle>=EDFLIB_MAXFILES)) return -1;
- if(handle<0)
- {
- return -1;
- }
-
- if(handle>=EDFLIB_MAXFILES)
- {
- return -1;
- }
-
- if(hdrlist[handle]==NULL)
- {
- return -1;
- }
+ if(hdrlist[handle]==NULL) return -1;
- if(edfsignal<0)
- {
- return -1;
- }
+ if(edfsignal<0) return -1;
- if(hdrlist[handle]->writemode)
- {
- return -1;
- }
+ if(hdrlist[handle]->writemode) return -1;
- if(edfsignal>=(hdrlist[handle]->edfsignals - hdrlist[handle]->nr_annot_chns))
- {
- return -1;
- }
+ if(edfsignal>=(hdrlist[handle]->edfsignals - hdrlist[handle]->nr_annot_chns)) return -1;
channel = hdrlist[handle]->mapped_signals[edfsignal];
- if(n<0LL)
- {
- return -1;
- }
+ if(n<0LL) return -1;
- if(n==0LL)
- {
- return 0LL;
- }
+ if(n==0LL) return 0LL;
hdr = hdrlist[handle];
@@ -928,15 +828,9 @@ int edfread_physical_samples(int handle, int edfsignal, int n, double *buf)
{
n = smp_in_file - hdr->edfparam[channel].sample_pntr;
- if(n==0)
- {
- return 0LL;
- }
+ if(n==0) return 0LL;
- if(n<0)
- {
- return -1;
- }
+ if(n<0) return -1;
}
file = hdr->file_hdl;
@@ -1008,10 +902,7 @@ int edfread_physical_samples(int handle, int edfsignal, int n, double *buf)
var.four[0] = fgetc(file);
var.four[1] = fgetc(file);
tmp = fgetc(file);
- if(tmp==EOF)
- {
- return -1;
- }
+ if(tmp==EOF) return -1;
var.four[2] = tmp;
if(var.four[2]&0x80)
@@ -1069,48 +960,21 @@ int edfread_digital_samples(int handle, int edfsignal, int n, int *buf)
FILE *file;
+ if((handle<0)||(handle>=EDFLIB_MAXFILES)) return -1;
- if(handle<0)
- {
- return -1;
- }
-
- if(handle>=EDFLIB_MAXFILES)
- {
- return -1;
- }
-
- if(hdrlist[handle]==NULL)
- {
- return -1;
- }
+ if(hdrlist[handle]==NULL) return -1;
- if(edfsignal<0)
- {
- return -1;
- }
+ if(edfsignal<0) return -1;
- if(hdrlist[handle]->writemode)
- {
- return -1;
- }
+ if(hdrlist[handle]->writemode) return -1;
- if(edfsignal>=(hdrlist[handle]->edfsignals - hdrlist[handle]->nr_annot_chns))
- {
- return -1;
- }
+ if(edfsignal>=(hdrlist[handle]->edfsignals - hdrlist[handle]->nr_annot_chns)) return -1;
channel = hdrlist[handle]->mapped_signals[edfsignal];
- if(n<0LL)
- {
- return -1;
- }
+ if(n<0LL) return -1;
- if(n==0LL)
- {
- return 0LL;
- }
+ if(n==0LL) return 0LL;
hdr = hdrlist[handle];
@@ -1170,10 +1034,7 @@ int edfread_digital_samples(int handle, int edfsignal, int n, int *buf)
var.four[0] = fgetc(file);
tmp = fgetc(file);
- if(tmp==EOF)
- {
- return -1;
- }
+ if(tmp==EOF) return -1;
var.four[1] = tmp;
if(var.two_signed[0] > hdr->edfparam[channel].dig_max)
@@ -1206,10 +1067,7 @@ int edfread_digital_samples(int handle, int edfsignal, int n, int *buf)
var.four[0] = fgetc(file);
var.four[1] = fgetc(file);
tmp = fgetc(file);
- if(tmp==EOF)
- {
- return -1;
- }
+ if(tmp==EOF) return -1;
var.four[2] = tmp;
if(var.four[2]&0x80)
@@ -1246,35 +1104,15 @@ int edf_get_annotation(int handle, int n, struct edf_annotation_struct *annot)
{
memset(annot, 0, sizeof(struct edf_annotation_struct));
- if(handle<0)
- {
- return -1;
- }
-
- if(handle>=EDFLIB_MAXFILES)
- {
- return -1;
- }
+ if((handle<0)||(handle>=EDFLIB_MAXFILES)) return -1;
- if(hdrlist[handle]==NULL)
- {
- return -1;
- }
+ if(hdrlist[handle]==NULL) return -1;
- if(hdrlist[handle]->writemode)
- {
- return -1;
- }
+ if(hdrlist[handle]->writemode) return -1;
- if(n<0)
- {
- return -1;
- }
+ if(n<0) return -1;
- if(n>=hdrlist[handle]->annots_in_file)
- {
- return -1;
- }
+ if(n>=hdrlist[handle]->annots_in_file) return -1;
annot->onset = (annotationslist[handle] + n)->onset;
annot->duration_l = (annotationslist[handle] + n)->duration_l;
@@ -1454,7 +1292,7 @@ static struct edfhdrblock * edflib_check_edf_file(FILE *inputfile, int *edf_erro
scratchpad[5] = 0;
scratchpad[8] = 0;
- if((edflib_atof_nonlocalized(scratchpad)<1)||(edflib_atof_nonlocalized(scratchpad)>31))
+ if((edflib_atoi_nonlocalized(scratchpad)<1)||(edflib_atoi_nonlocalized(scratchpad)>31))
{
strncpy(scratchpad, edf_hdr + 168, 8);
scratchpad[8] = 0;
@@ -1464,7 +1302,7 @@ static struct edfhdrblock * edflib_check_edf_file(FILE *inputfile, int *edf_erro
return NULL;
}
- if((edflib_atof_nonlocalized(scratchpad+3)<1)||(edflib_atof_nonlocalized(scratchpad+3)>12))
+ if((edflib_atoi_nonlocalized(scratchpad+3)<1)||(edflib_atoi_nonlocalized(scratchpad+3)>12))
{
strncpy(scratchpad, edf_hdr + 168, 8);
scratchpad[8] = 0;
@@ -1474,9 +1312,9 @@ static struct edfhdrblock * edflib_check_edf_file(FILE *inputfile, int *edf_erro
return NULL;
}
- edfhdr->startdate_day = edflib_atof_nonlocalized(scratchpad);
- edfhdr->startdate_month = edflib_atof_nonlocalized(scratchpad + 3);
- edfhdr->startdate_year = edflib_atof_nonlocalized(scratchpad + 6);
+ edfhdr->startdate_day = edflib_atoi_nonlocalized(scratchpad);
+ edfhdr->startdate_month = edflib_atoi_nonlocalized(scratchpad + 3);
+ edfhdr->startdate_year = edflib_atoi_nonlocalized(scratchpad + 6);
if(edfhdr->startdate_year>84)
{
edfhdr->startdate_year += 1900;
@@ -1527,7 +1365,7 @@ static struct edfhdrblock * edflib_check_edf_file(FILE *inputfile, int *edf_erro
scratchpad[5] = 0;
scratchpad[8] = 0;
- if(edflib_atof_nonlocalized(scratchpad)>23)
+ if(edflib_atoi_nonlocalized(scratchpad)>23)
{
strncpy(scratchpad, edf_hdr + 176, 8);
scratchpad[8] = 0;
@@ -1537,7 +1375,7 @@ static struct edfhdrblock * edflib_check_edf_file(FILE *inputfile, int *edf_erro
return NULL;
}
- if(edflib_atof_nonlocalized(scratchpad+3)>59)
+ if(edflib_atoi_nonlocalized(scratchpad+3)>59)
{
strncpy(scratchpad, edf_hdr + 176, 8);
scratchpad[8] = 0;
@@ -1547,7 +1385,7 @@ static struct edfhdrblock * edflib_check_edf_file(FILE *inputfile, int *edf_erro
return NULL;
}
- if(edflib_atof_nonlocalized(scratchpad+6)>59)
+ if(edflib_atoi_nonlocalized(scratchpad+6)>59)
{
strncpy(scratchpad, edf_hdr + 176, 8);
scratchpad[8] = 0;
@@ -1557,13 +1395,13 @@ static struct edfhdrblock * edflib_check_edf_file(FILE *inputfile, int *edf_erro
return NULL;
}
- edfhdr->starttime_hour = edflib_atof_nonlocalized(scratchpad);
- edfhdr->starttime_minute = edflib_atof_nonlocalized(scratchpad + 3);
- edfhdr->starttime_second = edflib_atof_nonlocalized(scratchpad + 6);
+ edfhdr->starttime_hour = edflib_atoi_nonlocalized(scratchpad);
+ edfhdr->starttime_minute = edflib_atoi_nonlocalized(scratchpad + 3);
+ edfhdr->starttime_second = edflib_atoi_nonlocalized(scratchpad + 6);
- edfhdr->l_starttime = 3600 * edflib_atof_nonlocalized(scratchpad);
- edfhdr->l_starttime += 60 * edflib_atof_nonlocalized(scratchpad + 3);
- edfhdr->l_starttime += edflib_atof_nonlocalized(scratchpad + 6);
+ edfhdr->l_starttime = 3600 * edflib_atoi_nonlocalized(scratchpad);
+ edfhdr->l_starttime += 60 * edflib_atoi_nonlocalized(scratchpad + 3);
+ edfhdr->l_starttime += edflib_atoi_nonlocalized(scratchpad + 6);
edfhdr->l_starttime *= EDFLIB_TIME_DIMENSION;
@@ -1589,7 +1427,7 @@ static struct edfhdrblock * edflib_check_edf_file(FILE *inputfile, int *edf_erro
free(edfhdr);
return NULL;
}
- edfhdr->edfsignals = edflib_atof_nonlocalized(scratchpad);
+ edfhdr->edfsignals = edflib_atoi_nonlocalized(scratchpad);
if(edfhdr->edfsignals<1)
{
*edf_error = EDFLIB_FILE_CONTAINS_FORMAT_ERRORS;
@@ -1630,7 +1468,7 @@ static struct edfhdrblock * edflib_check_edf_file(FILE *inputfile, int *edf_erro
return NULL;
}
- n = edflib_atof_nonlocalized(scratchpad);
+ n = edflib_atoi_nonlocalized(scratchpad);
if((edfhdr->edfsignals * 256 + 256)!=n)
{
*edf_error = EDFLIB_FILE_CONTAINS_FORMAT_ERRORS;
@@ -1712,7 +1550,7 @@ static struct edfhdrblock * edflib_check_edf_file(FILE *inputfile, int *edf_erro
return NULL;
}
- edfhdr->datarecords = edflib_atof_nonlocalized(scratchpad);
+ edfhdr->datarecords = edflib_atoi_nonlocalized(scratchpad);
if(edfhdr->datarecords<1)
{
*edf_error = EDFLIB_FILE_CONTAINS_FORMAT_ERRORS;
@@ -2008,12 +1846,12 @@ static struct edfhdrblock * edflib_check_edf_file(FILE *inputfile, int *edf_erro
return NULL;
}
- n = edflib_atof_nonlocalized(scratchpad);
+ n = edflib_atoi_nonlocalized(scratchpad);
if(edfhdr->edfplus)
{
if(edfhdr->edfparam[i].annotation)
{
- if(n!=-32768)
+ if(n!=-0x8000)
{
*edf_error = EDFLIB_FILE_CONTAINS_FORMAT_ERRORS;
free(edf_hdr);
@@ -2027,7 +1865,7 @@ static struct edfhdrblock * edflib_check_edf_file(FILE *inputfile, int *edf_erro
{
if(edfhdr->edfparam[i].annotation)
{
- if(n!=-8388608)
+ if(n!=-0x800000)
{
*edf_error = EDFLIB_FILE_CONTAINS_FORMAT_ERRORS;
free(edf_hdr);
@@ -2039,7 +1877,7 @@ static struct edfhdrblock * edflib_check_edf_file(FILE *inputfile, int *edf_erro
}
if(edfhdr->edf)
{
- if((n>32767)||(n<-32768))
+ if((n>0x7fff)||(n<-0x8000))
{
*edf_error = EDFLIB_FILE_CONTAINS_FORMAT_ERRORS;
free(edf_hdr);
@@ -2050,7 +1888,7 @@ static struct edfhdrblock * edflib_check_edf_file(FILE *inputfile, int *edf_erro
}
if(edfhdr->bdf)
{
- if((n>8388607)||(n<-8388608))
+ if((n>0x7fffff)||(n<-0x800000))
{
*edf_error = EDFLIB_FILE_CONTAINS_FORMAT_ERRORS;
free(edf_hdr);
@@ -2090,12 +1928,12 @@ static struct edfhdrblock * edflib_check_edf_file(FILE *inputfile, int *edf_erro
return NULL;
}
- n = edflib_atof_nonlocalized(scratchpad);
+ n = edflib_atoi_nonlocalized(scratchpad);
if(edfhdr->edfplus)
{
if(edfhdr->edfparam[i].annotation)
{
- if(n!=32767)
+ if(n!=0x7fff)
{
*edf_error = EDFLIB_FILE_CONTAINS_FORMAT_ERRORS;
free(edf_hdr);
@@ -2109,7 +1947,7 @@ static struct edfhdrblock * edflib_check_edf_file(FILE *inputfile, int *edf_erro
{
if(edfhdr->edfparam[i].annotation)
{
- if(n!=8388607)
+ if(n!=0x7fffff)
{
*edf_error = EDFLIB_FILE_CONTAINS_FORMAT_ERRORS;
free(edf_hdr);
@@ -2121,7 +1959,7 @@ static struct edfhdrblock * edflib_check_edf_file(FILE *inputfile, int *edf_erro
}
if(edfhdr->edf)
{
- if((n>32767)||(n<-32768))
+ if((n>0x7fff)||(n<-0x8000))
{
*edf_error = EDFLIB_FILE_CONTAINS_FORMAT_ERRORS;
free(edf_hdr);
@@ -2132,7 +1970,7 @@ static struct edfhdrblock * edflib_check_edf_file(FILE *inputfile, int *edf_erro
}
else
{
- if((n>8388607)||(n<-8388608))
+ if((n>0x7fffff)||(n<-0x800000))
{
*edf_error = EDFLIB_FILE_CONTAINS_FORMAT_ERRORS;
free(edf_hdr);
@@ -2220,7 +2058,7 @@ static struct edfhdrblock * edflib_check_edf_file(FILE *inputfile, int *edf_erro
return NULL;
}
- n = edflib_atof_nonlocalized(scratchpad);
+ n = edflib_atoi_nonlocalized(scratchpad);
if(n<1)
{
*edf_error = EDFLIB_FILE_CONTAINS_FORMAT_ERRORS;
@@ -2326,7 +2164,7 @@ static struct edfhdrblock * edflib_check_edf_file(FILE *inputfile, int *edf_erro
if((scratchpad2[8]<48)||(scratchpad2[8]>57)) error = 1;
if((scratchpad2[9]<48)||(scratchpad2[9]>57)) error = 1;
if((scratchpad2[10]<48)||(scratchpad2[10]>57)) error = 1;
- if((edflib_atof_nonlocalized(scratchpad2)<1)||(edflib_atof_nonlocalized(scratchpad2)>31)) error = 1;
+ if((edflib_atoi_nonlocalized(scratchpad2)<1)||(edflib_atoi_nonlocalized(scratchpad2)>31)) error = 1;
if(strcmp(scratchpad2 + 3, "JAN"))
if(strcmp(scratchpad2 + 3, "FEB"))
if(strcmp(scratchpad2 + 3, "MAR"))
@@ -2524,7 +2362,7 @@ static struct edfhdrblock * edflib_check_edf_file(FILE *inputfile, int *edf_erro
if((scratchpad2[8]<48)||(scratchpad2[8]>57)) error = 1;
if((scratchpad2[9]<48)||(scratchpad2[9]>57)) error = 1;
if((scratchpad2[10]<48)||(scratchpad2[10]>57)) error = 1;
- if((edflib_atof_nonlocalized(scratchpad2)<1)||(edflib_atof_nonlocalized(scratchpad2)>31)) error = 1;
+ if((edflib_atoi_nonlocalized(scratchpad2)<1)||(edflib_atoi_nonlocalized(scratchpad2)>31)) error = 1;
r = 0;
if(!strcmp(scratchpad2 + 3, "JAN")) r = 1;
else if(!strcmp(scratchpad2 + 3, "FEB")) r = 2;
@@ -2579,9 +2417,9 @@ static struct edfhdrblock * edflib_check_edf_file(FILE *inputfile, int *edf_erro
scratchpad[5] = 0;
scratchpad[8] = 0;
- if(edflib_atof_nonlocalized(scratchpad)!=edflib_atof_nonlocalized(scratchpad2)) error = 1;
- if(edflib_atof_nonlocalized(scratchpad+3)!=r) error = 1;
- if(edflib_atof_nonlocalized(scratchpad+6)!=edflib_atof_nonlocalized(scratchpad2+9)) error = 1;
+ if(edflib_atoi_nonlocalized(scratchpad)!=edflib_atoi_nonlocalized(scratchpad2)) error = 1;
+ if(edflib_atoi_nonlocalized(scratchpad+3)!=r) error = 1;
+ if(edflib_atoi_nonlocalized(scratchpad+6)!=edflib_atoi_nonlocalized(scratchpad2+9)) error = 1;
if(error)
{
*edf_error = EDFLIB_FILE_CONTAINS_FORMAT_ERRORS;
@@ -2591,7 +2429,7 @@ static struct edfhdrblock * edflib_check_edf_file(FILE *inputfile, int *edf_erro
return NULL;
}
- if(edfhdr->startdate_year != edflib_atof_nonlocalized(scratchpad2 + 7))
+ if(edfhdr->startdate_year != edflib_atoi_nonlocalized(scratchpad2 + 7))
{
*edf_error = EDFLIB_FILE_CONTAINS_FORMAT_ERRORS;
free(edf_hdr);
@@ -3377,7 +3215,6 @@ static int edflib_is_duration_number(char *str)
}
-
static int edflib_is_onset_number(char *str)
{
int i, l, hasdot = 0;
@@ -3407,7 +3244,6 @@ static int edflib_is_onset_number(char *str)
}
-
static long long edflib_get_long_time(char *str)
{
int i, len, hasdot=0, dotposition=0, neg=0;
@@ -3600,13 +3436,13 @@ int edfopen_file_writeonly_with_params(const char *path, int filetype, int numbe
if(filetype == EDFLIB_FILETYPE_BDFPLUS)
{
- if(edf_set_digital_maximum(handle, i, 8388607))
+ if(edf_set_digital_maximum(handle, i, 0x7fffff))
{
edfclose_file(handle);
return -1;
}
- if(edf_set_digital_minimum(handle, i, -8388608))
+ if(edf_set_digital_minimum(handle, i, -0x800000))
{
edfclose_file(handle);
return -1;
@@ -3614,13 +3450,13 @@ int edfopen_file_writeonly_with_params(const char *path, int filetype, int numbe
}
else
{
- if(edf_set_digital_maximum(handle, i, 32767))
+ if(edf_set_digital_maximum(handle, i, 0x7fff))
{
edfclose_file(handle);
return -1;
}
- if(edf_set_digital_minimum(handle, i, -32768))
+ if(edf_set_digital_minimum(handle, i, -0x8000))
{
edfclose_file(handle);
return -1;
@@ -3640,6 +3476,32 @@ int edfopen_file_writeonly(const char *path, int filetype, int number_of_signals
struct edfhdrblock *hdr;
+ union
+ {
+ char four[4];
+ int one;
+ } byte_order_test_var;
+
+ /* avoid surprises! */
+ if((sizeof(char) != 1) ||
+ (sizeof(short) != 2) ||
+ (sizeof(int) != 4) ||
+ (sizeof(long long) != 8) ||
+ (sizeof(float) != 4) ||
+ (sizeof(double) != 8))
+ {
+ return EDFLIB_ARCH_ERROR;
+ }
+
+ /* check endianness! */
+ byte_order_test_var.one = 0x03020100;
+ if((byte_order_test_var.four[0] != 0) ||
+ (byte_order_test_var.four[1] != 1) ||
+ (byte_order_test_var.four[2] != 2) ||
+ (byte_order_test_var.four[3] != 3))
+ {
+ return EDFLIB_ARCH_ERROR;
+ }
if((filetype!=EDFLIB_FILETYPE_EDFPLUS)&&(filetype!=EDFLIB_FILETYPE_BDFPLUS))
{
@@ -3761,45 +3623,19 @@ int edfopen_file_writeonly(const char *path, int filetype, int number_of_signals
int edf_set_samplefrequency(int handle, int edfsignal, int samplefrequency)
{
- if(handle<0)
- {
- return -1;
- }
-
- if(handle>=EDFLIB_MAXFILES)
- {
- return -1;
- }
+ if((handle<0)||(handle>=EDFLIB_MAXFILES)) return -1;
- if(hdrlist[handle]==NULL)
- {
- return -1;
- }
+ if(hdrlist[handle]==NULL) return -1;
- if(!(hdrlist[handle]->writemode))
- {
- return -1;
- }
+ if(edfsignal<0) return -1;
- if(edfsignal<0)
- {
- return -1;
- }
+ if(!hdrlist[handle]->writemode) return -1;
- if(edfsignal>=hdrlist[handle]->edfsignals)
- {
- return -1;
- }
+ if(edfsignal>=hdrlist[handle]->edfsignals) return -1;
- if(samplefrequency<1)
- {
- return -1;
- }
+ if(samplefrequency<1) return -1;
- if(hdrlist[handle]->datarecords)
- {
- return -1;
- }
+ if(hdrlist[handle]->datarecords) return -1;
hdrlist[handle]->edfparam[edfsignal].smp_per_record = samplefrequency;
@@ -3809,35 +3645,15 @@ int edf_set_samplefrequency(int handle, int edfsignal, int samplefrequency)
int edf_set_number_of_annotation_signals(int handle, int annot_signals)
{
- if(handle<0)
- {
- return -1;
- }
-
- if(handle>=EDFLIB_MAXFILES)
- {
- return -1;
- }
+ if((handle<0)||(handle>=EDFLIB_MAXFILES)) return -1;
- if(hdrlist[handle]==NULL)
- {
- return -1;
- }
+ if(hdrlist[handle]==NULL) return -1;
- if(!(hdrlist[handle]->writemode))
- {
- return -1;
- }
+ if(!hdrlist[handle]->writemode) return -1;
- if(hdrlist[handle]->datarecords)
- {
- return -1;
- }
+ if(hdrlist[handle]->datarecords) return -1;
- if((annot_signals < 1) || (annot_signals > EDFLIB_MAX_ANNOTATION_CHANNELS))
- {
- return -1;
- }
+ if((annot_signals < 1) || (annot_signals > EDFLIB_MAX_ANNOTATION_CHANNELS)) return -1;
hdrlist[handle]->nr_annot_chns = annot_signals;
@@ -3847,35 +3663,15 @@ int edf_set_number_of_annotation_signals(int handle, int annot_signals)
int edf_set_datarecord_duration(int handle, int duration)
{
- if(handle<0)
- {
- return -1;
- }
-
- if(handle>=EDFLIB_MAXFILES)
- {
- return -1;
- }
+ if((handle<0)||(handle>=EDFLIB_MAXFILES)) return -1;
- if(hdrlist[handle]==NULL)
- {
- return -1;
- }
+ if(hdrlist[handle]==NULL) return -1;
- if(!(hdrlist[handle]->writemode))
- {
- return -1;
- }
+ if(!hdrlist[handle]->writemode) return -1;
- if(hdrlist[handle]->datarecords)
- {
- return -1;
- }
+ if(hdrlist[handle]->datarecords) return -1;
- if((duration < 100) || (duration > 6000000))
- {
- return -1;
- }
+ if((duration < 100) || (duration > 6000000)) return -1;
hdrlist[handle]->long_data_record_duration = (long long)duration * 100LL;
@@ -3900,35 +3696,15 @@ int edf_set_datarecord_duration(int handle, int duration)
int edf_set_micro_datarecord_duration(int handle, int duration)
{
- if(handle<0)
- {
- return -1;
- }
-
- if(handle>=EDFLIB_MAXFILES)
- {
- return -1;
- }
+ if((handle<0)||(handle>=EDFLIB_MAXFILES)) return -1;
- if(hdrlist[handle]==NULL)
- {
- return -1;
- }
+ if(hdrlist[handle]==NULL) return -1;
- if(!(hdrlist[handle]->writemode))
- {
- return -1;
- }
+ if(!hdrlist[handle]->writemode) return -1;
- if(hdrlist[handle]->datarecords)
- {
- return -1;
- }
+ if(hdrlist[handle]->datarecords) return -1;
- if((duration < 1) || (duration > 9999))
- {
- return -1;
- }
+ if((duration < 1) || (duration > 9999)) return -1;
hdrlist[handle]->long_data_record_duration = (long long)duration * 10LL;
@@ -3940,35 +3716,15 @@ int edf_set_micro_datarecord_duration(int handle, int duration)
int edf_set_subsecond_starttime(int handle, int subsecond)
{
- if(handle<0)
- {
- return -1;
- }
-
- if(handle>=EDFLIB_MAXFILES)
- {
- return -1;
- }
+ if((handle<0)||(handle>=EDFLIB_MAXFILES)) return -1;
- if(hdrlist[handle]==NULL)
- {
- return -1;
- }
+ if(hdrlist[handle]==NULL) return -1;
- if(!(hdrlist[handle]->writemode))
- {
- return -1;
- }
+ if(!hdrlist[handle]->writemode) return -1;
- if(hdrlist[handle]->datarecords)
- {
- return -1;
- }
+ if(hdrlist[handle]->datarecords) return -1;
- if((subsecond < 0) || (subsecond > 9999999))
- {
- return -1;
- }
+ if((subsecond < 0) || (subsecond > 9999999)) return -1;
hdrlist[handle]->starttime_offset = (long long)subsecond;
@@ -3990,36 +3746,15 @@ int edfwrite_digital_short_samples(int handle, short *buf)
struct edfhdrblock *hdr;
+ if((handle<0)||(handle>=EDFLIB_MAXFILES)) return -1;
- if(handle<0)
- {
- return -1;
- }
-
- if(handle>=EDFLIB_MAXFILES)
- {
- return -1;
- }
-
- if(hdrlist[handle]==NULL)
- {
- return -1;
- }
+ if(hdrlist[handle]==NULL) return -1;
- if(!(hdrlist[handle]->writemode))
- {
- return -1;
- }
+ if(!hdrlist[handle]->writemode) return -1;
- if(hdrlist[handle]->edfsignals == 0)
- {
- return -1;
- }
+ if(hdrlist[handle]->edfsignals == 0) return -1;
- if(hdrlist[handle]->bdf == 1)
- {
- return -1;
- }
+ if(hdrlist[handle]->bdf == 1) return -1;
hdr = hdrlist[handle];
@@ -4033,10 +3768,7 @@ int edfwrite_digital_short_samples(int handle, short *buf)
{
error = edflib_write_edf_header(hdr);
- if(error)
- {
- return error;
- }
+ if(error) return error;
}
}
@@ -4048,26 +3780,17 @@ int edfwrite_digital_short_samples(int handle, short *buf)
if(hdr->edf)
{
- if((digmax != 32767) || (digmin != -32768))
+ if((digmax != 0x7fff) || (digmin != -0x8000))
{
for(i=0; i<sf; i++)
{
- if(buf[i]>digmax)
- {
- buf[i] = digmax;
- }
+ if(buf[i]>digmax) buf[i] = digmax;
- if(buf[i]<digmin)
- {
- buf[i] = digmin;
- }
+ if(buf[i]<digmin) buf[i] = digmin;
}
}
- if(fwrite(buf, sf * 2, 1, file) != 1)
- {
- return -1;
- }
+ if(fwrite(buf, sf * 2, 1, file) != 1) return -1;
}
else // BDF
{
@@ -4079,10 +3802,7 @@ int edfwrite_digital_short_samples(int handle, short *buf)
hdr->wrbuf = (char *)malloc(sf * 3);
- if(hdr->wrbuf == NULL)
- {
- return -1;
- }
+ if(hdr->wrbuf == NULL) return -1;
hdr->wrbufsize = sf * 3;
}
@@ -4091,15 +3811,9 @@ int edfwrite_digital_short_samples(int handle, short *buf)
{
value = buf[i];
- if(value>digmax)
- {
- value = digmax;
- }
+ if(value>digmax) value = digmax;
- if(value<digmin)
- {
- value = digmin;
- }
+ if(value<digmin) value = digmin;
hdr->wrbuf[i * 3] = value & 0xff;
@@ -4108,10 +3822,7 @@ int edfwrite_digital_short_samples(int handle, short *buf)
hdr->wrbuf[i * 3 + 2] = (value >> 16) & 0xff;
}
- if(fwrite(hdr->wrbuf, sf * 3, 1, file) != 1)
- {
- return -1;
- }
+ if(fwrite(hdr->wrbuf, sf * 3, 1, file) != 1) return -1;
}
hdr->signal_write_sequence_pos++;
@@ -4120,10 +3831,7 @@ int edfwrite_digital_short_samples(int handle, short *buf)
{
hdr->signal_write_sequence_pos = 0;
- if(edflib_write_tal(hdr, file))
- {
- return -1;
- }
+ if(edflib_write_tal(hdr, file)) return -1;
hdr->datarecords++;
@@ -4148,31 +3856,13 @@ int edfwrite_digital_samples(int handle, int *buf)
struct edfhdrblock *hdr;
+ if((handle<0)||(handle>=EDFLIB_MAXFILES)) return -1;
- if(handle<0)
- {
- return -1;
- }
-
- if(handle>=EDFLIB_MAXFILES)
- {
- return -1;
- }
-
- if(hdrlist[handle]==NULL)
- {
- return -1;
- }
+ if(hdrlist[handle]==NULL) return -1;
- if(!(hdrlist[handle]->writemode))
- {
- return -1;
- }
+ if(!hdrlist[handle]->writemode) return -1;
- if(hdrlist[handle]->edfsignals == 0)
- {
- return -1;
- }
+ if(hdrlist[handle]->edfsignals == 0) return -1;
hdr = hdrlist[handle];
@@ -4186,10 +3876,7 @@ int edfwrite_digital_samples(int handle, int *buf)
{
error = edflib_write_edf_header(hdr);
- if(error)
- {
- return error;
- }
+ if(error) return error;
}
}
@@ -4209,10 +3896,7 @@ int edfwrite_digital_samples(int handle, int *buf)
hdr->wrbuf = (char *)malloc(sf * 2);
- if(hdr->wrbuf == NULL)
- {
- return -1;
- }
+ if(hdr->wrbuf == NULL) return -1;
hdr->wrbufsize = sf * 2;
}
@@ -4221,25 +3905,16 @@ int edfwrite_digital_samples(int handle, int *buf)
{
value = buf[i];
- if(value>digmax)
- {
- value = digmax;
- }
+ if(value>digmax) value = digmax;
- if(value<digmin)
- {
- value = digmin;
- }
+ if(value<digmin) value = digmin;
hdr->wrbuf[i * 2] = value & 0xff;
hdr->wrbuf[i * 2 + 1] = (value >> 8) & 0xff;
}
- if(fwrite(hdr->wrbuf, sf * 2, 1, file) != 1)
- {
- return -1;
- }
+ if(fwrite(hdr->wrbuf, sf * 2, 1, file) != 1) return -1;
}
else // BDF
{
@@ -4251,10 +3926,7 @@ int edfwrite_digital_samples(int handle, int *buf)
hdr->wrbuf = (char *)malloc(sf * 3);
- if(hdr->wrbuf == NULL)
- {
- return -1;
- }
+ if(hdr->wrbuf == NULL) return -1;
hdr->wrbufsize = sf * 3;
}
@@ -4263,15 +3935,9 @@ int edfwrite_digital_samples(int handle, int *buf)
{
value = buf[i];
- if(value>digmax)
- {
- value = digmax;
- }
+ if(value>digmax) value = digmax;
- if(value<digmin)
- {
- value = digmin;
- }
+ if(value<digmin) value = digmin;
hdr->wrbuf[i * 3] = value & 0xff;
@@ -4280,10 +3946,7 @@ int edfwrite_digital_samples(int handle, int *buf)
hdr->wrbuf[i * 3 + 2] = (value >> 16) & 0xff;
}
- if(fwrite(hdr->wrbuf, sf * 3, 1, file) != 1)
- {
- return -1;
- }
+ if(fwrite(hdr->wrbuf, sf * 3, 1, file) != 1) return -1;
}
hdr->signal_write_sequence_pos++;
@@ -4292,10 +3955,7 @@ int edfwrite_digital_samples(int handle, int *buf)
{
hdr->signal_write_sequence_pos = 0;
- if(edflib_write_tal(hdr, file))
- {
- return -1;
- }
+ if(edflib_write_tal(hdr, file)) return -1;
hdr->datarecords++;
@@ -4321,36 +3981,15 @@ int edf_blockwrite_digital_samples(int handle, int *buf)
struct edfhdrblock *hdr;
+ if((handle<0)||(handle>=EDFLIB_MAXFILES)) return -1;
- if(handle<0)
- {
- return -1;
- }
-
- if(handle>=EDFLIB_MAXFILES)
- {
- return -1;
- }
-
- if(hdrlist[handle]==NULL)
- {
- return -1;
- }
+ if(hdrlist[handle]==NULL) return -1;
- if(!(hdrlist[handle]->writemode))
- {
- return -1;
- }
+ if(!hdrlist[handle]->writemode) return -1;
- if(hdrlist[handle]->signal_write_sequence_pos)
- {
- return -1;
- }
+ if(hdrlist[handle]->edfsignals == 0) return -1;
- if(hdrlist[handle]->edfsignals == 0)
- {
- return -1;
- }
+ if(hdrlist[handle]->signal_write_sequence_pos) return -1;
hdr = hdrlist[handle];
@@ -4362,10 +4001,7 @@ int edf_blockwrite_digital_samples(int handle, int *buf)
{
error = edflib_write_edf_header(hdr);
- if(error)
- {
- return error;
- }
+ if(error) return error;
}
buf_offset = 0;
@@ -4388,10 +4024,7 @@ int edf_blockwrite_digital_samples(int handle, int *buf)
hdr->wrbuf = (char *)malloc(sf * 2);
- if(hdr->wrbuf == NULL)
- {
- return -1;
- }
+ if(hdr->wrbuf == NULL) return -1;
hdr->wrbufsize = sf * 2;
}
@@ -4400,25 +4033,16 @@ int edf_blockwrite_digital_samples(int handle, int *buf)
{
value = buf[i + buf_offset];
- if(value>digmax)
- {
- value = digmax;
- }
+ if(value>digmax) value = digmax;
- if(value<digmin)
- {
- value = digmin;
- }
+ if(value<digmin) value = digmin;
hdr->wrbuf[i * 2] = value & 0xff;
hdr->wrbuf[i * 2 + 1] = (value >> 8) & 0xff;
}
- if(fwrite(hdr->wrbuf, sf * 2, 1, file) != 1)
- {
- return -1;
- }
+ if(fwrite(hdr->wrbuf, sf * 2, 1, file) != 1) return -1;
}
else // BDF
{
@@ -4430,10 +4054,7 @@ int edf_blockwrite_digital_samples(int handle, int *buf)
hdr->wrbuf = (char *)malloc(sf * 3);
- if(hdr->wrbuf == NULL)
- {
- return -1;
- }
+ if(hdr->wrbuf == NULL) return -1;
hdr->wrbufsize = sf * 3;
}
@@ -4442,15 +4063,9 @@ int edf_blockwrite_digital_samples(int handle, int *buf)
{
value = buf[i + buf_offset];
- if(value>digmax)
- {
- value = digmax;
- }
+ if(value>digmax) value = digmax;
- if(value<digmin)
- {
- value = digmin;
- }
+ if(value<digmin) value = digmin;
hdr->wrbuf[i * 3] = value & 0xff;
@@ -4459,19 +4074,13 @@ int edf_blockwrite_digital_samples(int handle, int *buf)
hdr->wrbuf[i * 3 + 2] = (value >> 16) & 0xff;
}
- if(fwrite(hdr->wrbuf, sf * 3, 1, file) != 1)
- {
- return -1;
- }
+ if(fwrite(hdr->wrbuf, sf * 3, 1, file) != 1) return -1;
}
buf_offset += sf;
}
- if(edflib_write_tal(hdr, file))
- {
- return -1;
- }
+ if(edflib_write_tal(hdr, file)) return -1;
hdr->datarecords++;
@@ -4496,41 +4105,17 @@ int edf_blockwrite_digital_short_samples(int handle, short *buf)
struct edfhdrblock *hdr;
+ if((handle<0)||(handle>=EDFLIB_MAXFILES)) return -1;
- if(handle<0)
- {
- return -1;
- }
-
- if(handle>=EDFLIB_MAXFILES)
- {
- return -1;
- }
-
- if(hdrlist[handle]==NULL)
- {
- return -1;
- }
+ if(hdrlist[handle]==NULL) return -1;
- if(!(hdrlist[handle]->writemode))
- {
- return -1;
- }
+ if(!hdrlist[handle]->writemode) return -1;
- if(hdrlist[handle]->signal_write_sequence_pos)
- {
- return -1;
- }
+ if(hdrlist[handle]->edfsignals == 0) return -1;
- if(hdrlist[handle]->edfsignals == 0)
- {
- return -1;
- }
+ if(hdrlist[handle]->signal_write_sequence_pos) return -1;
- if(hdrlist[handle]->bdf == 1)
- {
- return -1;
- }
+ if(hdrlist[handle]->bdf == 1) return -1;
hdr = hdrlist[handle];
@@ -4560,7 +4145,7 @@ int edf_blockwrite_digital_short_samples(int handle, short *buf)
if(hdr->edf)
{
- if((digmax != 32767) || (digmin != -32768))
+ if((digmax != 0x7fff) || (digmin != -0x8000))
{
for(i=0; i<sf; i++)
{
@@ -4576,10 +4161,7 @@ int edf_blockwrite_digital_short_samples(int handle, short *buf)
}
}
- if(fwrite(buf + buf_offset, sf * 2, 1, file) != 1)
- {
- return -1;
- }
+ if(fwrite(buf + buf_offset, sf * 2, 1, file) != 1) return -1;
}
else // BDF
{
@@ -4591,10 +4173,7 @@ int edf_blockwrite_digital_short_samples(int handle, short *buf)
hdr->wrbuf = (char *)malloc(sf * 3);
- if(hdr->wrbuf == NULL)
- {
- return -1;
- }
+ if(hdr->wrbuf == NULL) return -1;
hdr->wrbufsize = sf * 3;
}
@@ -4603,15 +4182,9 @@ int edf_blockwrite_digital_short_samples(int handle, short *buf)
{
value = buf[i + buf_offset];
- if(value>digmax)
- {
- value = digmax;
- }
+ if(value>digmax) value = digmax;
- if(value<digmin)
- {
- value = digmin;
- }
+ if(value<digmin) value = digmin;
hdr->wrbuf[i * 3] = value & 0xff;
@@ -4620,19 +4193,13 @@ int edf_blockwrite_digital_short_samples(int handle, short *buf)
hdr->wrbuf[i * 3 + 2] = (value >> 16) & 0xff;
}
- if(fwrite(hdr->wrbuf, sf * 3, 1, file) != 1)
- {
- return -1;
- }
+ if(fwrite(hdr->wrbuf, sf * 3, 1, file) != 1) return -1;
}
buf_offset += sf;
}
- if(edflib_write_tal(hdr, file))
- {
- return -1;
- }
+ if(edflib_write_tal(hdr, file)) return -1;
hdr->datarecords++;
@@ -4653,41 +4220,17 @@ int edf_blockwrite_digital_3byte_samples(int handle, void *buf)
struct edfhdrblock *hdr;
+ if((handle<0)||(handle>=EDFLIB_MAXFILES)) return -1;
- if(handle<0)
- {
- return -1;
- }
-
- if(handle>=EDFLIB_MAXFILES)
- {
- return -1;
- }
-
- if(hdrlist[handle]==NULL)
- {
- return -1;
- }
+ if(hdrlist[handle]==NULL) return -1;
- if(!(hdrlist[handle]->writemode))
- {
- return -1;
- }
+ if(!hdrlist[handle]->writemode) return -1;
- if(hdrlist[handle]->signal_write_sequence_pos)
- {
- return -1;
- }
+ if(hdrlist[handle]->edfsignals == 0) return -1;
- if(hdrlist[handle]->edfsignals == 0)
- {
- return -1;
- }
+ if(hdrlist[handle]->signal_write_sequence_pos) return -1;
- if(hdrlist[handle]->bdf != 1)
- {
- return -1;
- }
+ if(hdrlist[handle]->bdf != 1) return -1;
hdr = hdrlist[handle];
@@ -4699,10 +4242,7 @@ int edf_blockwrite_digital_3byte_samples(int handle, void *buf)
{
error = edflib_write_edf_header(hdr);
- if(error)
- {
- return error;
- }
+ if(error) return error;
}
for(j=0; j<edfsignals; j++)
@@ -4710,15 +4250,9 @@ int edf_blockwrite_digital_3byte_samples(int handle, void *buf)
total_samples += hdr->edfparam[j].smp_per_record;
}
- if(fwrite(buf, total_samples * 3, 1, file) != 1)
- {
- return -1;
- }
+ if(fwrite(buf, total_samples * 3, 1, file) != 1) return -1;
- if(edflib_write_tal(hdr, file))
- {
- return -1;
- }
+ if(edflib_write_tal(hdr, file)) return -1;
hdr->datarecords++;
@@ -4745,31 +4279,13 @@ int edfwrite_physical_samples(int handle, double *buf)
struct edfhdrblock *hdr;
+ if((handle<0)||(handle>=EDFLIB_MAXFILES)) return -1;
- if(handle<0)
- {
- return -1;
- }
+ if(hdrlist[handle]==NULL) return -1;
- if(handle>=EDFLIB_MAXFILES)
- {
- return -1;
- }
+ if(!hdrlist[handle]->writemode) return -1;
- if(hdrlist[handle]==NULL)
- {
- return -1;
- }
-
- if(!(hdrlist[handle]->writemode))
- {
- return -1;
- }
-
- if(hdrlist[handle]->edfsignals == 0)
- {
- return -1;
- }
+ if(hdrlist[handle]->edfsignals == 0) return -1;
hdr = hdrlist[handle];
@@ -4783,10 +4299,7 @@ int edfwrite_physical_samples(int handle, double *buf)
{
error = edflib_write_edf_header(hdr);
- if(error)
- {
- return error;
- }
+ if(error) return error;
}
}
@@ -4810,10 +4323,7 @@ int edfwrite_physical_samples(int handle, double *buf)
hdr->wrbuf = (char *)malloc(sf * 2);
- if(hdr->wrbuf == NULL)
- {
- return -1;
- }
+ if(hdr->wrbuf == NULL) return -1;
hdr->wrbufsize = sf * 2;
}
@@ -4822,25 +4332,16 @@ int edfwrite_physical_samples(int handle, double *buf)
{
value = (buf[i] / bitvalue) - phys_offset;
- if(value>digmax)
- {
- value = digmax;
- }
+ if(value>digmax) value = digmax;
- if(value<digmin)
- {
- value = digmin;
- }
+ if(value<digmin) value = digmin;
hdr->wrbuf[i * 2] = value & 0xff;
hdr->wrbuf[i * 2 + 1] = (value >> 8) & 0xff;
}
- if(fwrite(hdr->wrbuf, sf * 2, 1, file) != 1)
- {
- return -1;
- }
+ if(fwrite(hdr->wrbuf, sf * 2, 1, file) != 1) return -1;
}
else // BDF
{
@@ -4852,10 +4353,7 @@ int edfwrite_physical_samples(int handle, double *buf)
hdr->wrbuf = (char *)malloc(sf * 3);
- if(hdr->wrbuf == NULL)
- {
- return -1;
- }
+ if(hdr->wrbuf == NULL) return -1;
hdr->wrbufsize = sf * 3;
}
@@ -4864,15 +4362,9 @@ int edfwrite_physical_samples(int handle, double *buf)
{
value = (buf[i] / bitvalue) - phys_offset;
- if(value>digmax)
- {
- value = digmax;
- }
+ if(value>digmax) value = digmax;
- if(value<digmin)
- {
- value = digmin;
- }
+ if(value<digmin) value = digmin;
hdr->wrbuf[i * 3] = value & 0xff;
@@ -4881,10 +4373,7 @@ int edfwrite_physical_samples(int handle, double *buf)
hdr->wrbuf[i * 3 + 2] = (value >> 16) & 0xff;
}
- if(fwrite(hdr->wrbuf, sf * 3, 1, file) != 1)
- {
- return -1;
- }
+ if(fwrite(hdr->wrbuf, sf * 3, 1, file) != 1) return -1;
}
hdr->signal_write_sequence_pos++;
@@ -4893,10 +4382,7 @@ int edfwrite_physical_samples(int handle, double *buf)
{
hdr->signal_write_sequence_pos = 0;
- if(edflib_write_tal(hdr, file))
- {
- return -1;
- }
+ if(edflib_write_tal(hdr, file)) return -1;
hdr->datarecords++;
@@ -4925,36 +4411,15 @@ int edf_blockwrite_physical_samples(int handle, double *buf)
struct edfhdrblock *hdr;
+ if((handle<0)||(handle>=EDFLIB_MAXFILES)) return -1;
- if(handle<0)
- {
- return -1;
- }
+ if(hdrlist[handle]==NULL) return -1;
- if(handle>=EDFLIB_MAXFILES)
- {
- return -1;
- }
+ if(!hdrlist[handle]->writemode) return -1;
- if(hdrlist[handle]==NULL)
- {
- return -1;
- }
+ if(hdrlist[handle]->edfsignals == 0) return -1;
- if(!(hdrlist[handle]->writemode))
- {
- return -1;
- }
-
- if(hdrlist[handle]->signal_write_sequence_pos)
- {
- return -1;
- }
-
- if(hdrlist[handle]->edfsignals == 0)
- {
- return -1;
- }
+ if(hdrlist[handle]->signal_write_sequence_pos) return -1;
hdr = hdrlist[handle];
@@ -4966,10 +4431,7 @@ int edf_blockwrite_physical_samples(int handle, double *buf)
{
error = edflib_write_edf_header(hdr);
- if(error)
- {
- return error;
- }
+ if(error) return error;
}
buf_offset = 0;
@@ -4996,10 +4458,7 @@ int edf_blockwrite_physical_samples(int handle, double *buf)
hdr->wrbuf = (char *)malloc(sf * 2);
- if(hdr->wrbuf == NULL)
- {
- return -1;
- }
+ if(hdr->wrbuf == NULL) return -1;
hdr->wrbufsize = sf * 2;
}
@@ -5008,25 +4467,16 @@ int edf_blockwrite_physical_samples(int handle, double *buf)
{
value = (buf[i + buf_offset] / bitvalue) - phys_offset;
- if(value>digmax)
- {
- value = digmax;
- }
+ if(value>digmax) value = digmax;
- if(value<digmin)
- {
- value = digmin;
- }
+ if(value<digmin) value = digmin;
hdr->wrbuf[i * 2] = value & 0xff;
hdr->wrbuf[i * 2 + 1] = (value >> 8) & 0xff;
}
- if(fwrite(hdr->wrbuf, sf * 2, 1, file) != 1)
- {
- return -1;
- }
+ if(fwrite(hdr->wrbuf, sf * 2, 1, file) != 1) return -1;
}
else // BDF
{
@@ -5038,10 +4488,7 @@ int edf_blockwrite_physical_samples(int handle, double *buf)
hdr->wrbuf = (char *)malloc(sf * 3);
- if(hdr->wrbuf == NULL)
- {
- return -1;
- }
+ if(hdr->wrbuf == NULL) return -1;
hdr->wrbufsize = sf * 3;
}
@@ -5050,15 +4497,9 @@ int edf_blockwrite_physical_samples(int handle, double *buf)
{
value = (buf[i + buf_offset] / bitvalue) - phys_offset;
- if(value>digmax)
- {
- value = digmax;
- }
+ if(value>digmax) value = digmax;
- if(value<digmin)
- {
- value = digmin;
- }
+ if(value<digmin) value = digmin;
hdr->wrbuf[i * 3] = value & 0xff;
@@ -5067,19 +4508,13 @@ int edf_blockwrite_physical_samples(int handle, double *buf)
hdr->wrbuf[i * 3 + 2] = (value >> 16) & 0xff;
}
- if(fwrite(hdr->wrbuf, sf * 3, 1, file) != 1)
- {
- return -1;
- }
+ if(fwrite(hdr->wrbuf, sf * 3, 1, file) != 1) return -1;
}
buf_offset += sf;
}
- if(edflib_write_tal(hdr, file))
- {
- return -1;
- }
+ if(edflib_write_tal(hdr, file)) return -1;
hdr->datarecords++;
@@ -5104,20 +4539,13 @@ static int edflib_write_edf_header(struct edfhdrblock *hdr)
FILE *file;
-
file = hdr->file_hdl;
edfsignals = hdr->edfsignals;
- if(edfsignals<0)
- {
- return EDFLIB_NO_SIGNALS;
- }
+ if(edfsignals<0) return EDFLIB_NO_SIGNALS;
- if(edfsignals>EDFLIB_MAXSIGNALS)
- {
- return EDFLIB_TOO_MANY_SIGNALS;
- }
+ if(edfsignals>EDFLIB_MAXSIGNALS) return EDFLIB_TOO_MANY_SIGNALS;
hdr->eq_sf = 1;
@@ -5127,25 +4555,13 @@ static int edflib_write_edf_header(struct edfhdrblock *hdr)
for(i=0; i<edfsignals; i++)
{
- if(hdr->edfparam[i].smp_per_record<1)
- {
- return EDFLIB_NO_SAMPLES_IN_RECORD;
- }
+ if(hdr->edfparam[i].smp_per_record<1) return EDFLIB_NO_SAMPLES_IN_RECORD;
- if(hdr->edfparam[i].dig_max==hdr->edfparam[i].dig_min)
- {
- return EDFLIB_DIGMIN_IS_DIGMAX;
- }
+ if(hdr->edfparam[i].dig_max==hdr->edfparam[i].dig_min) return EDFLIB_DIGMIN_IS_DIGMAX;
- if(hdr->edfparam[i].dig_max<hdr->edfparam[i].dig_min)
- {
- return EDFLIB_DIGMAX_LOWER_THAN_DIGMIN;
- }
+ if(hdr->edfparam[i].dig_max<hdr->edfparam[i].dig_min) return EDFLIB_DIGMAX_LOWER_THAN_DIGMIN;
- if(hdr->edfparam[i].phys_max==hdr->edfparam[i].phys_min)
- {
- return EDFLIB_PHYSMIN_IS_PHYSMAX;
- }
+ if(hdr->edfparam[i].phys_max==hdr->edfparam[i].phys_min) return EDFLIB_PHYSMIN_IS_PHYSMAX;
hdr->recordsize += hdr->edfparam[i].smp_per_record;
@@ -5271,7 +4687,7 @@ static int edflib_write_edf_header(struct edfhdrblock *hdr)
fputc(hdr->plus_birthdate[0], file);
fputc(hdr->plus_birthdate[1], file);
fputc('-', file);
- q = edflib_atof_nonlocalized(&(hdr->plus_birthdate[3]));
+ q = edflib_atoi_nonlocalized(&(hdr->plus_birthdate[3]));
switch(q)
{
case 1: fprintf(file, "JAN"); break;
@@ -5753,40 +5169,15 @@ static int edflib_write_edf_header(struct edfhdrblock *hdr)
int edf_set_label(int handle, int edfsignal, const char *label)
{
- if(handle<0)
- {
- return -1;
- }
+ if((handle<0)||(handle>=EDFLIB_MAXFILES)) return -1;
- if(handle>=EDFLIB_MAXFILES)
- {
- return -1;
- }
-
- if(hdrlist[handle]==NULL)
- {
- return -1;
- }
+ if(hdrlist[handle]==NULL) return -1;
- if(!(hdrlist[handle]->writemode))
- {
- return -1;
- }
+ if(!hdrlist[handle]->writemode) return -1;
- if(edfsignal<0)
- {
- return -1;
- }
+ if(hdrlist[handle]->datarecords) return -1;
- if(edfsignal>=hdrlist[handle]->edfsignals)
- {
- return -1;
- }
-
- if(hdrlist[handle]->datarecords)
- {
- return -1;
- }
+ if((edfsignal<0) || (edfsignal>=hdrlist[handle]->edfsignals)) return -1;
strncpy(hdrlist[handle]->edfparam[edfsignal].label, label, 16);
@@ -5800,40 +5191,15 @@ int edf_set_label(int handle, int edfsignal, const char *label)
int edf_set_physical_dimension(int handle, int edfsignal, const char *phys_dim)
{
- if(handle<0)
- {
- return -1;
- }
+ if((handle<0)||(handle>=EDFLIB_MAXFILES)) return -1;
- if(handle>=EDFLIB_MAXFILES)
- {
- return -1;
- }
+ if(hdrlist[handle]==NULL) return -1;
- if(hdrlist[handle]==NULL)
- {
- return -1;
- }
+ if(!hdrlist[handle]->writemode) return -1;
- if(!(hdrlist[handle]->writemode))
- {
- return -1;
- }
-
- if(edfsignal<0)
- {
- return -1;
- }
-
- if(edfsignal>=hdrlist[handle]->edfsignals)
- {
- return -1;
- }
+ if(hdrlist[handle]->datarecords) return -1;
- if(hdrlist[handle]->datarecords)
- {
- return -1;
- }
+ if((edfsignal<0) || (edfsignal>=hdrlist[handle]->edfsignals)) return -1;
strncpy(hdrlist[handle]->edfparam[edfsignal].physdimension, phys_dim, 8);
@@ -5847,40 +5213,15 @@ int edf_set_physical_dimension(int handle, int edfsignal, const char *phys_dim)
int edf_set_physical_maximum(int handle, int edfsignal, double phys_max)
{
- if(handle<0)
- {
- return -1;
- }
+ if((handle<0)||(handle>=EDFLIB_MAXFILES)) return -1;
- if(handle>=EDFLIB_MAXFILES)
- {
- return -1;
- }
+ if(hdrlist[handle]==NULL) return -1;
- if(hdrlist[handle]==NULL)
- {
- return -1;
- }
+ if(!hdrlist[handle]->writemode) return -1;
- if(!(hdrlist[handle]->writemode))
- {
- return -1;
- }
+ if(hdrlist[handle]->datarecords) return -1;
- if(edfsignal<0)
- {
- return -1;
- }
-
- if(edfsignal>=hdrlist[handle]->edfsignals)
- {
- return -1;
- }
-
- if(hdrlist[handle]->datarecords)
- {
- return -1;
- }
+ if((edfsignal<0) || (edfsignal>=hdrlist[handle]->edfsignals)) return -1;
hdrlist[handle]->edfparam[edfsignal].phys_max = phys_max;
@@ -5890,40 +5231,15 @@ int edf_set_physical_maximum(int handle, int edfsignal, double phys_max)
int edf_set_physical_minimum(int handle, int edfsignal, double phys_min)
{
- if(handle<0)
- {
- return -1;
- }
+ if((handle<0)||(handle>=EDFLIB_MAXFILES)) return -1;
- if(handle>=EDFLIB_MAXFILES)
- {
- return -1;
- }
+ if(hdrlist[handle]==NULL) return -1;
- if(hdrlist[handle]==NULL)
- {
- return -1;
- }
+ if(!hdrlist[handle]->writemode) return -1;
- if(!(hdrlist[handle]->writemode))
- {
- return -1;
- }
+ if(hdrlist[handle]->datarecords) return -1;
- if(edfsignal<0)
- {
- return -1;
- }
-
- if(edfsignal>=hdrlist[handle]->edfsignals)
- {
- return -1;
- }
-
- if(hdrlist[handle]->datarecords)
- {
- return -1;
- }
+ if((edfsignal<0) || (edfsignal>=hdrlist[handle]->edfsignals)) return -1;
hdrlist[handle]->edfparam[edfsignal].phys_min = phys_min;
@@ -5933,54 +5249,23 @@ int edf_set_physical_minimum(int handle, int edfsignal, double phys_min)
int edf_set_digital_maximum(int handle, int edfsignal, int dig_max)
{
- if(handle<0)
- {
- return -1;
- }
+ if((handle<0)||(handle>=EDFLIB_MAXFILES)) return -1;
- if(handle>=EDFLIB_MAXFILES)
- {
- return -1;
- }
+ if(hdrlist[handle]==NULL) return -1;
- if(hdrlist[handle]==NULL)
- {
- return -1;
- }
+ if(!hdrlist[handle]->writemode) return -1;
- if(!(hdrlist[handle]->writemode))
- {
- return -1;
- }
+ if(hdrlist[handle]->datarecords) return -1;
- if(edfsignal<0)
- {
- return -1;
- }
-
- if(edfsignal>=hdrlist[handle]->edfsignals)
- {
- return -1;
- }
+ if((edfsignal<0) || (edfsignal>=hdrlist[handle]->edfsignals)) return -1;
if(hdrlist[handle]->edf)
{
- if(dig_max > 32767)
- {
- return -1;
- }
+ if(dig_max > 0x7fff) return -1;
}
else
{
- if(dig_max > 8388607)
- {
- return -1;
- }
- }
-
- if(hdrlist[handle]->datarecords)
- {
- return -1;
+ if(dig_max > 0x7fffff) return -1;
}
hdrlist[handle]->edfparam[edfsignal].dig_max = dig_max;
@@ -5991,54 +5276,23 @@ int edf_set_digital_maximum(int handle, int edfsignal, int dig_max)
int edf_set_digital_minimum(int handle, int edfsignal, int dig_min)
{
- if(handle<0)
- {
- return -1;
- }
+ if((handle<0)||(handle>=EDFLIB_MAXFILES)) return -1;
- if(handle>=EDFLIB_MAXFILES)
- {
- return -1;
- }
+ if(hdrlist[handle]==NULL) return -1;
- if(hdrlist[handle]==NULL)
- {
- return -1;
- }
+ if(!hdrlist[handle]->writemode) return -1;
- if(!(hdrlist[handle]->writemode))
- {
- return -1;
- }
+ if(hdrlist[handle]->datarecords) return -1;
- if(edfsignal<0)
- {
- return -1;
- }
-
- if(edfsignal>=hdrlist[handle]->edfsignals)
- {
- return -1;
- }
+ if((edfsignal<0) || (edfsignal>=hdrlist[handle]->edfsignals)) return -1;
if(hdrlist[handle]->edf)
{
- if(dig_min < (-32768))
- {
- return -1;
- }
+ if(dig_min < (-0x8000)) return -1;
}
else
{
- if(dig_min < (-8388608))
- {
- return -1;
- }
- }
-
- if(hdrlist[handle]->datarecords)
- {
- return -1;
+ if(dig_min < (-0x800000)) return -1;
}
hdrlist[handle]->edfparam[edfsignal].dig_min = dig_min;
@@ -6049,30 +5303,13 @@ int edf_set_digital_minimum(int handle, int edfsignal, int dig_min)
int edf_set_patientname(int handle, const char *patientname)
{
- if(handle<0)
- {
- return -1;
- }
+ if((handle<0)||(handle>=EDFLIB_MAXFILES)) return -1;
- if(handle>=EDFLIB_MAXFILES)
- {
- return -1;
- }
-
- if(hdrlist[handle]==NULL)
- {
- return -1;
- }
+ if(hdrlist[handle]==NULL) return -1;
- if(!(hdrlist[handle]->writemode))
- {
- return -1;
- }
+ if(!hdrlist[handle]->writemode) return -1;
- if(hdrlist[handle]->datarecords)
- {
- return -1;
- }
+ if(hdrlist[handle]->datarecords) return -1;
strncpy(hdrlist[handle]->plus_patient_name, patientname, 80);
@@ -6086,30 +5323,13 @@ int edf_set_patientname(int handle, const char *patientname)
int edf_set_patientcode(int handle, const char *patientcode)
{
- if(handle<0)
- {
- return -1;
- }
-
- if(handle>=EDFLIB_MAXFILES)
- {
- return -1;
- }
+ if((handle<0)||(handle>=EDFLIB_MAXFILES)) return -1;
- if(hdrlist[handle]==NULL)
- {
- return -1;
- }
+ if(hdrlist[handle]==NULL) return -1;
- if(!(hdrlist[handle]->writemode))
- {
- return -1;
- }
+ if(!hdrlist[handle]->writemode) return -1;
- if(hdrlist[handle]->datarecords)
- {
- return -1;
- }
+ if(hdrlist[handle]->datarecords) return -1;
strncpy(hdrlist[handle]->plus_patientcode, patientcode, 80);
@@ -6123,35 +5343,15 @@ int edf_set_patientcode(int handle, const char *patientcode)
int edf_set_gender(int handle, int gender)
{
- if(handle<0)
- {
- return -1;
- }
+ if((handle<0)||(handle>=EDFLIB_MAXFILES)) return -1;
- if(handle>=EDFLIB_MAXFILES)
- {
- return -1;
- }
+ if(hdrlist[handle]==NULL) return -1;
- if(hdrlist[handle]==NULL)
- {
- return -1;
- }
+ if(!hdrlist[handle]->writemode) return -1;
- if(!(hdrlist[handle]->writemode))
- {
- return -1;
- }
+ if(hdrlist[handle]->datarecords) return -1;
- if(hdrlist[handle]->datarecords)
- {
- return -1;
- }
-
- if((gender<0)||(gender>1))
- {
- return -1;
- }
+ if((gender<0)||(gender>1)) return -1;
if(gender)
{
@@ -6170,30 +5370,13 @@ int edf_set_gender(int handle, int gender)
int edf_set_birthdate(int handle, int birthdate_year, int birthdate_month, int birthdate_day)
{
- if(handle<0)
- {
- return -1;
- }
+ if((handle<0)||(handle>=EDFLIB_MAXFILES)) return -1;
- if(handle>=EDFLIB_MAXFILES)
- {
- return -1;
- }
+ if(hdrlist[handle]==NULL) return -1;
- if(hdrlist[handle]==NULL)
- {
- return -1;
- }
-
- if(!(hdrlist[handle]->writemode))
- {
- return -1;
- }
+ if(!hdrlist[handle]->writemode) return -1;
- if(hdrlist[handle]->datarecords)
- {
- return -1;
- }
+ if(hdrlist[handle]->datarecords) return -1;
if((birthdate_year<1800) || (birthdate_year>3000) ||
(birthdate_month<1) || (birthdate_month>12) ||
@@ -6212,30 +5395,13 @@ int edf_set_birthdate(int handle, int birthdate_year, int birthdate_month, int b
int edf_set_patient_additional(int handle, const char *patient_additional)
{
- if(handle<0)
- {
- return -1;
- }
+ if((handle<0)||(handle>=EDFLIB_MAXFILES)) return -1;
- if(handle>=EDFLIB_MAXFILES)
- {
- return -1;
- }
-
- if(hdrlist[handle]==NULL)
- {
- return -1;
- }
+ if(hdrlist[handle]==NULL) return -1;
- if(!(hdrlist[handle]->writemode))
- {
- return -1;
- }
+ if(!hdrlist[handle]->writemode) return -1;
- if(hdrlist[handle]->datarecords)
- {
- return -1;
- }
+ if(hdrlist[handle]->datarecords) return -1;
strncpy(hdrlist[handle]->plus_patient_additional, patient_additional, 80);
@@ -6249,30 +5415,13 @@ int edf_set_patient_additional(int handle, const char *patient_additional)
int edf_set_admincode(int handle, const char *admincode)
{
- if(handle<0)
- {
- return -1;
- }
+ if((handle<0)||(handle>=EDFLIB_MAXFILES)) return -1;
- if(handle>=EDFLIB_MAXFILES)
- {
- return -1;
- }
+ if(hdrlist[handle]==NULL) return -1;
- if(hdrlist[handle]==NULL)
- {
- return -1;
- }
+ if(!hdrlist[handle]->writemode) return -1;
- if(!(hdrlist[handle]->writemode))
- {
- return -1;
- }
-
- if(hdrlist[handle]->datarecords)
- {
- return -1;
- }
+ if(hdrlist[handle]->datarecords) return -1;
strncpy(hdrlist[handle]->plus_admincode, admincode, 80);
@@ -6286,30 +5435,13 @@ int edf_set_admincode(int handle, const char *admincode)
int edf_set_technician(int handle, const char *technician)
{
- if(handle<0)
- {
- return -1;
- }
+ if((handle<0)||(handle>=EDFLIB_MAXFILES)) return -1;
- if(handle>=EDFLIB_MAXFILES)
- {
- return -1;
- }
+ if(hdrlist[handle]==NULL) return -1;
- if(hdrlist[handle]==NULL)
- {
- return -1;
- }
+ if(!hdrlist[handle]->writemode) return -1;
- if(!(hdrlist[handle]->writemode))
- {
- return -1;
- }
-
- if(hdrlist[handle]->datarecords)
- {
- return -1;
- }
+ if(hdrlist[handle]->datarecords) return -1;
strncpy(hdrlist[handle]->plus_technician, technician, 80);
@@ -6323,30 +5455,13 @@ int edf_set_technician(int handle, const char *technician)
int edf_set_equipment(int handle, const char *equipment)
{
- if(handle<0)
- {
- return -1;
- }
+ if((handle<0)||(handle>=EDFLIB_MAXFILES)) return -1;
- if(handle>=EDFLIB_MAXFILES)
- {
- return -1;
- }
+ if(hdrlist[handle]==NULL) return -1;
- if(hdrlist[handle]==NULL)
- {
- return -1;
- }
-
- if(!(hdrlist[handle]->writemode))
- {
- return -1;
- }
+ if(!hdrlist[handle]->writemode) return -1;
- if(hdrlist[handle]->datarecords)
- {
- return -1;
- }
+ if(hdrlist[handle]->datarecords) return -1;
strncpy(hdrlist[handle]->plus_equipment, equipment, 80);
@@ -6360,30 +5475,13 @@ int edf_set_equipment(int handle, const char *equipment)
int edf_set_recording_additional(int handle, const char *recording_additional)
{
- if(handle<0)
- {
- return -1;
- }
-
- if(handle>=EDFLIB_MAXFILES)
- {
- return -1;
- }
+ if((handle<0)||(handle>=EDFLIB_MAXFILES)) return -1;
- if(hdrlist[handle]==NULL)
- {
- return -1;
- }
+ if(hdrlist[handle]==NULL) return -1;
- if(!(hdrlist[handle]->writemode))
- {
- return -1;
- }
+ if(!hdrlist[handle]->writemode) return -1;
- if(hdrlist[handle]->datarecords)
- {
- return -1;
- }
+ if(hdrlist[handle]->datarecords) return -1;
strncpy(hdrlist[handle]->plus_recording_additional, recording_additional, 80);
@@ -6398,30 +5496,13 @@ int edf_set_recording_additional(int handle, const char *recording_additional)
int edf_set_startdatetime(int handle, int startdate_year, int startdate_month, int startdate_day,
int starttime_hour, int starttime_minute, int starttime_second)
{
- if(handle<0)
- {
- return -1;
- }
+ if((handle<0)||(handle>=EDFLIB_MAXFILES)) return -1;
- if(handle>=EDFLIB_MAXFILES)
- {
- return -1;
- }
-
- if(hdrlist[handle]==NULL)
- {
- return -1;
- }
+ if(hdrlist[handle]==NULL) return -1;
- if(!(hdrlist[handle]->writemode))
- {
- return -1;
- }
+ if(!hdrlist[handle]->writemode) return -1;
- if(hdrlist[handle]->datarecords)
- {
- return -1;
- }
+ if(hdrlist[handle]->datarecords) return -1;
if((startdate_year<1985) || (startdate_year>2084) ||
(startdate_month<1) || (startdate_month>12) ||
@@ -6450,31 +5531,13 @@ int edfwrite_annotation_utf8(int handle, long long onset, long long duration, co
struct edf_write_annotationblock *list_annot, *malloc_list;
+ if((handle<0)||(handle>=EDFLIB_MAXFILES)) return -1;
- if(handle<0)
- {
- return -1;
- }
+ if(hdrlist[handle]==NULL) return -1;
- if(handle>=EDFLIB_MAXFILES)
- {
- return -1;
- }
+ if(!hdrlist[handle]->writemode) return -1;
- if(hdrlist[handle]==NULL)
- {
- return -1;
- }
-
- if(!(hdrlist[handle]->writemode))
- {
- return -1;
- }
-
- if(onset<0LL)
- {
- return -1;
- }
+ if(onset<0LL) return -1;
if(hdrlist[handle]->annots_in_file >= hdrlist[handle]->annotlist_sz)
{
@@ -6522,31 +5585,13 @@ int edfwrite_annotation_latin1(int handle, long long onset, long long duration,
char str[EDFLIB_WRITE_MAX_ANNOTATION_LEN + 1];
+ if((handle<0)||(handle>=EDFLIB_MAXFILES)) return -1;
- if(handle<0)
- {
- return -1;
- }
-
- if(handle>=EDFLIB_MAXFILES)
- {
- return -1;
- }
-
- if(hdrlist[handle]==NULL)
- {
- return -1;
- }
+ if(hdrlist[handle]==NULL) return -1;
- if(!(hdrlist[handle]->writemode))
- {
- return -1;
- }
+ if(!hdrlist[handle]->writemode) return -1;
- if(onset<0LL)
- {
- return -1;
- }
+ if(onset<0LL) return -1;
if(hdrlist[handle]->annots_in_file >= hdrlist[handle]->annotlist_sz)
{
@@ -6611,40 +5656,17 @@ static void edflib_remove_padding_trailing_spaces(char *str)
int edf_set_prefilter(int handle, int edfsignal, const char *prefilter)
{
- if(handle<0)
- {
- return -1;
- }
+ if((handle<0)||(handle>=EDFLIB_MAXFILES)) return -1;
- if(handle>=EDFLIB_MAXFILES)
- {
- return -1;
- }
+ if(hdrlist[handle]==NULL) return -1;
- if(hdrlist[handle]==NULL)
- {
- return -1;
- }
+ if(!hdrlist[handle]->writemode) return -1;
- if(!(hdrlist[handle]->writemode))
- {
- return -1;
- }
-
- if(edfsignal<0)
- {
- return -1;
- }
+ if(hdrlist[handle]->datarecords) return -1;
- if(edfsignal>=hdrlist[handle]->edfsignals)
- {
- return -1;
- }
+ if((edfsignal<0) || (edfsignal>=hdrlist[handle]->edfsignals)) return -1;
- if(hdrlist[handle]->datarecords)
- {
- return -1;
- }
+ if(hdrlist[handle]->datarecords) return -1;
strncpy(hdrlist[handle]->edfparam[edfsignal].prefilter, prefilter, 80);
@@ -6658,40 +5680,17 @@ int edf_set_prefilter(int handle, int edfsignal, const char *prefilter)
int edf_set_transducer(int handle, int edfsignal, const char *transducer)
{
- if(handle<0)
- {
- return -1;
- }
+ if((handle<0)||(handle>=EDFLIB_MAXFILES)) return -1;
- if(handle>=EDFLIB_MAXFILES)
- {
- return -1;
- }
+ if(hdrlist[handle]==NULL) return -1;
- if(hdrlist[handle]==NULL)
- {
- return -1;
- }
+ if(!hdrlist[handle]->writemode) return -1;
- if(!(hdrlist[handle]->writemode))
- {
- return -1;
- }
+ if(hdrlist[handle]->datarecords) return -1;
- if(edfsignal<0)
- {
- return -1;
- }
+ if((edfsignal<0) || (edfsignal>=hdrlist[handle]->edfsignals)) return -1;
- if(edfsignal>=hdrlist[handle]->edfsignals)
- {
- return -1;
- }
-
- if(hdrlist[handle]->datarecords)
- {
- return -1;
- }
+ if(hdrlist[handle]->datarecords) return -1;
strncpy(hdrlist[handle]->edfparam[edfsignal].transducer, transducer, 80);
=====================================
edflib.h
=====================================
@@ -91,8 +91,19 @@
* This will limit the timeresolution to 100 nanoSeconds. To calculate the amount of seconds, divide
* the timevalue by 10000000 or use the macro EDFLIB_TIME_DIMENSION which is declared in edflib.h.
* The following variables use this scaling when you open a file in read mode: "file_duration", "starttime_subsecond" and "onset".
+ *
+ * EDFlib and thread-safety
+ * ========================
+ * The following functions are always MT-unsafe:
+ * edfopen_file_readonly() (race condition)
+ * edfclose_file() (race condition)
+ * edflib_get_handle() (race condition)
+ *
+ * When writing to or reading from the same file, all EDFlib functions are MT-unsafe (race condition).
+ *
*/
+
/* compile with options "-D_LARGEFILE64_SOURCE -D_LARGEFILE_SOURCE" */
#ifndef EDFLIB_INCLUDED
@@ -122,7 +133,7 @@
/* when this error occurs, try to open the file with EDFbrowser,
it will give you full details about the cause of the error. */
-#define EDFLIB_FILE_CONTAINS_FORMAT_ERRORS -3
+#define EDFLIB_FILE_CONTAINS_FORMAT_ERRORS (-3)
#define EDFLIB_MAXFILES_REACHED (-4)
#define EDFLIB_FILE_READ_ERROR (-5)
@@ -132,6 +143,7 @@
#define EDFLIB_NUMBER_OF_SIGNALS_INVALID (-9)
#define EDFLIB_FILE_IS_DISCONTINUOUS (-10)
#define EDFLIB_INVALID_READ_ANNOTS_VALUE (-11)
+#define EDFLIB_ARCH_ERROR (-12)
/* values for annotations */
#define EDFLIB_DO_NOT_READ_ANNOTATIONS (0)
@@ -308,6 +320,7 @@ int edfopen_file_writeonly(const char *path, int filetype, int number_of_signals
* EDFLIB_MAXFILES_REACHED
* EDFLIB_FILE_ALREADY_OPENED
* EDFLIB_NUMBER_OF_SIGNALS_INVALID
+ * EDFLIB_ARCH_ERROR
* This function is required if you want to write a file (or use edfopen_file_writeonly_with_params())
*/
@@ -330,6 +343,7 @@ int edfopen_file_writeonly_with_params(const char *path, int filetype, int numbe
* EDFLIB_MAXFILES_REACHED
* EDFLIB_FILE_ALREADY_OPENED
* EDFLIB_NUMBER_OF_SIGNALS_INVALID
+ * EDFLIB_ARCH_ERROR
* This function is required if you want to write a file (or use edfopen_file_writeonly())
*/
=====================================
unittest/unittest.c
=====================================
@@ -78,7 +78,7 @@ int main(void)
setlocale(LC_ALL, "C");
- if(edflib_version() != 122) JUMP_TO_EXIT_ERROR_PROC
+ if(edflib_version() != 123) JUMP_TO_EXIT_ERROR_PROC
ibuf = (int *)malloc(100 * sizeof(int));
if(ibuf == NULL)
View it on GitLab: https://salsa.debian.org/med-team/edflib/-/commit/529a35ac59b6d5b82750e653edde153a232bf417
--
View it on GitLab: https://salsa.debian.org/med-team/edflib/-/commit/529a35ac59b6d5b82750e653edde153a232bf417
You're receiving this email because of your account on salsa.debian.org.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://alioth-lists.debian.net/pipermail/debian-med-commit/attachments/20221022/bd4ff505/attachment-0001.htm>
More information about the debian-med-commit
mailing list