mirror of
https://github.com/facebook/zstd.git
synced 2025-08-07 06:23:00 +03:00
return final \0
directly from readLine()
This commit is contained in:
@@ -214,14 +214,18 @@ U64 UTIL_getTotalFileSize(const char* const * fileNamesTable, unsigned nbFiles)
|
|||||||
|
|
||||||
|
|
||||||
/* condition : @file must be valid, and not have reached its end.
|
/* condition : @file must be valid, and not have reached its end.
|
||||||
* @return : length of line written into buf, without the final '\n',
|
* @return : length of line written into @buf, ended with `\0` instead of '\n',
|
||||||
* or 0, if there is no new line */
|
* or 0, if there is no new line */
|
||||||
static size_t readLineFromFile(char* buf, size_t len, FILE* file)
|
static size_t readLineFromFile(char* buf, size_t len, FILE* file)
|
||||||
{
|
{
|
||||||
assert(!feof(file));
|
assert(!feof(file));
|
||||||
CONTROL( fgets(buf, (int) len, file) == buf ); /* requires success */
|
CONTROL( fgets(buf, (int) len, file) == buf ); /* requires success */
|
||||||
|
{ size_t linelen = strlen(buf);
|
||||||
if (strlen(buf)==0) return 0;
|
if (strlen(buf)==0) return 0;
|
||||||
return strlen(buf) - (buf[strlen(buf)-1] == '\n'); /* ignore final '\n' character */
|
if (buf[linelen-1] == '\n') linelen--;
|
||||||
|
buf[linelen] = '\0';
|
||||||
|
return linelen+1;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Conditions :
|
/* Conditions :
|
||||||
@@ -250,8 +254,7 @@ readLinesFromFile(void* dst, size_t dstCapacity,
|
|||||||
size_t const lineLength = readLineFromFile(buf+pos, dstCapacity-pos, inputFile);
|
size_t const lineLength = readLineFromFile(buf+pos, dstCapacity-pos, inputFile);
|
||||||
if (lineLength == 0) break;
|
if (lineLength == 0) break;
|
||||||
assert(pos + lineLength < dstCapacity);
|
assert(pos + lineLength < dstCapacity);
|
||||||
buf[pos+lineLength] = '\0'; /* replace '\n' with '\0'*/
|
pos += lineLength;
|
||||||
pos += lineLength + 1;
|
|
||||||
++nbFiles;
|
++nbFiles;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -866,9 +866,8 @@ else
|
|||||||
fi
|
fi
|
||||||
|
|
||||||
|
|
||||||
println "\n===> lz4 frame tests "
|
|
||||||
|
|
||||||
if [ $LZ4MODE -eq 1 ]; then
|
if [ $LZ4MODE -eq 1 ]; then
|
||||||
|
println "\n===> lz4 frame tests "
|
||||||
./datagen > tmp
|
./datagen > tmp
|
||||||
$ZSTD -f --format=lz4 tmp
|
$ZSTD -f --format=lz4 tmp
|
||||||
$ZSTD -f tmp
|
$ZSTD -f tmp
|
||||||
@@ -876,9 +875,10 @@ if [ $LZ4MODE -eq 1 ]; then
|
|||||||
truncateLastByte tmp.lz4 | $ZSTD -t > $INTOVOID && die "incomplete frame not detected !"
|
truncateLastByte tmp.lz4 | $ZSTD -t > $INTOVOID && die "incomplete frame not detected !"
|
||||||
rm tmp*
|
rm tmp*
|
||||||
else
|
else
|
||||||
println "lz4 mode not supported"
|
println "\nlz4 mode not supported"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
|
||||||
println "\n===> suffix list test"
|
println "\n===> suffix list test"
|
||||||
|
|
||||||
! $ZSTD -d tmp.abc 2> tmplg
|
! $ZSTD -d tmp.abc 2> tmplg
|
||||||
@@ -896,6 +896,7 @@ if [ $LZ4MODE -ne 1 ]; then
|
|||||||
grep ".lz4" tmplg > $INTOVOID && die "Unsupported suffix listed"
|
grep ".lz4" tmplg > $INTOVOID && die "Unsupported suffix listed"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
|
||||||
println "\n===> tar extension tests "
|
println "\n===> tar extension tests "
|
||||||
|
|
||||||
rm -f tmp tmp.tar tmp.tzst tmp.tgz tmp.txz tmp.tlz4
|
rm -f tmp tmp.tar tmp.tzst tmp.tgz tmp.txz tmp.tlz4
|
||||||
@@ -934,7 +935,6 @@ touch tmp.t tmp.tz tmp.tzs
|
|||||||
! $ZSTD -d tmp.tz
|
! $ZSTD -d tmp.tz
|
||||||
! $ZSTD -d tmp.tzs
|
! $ZSTD -d tmp.tzs
|
||||||
|
|
||||||
exit
|
|
||||||
|
|
||||||
println "\n===> zstd round-trip tests "
|
println "\n===> zstd round-trip tests "
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user