Skip to content

Commit

Permalink
Fix fseek test (#2055)
Browse files Browse the repository at this point in the history
TYPE: bug fix

KEYWORDS: fseek, compilation, cmake

SOURCE: internal

DESCRIPTION OF CHANGES:
Problem:
The fseek test lacks correct syntax causing false negative reports of
feature not existing when newer compiler standards disallow this.

Solution:
Add `int` to the main program in the fseek test. Also to add further
robustness in detecting this feature, use the `-D_FILE_OFFSET_BITS=64
-D_LARGEFILE_SOURCE=1` generally *nix standard defines.

LIST OF MODIFIED FILES: 
M       CMakeLists.txt
M       confcheck/CMakeLists.txt
M       tools/fseek_test.c

RELEASE NOTE: Fix fseek test
  • Loading branch information
islas authored Oct 14, 2024
1 parent 1e96a7e commit 2f844ad
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 7 deletions.
11 changes: 7 additions & 4 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -810,10 +810,13 @@ endif()
#!TODO Leaving as is in WRF for now but investigate why we don't do this
# https://stackoverflow.com/a/1035713
# If fseeko64 succeeds, use that, else check if we can fall back to fseeko, and if not just use fseek
if ( ${FSEEKO64} )
list( APPEND PROJECT_COMPILE_DEFINITIONS FSEEKO64_OK )
elseif( "${FSEEKO}" )
list( APPEND PROJECT_COMPILE_DEFINITIONS FSEEKO_OK )
if ( "${FSEEKO64}" OR "${FSEEKO}" )
list( APPEND PROJECT_COMPILE_DEFINITIONS _FILE_OFFSET_BITS=64 _LARGEFILE_SOURCE=1 )
if ( "${FSEEKO64}" )
list( APPEND PROJECT_COMPILE_DEFINITIONS FSEEKO64_OK )
elseif( "${FSEEKO}" )
list( APPEND PROJECT_COMPILE_DEFINITIONS FSEEKO_OK )
endif()
else()
list( APPEND PROJECT_COMPILE_DEFINITIONS FSEEK_OK )
endif()
Expand Down
4 changes: 2 additions & 2 deletions confcheck/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ wrf_conf_check(
RESULT_VAR FSEEKO64
SOURCE ${PROJECT_SOURCE_DIR}/tools/fseek_test.c
EXTENSION .c
ADDITIONAL_DEFINITIONS -DTEST_FSEEKO64 -DFILE_TO_TEST="${PROJECT_SOURCE_DIR}/CMakeLists.txt"
ADDITIONAL_DEFINITIONS -DTEST_FSEEKO64 -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE=1 -DFILE_TO_TEST="${PROJECT_SOURCE_DIR}/CMakeLists.txt"
MESSAGE "fseeko64 not supported, checking alternate fseeko"
)

Expand All @@ -60,7 +60,7 @@ if ( NOT "${FSEEKO64}" )
RESULT_VAR FSEEKO
SOURCE ${PROJECT_SOURCE_DIR}/tools/fseek_test.c
EXTENSION .c
ADDITIONAL_DEFINITIONS -DTEST_FSEEKO -DFILE_TO_TEST="${PROJECT_SOURCE_DIR}/CMakeLists.txt"
ADDITIONAL_DEFINITIONS -DTEST_FSEEKO -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE=1 -DFILE_TO_TEST="${PROJECT_SOURCE_DIR}/CMakeLists.txt"
MESSAGE "fseeko not supported, compiling with fseek (caution with large files)"
)
endif()
Expand Down
3 changes: 2 additions & 1 deletion tools/fseek_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#include <stdlib.h>
#include <errno.h>
#include <sys/types.h>
int
main()
{
FILE *fp ;
Expand Down Expand Up @@ -43,6 +44,6 @@ main()
retval = 1 ;
}
fclose(fp) ;
exit(retval) ;
return retval ;
}

0 comments on commit 2f844ad

Please sign in to comment.