file(READ ... LIMIT <n>) gives surprising results
I wanted to use the file(READ
parameter LIMIT
to limit the read to the single first byte. But the limiter functionality seems to have an off-by-one error and problems with trailing newlines:
cmake_minimum_required(VERSION 3.7)
file(WRITE fizz "abcde")
file(READ fizz FIZZ_VALUE LIMIT 2)
string(LENGTH ${FIZZ_VALUE} FIZZ_LENGTH)
message(STATUS "fizz[${FIZZ_LENGTH}]=\'${FIZZ_VALUE}\'")
file(WRITE buzz "ab
")
file(READ buzz BUZZ_VALUE LIMIT 1)
string(LENGTH ${BUZZ_VALUE} BUZZ_LENGTH)
message(STATUS "buzz[${BUZZ_LENGTH}]=\'${BUZZ_VALUE}\'")
the result is
-- fizz[1]='a'
-- buzz[1]='
'