mirror of https://github.com/ecmwf/eccodes.git
ECC-1099: grib_file_open: errno from fopen overwritten by call to strdup
This commit is contained in:
parent
a85fd56731
commit
56ad3dbe72
|
@ -238,28 +238,24 @@ grib_file* grib_file_open(const char* filename, const char* mode, int* err)
|
||||||
|
|
||||||
GRIB_MUTEX_LOCK(&mutex1);
|
GRIB_MUTEX_LOCK(&mutex1);
|
||||||
if (!same_mode && file->handle) {
|
if (!same_mode && file->handle) {
|
||||||
/*printf("========== mode=%s file->mode=%s\n",mode,file->mode);*/
|
|
||||||
fclose(file->handle);
|
fclose(file->handle);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!file->handle) {
|
if (!file->handle) {
|
||||||
/*printf("-- opening file %s %s\n",file->name,mode);*/
|
|
||||||
if (!is_new && *mode == 'w') {
|
if (!is_new && *mode == 'w') {
|
||||||
/* fprintf(stderr,"++++ opening %s as append\n",file->name); */
|
|
||||||
file->handle = fopen(file->name, "a");
|
file->handle = fopen(file->name, "a");
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
file->handle = fopen(file->name, mode);
|
file->handle = fopen(file->name, mode);
|
||||||
/* fprintf(stderr,"++++ opening %s as mode\n",file->name); */
|
|
||||||
}
|
}
|
||||||
|
|
||||||
file->mode = strdup(mode);
|
|
||||||
if (!file->handle) {
|
if (!file->handle) {
|
||||||
grib_context_log(file->context, GRIB_LOG_PERROR, "grib_file_open: cannot open file %s", file->name);
|
grib_context_log(file->context, GRIB_LOG_PERROR, "grib_file_open: cannot open file %s", file->name);
|
||||||
*err = GRIB_IO_PROBLEM;
|
*err = GRIB_IO_PROBLEM;
|
||||||
GRIB_MUTEX_UNLOCK(&mutex1);
|
GRIB_MUTEX_UNLOCK(&mutex1);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
file->mode = strdup(mode);
|
||||||
if (file_pool.context->io_buffer_size) {
|
if (file_pool.context->io_buffer_size) {
|
||||||
#ifdef POSIX_MEMALIGN
|
#ifdef POSIX_MEMALIGN
|
||||||
if (posix_memalign((void**)&(file->buffer), sysconf(_SC_PAGESIZE), file_pool.context->io_buffer_size)) {
|
if (posix_memalign((void**)&(file->buffer), sysconf(_SC_PAGESIZE), file_pool.context->io_buffer_size)) {
|
||||||
|
|
Loading…
Reference in New Issue