mirror of
https://github.com/amadvance/snapraid.git
synced 2026-10-12 02:10:54 +00:00
Make sgetbs() return the number of characters read on success
This commit is contained in:
+1
-1
@@ -144,7 +144,7 @@ void test(int advise_mode)
|
||||
char copy[STR_MAX];
|
||||
memset(str, ' ' + j, j - 1);
|
||||
str[j - 1] = 0;
|
||||
if (sgetbs(s, copy, sizeof(copy)) != 0 || strcmp(copy, str) != 0) {
|
||||
if (sgetbs(s, copy, sizeof(copy)) != (ssize_t)(j - 1) || strcmp(copy, str) != 0) {
|
||||
/* LCOV_EXCL_START */
|
||||
exit(EXIT_FAILURE);
|
||||
/* LCOV_EXCL_STOP */
|
||||
|
||||
@@ -2183,6 +2183,30 @@ static void test_stream(void)
|
||||
exit(EXIT_FAILURE);
|
||||
/* LCOV_EXCL_STOP */
|
||||
}
|
||||
|
||||
/* sgetbs test */
|
||||
unsigned char buf_bs[] = { 0x85, 'h', 'e', 'l', 'l', 'o' };
|
||||
char str_bs[16];
|
||||
memset(&f, 0, sizeof(f));
|
||||
f.pos = buf_bs;
|
||||
f.end = buf_bs + sizeof(buf_bs);
|
||||
if (sgetbs(&f, str_bs, sizeof(str_bs)) != 5 || strcmp(str_bs, "hello") != 0) {
|
||||
/* LCOV_EXCL_START */
|
||||
log_fatal(EINTERNAL, "test_stream: sgetbs valid string failed\n");
|
||||
exit(EXIT_FAILURE);
|
||||
/* LCOV_EXCL_STOP */
|
||||
}
|
||||
|
||||
/* sgetbs buffer too small test */
|
||||
memset(&f, 0, sizeof(f));
|
||||
f.pos = buf_bs;
|
||||
f.end = buf_bs + sizeof(buf_bs);
|
||||
if (sgetbs(&f, str_bs, 5) >= 0) {
|
||||
/* LCOV_EXCL_START */
|
||||
log_fatal(EINTERNAL, "test_stream: sgetbs small buffer accepted\n");
|
||||
exit(EXIT_FAILURE);
|
||||
/* LCOV_EXCL_STOP */
|
||||
}
|
||||
}
|
||||
|
||||
static void test_extent_run(void)
|
||||
|
||||
+1
-1
@@ -2416,7 +2416,7 @@ static void state_read_content(struct snapraid_state* state, const char* path, S
|
||||
int has_info;
|
||||
int has_invalid_parity;
|
||||
char buffer[PATH_MAX];
|
||||
int ret;
|
||||
ssize_t ret;
|
||||
tommy_array disk_mapping;
|
||||
uint32_t mapping_max;
|
||||
tommy_hashdyn bucket_hash;
|
||||
|
||||
+8
-2
@@ -691,7 +691,7 @@ int sgetble32(STREAM* f, uint32_t* value)
|
||||
return 0;
|
||||
}
|
||||
|
||||
int sgetbs(STREAM* f, char* str, size_t size)
|
||||
ssize_t sgetbs(STREAM* f, char* str, size_t size)
|
||||
{
|
||||
uint64_t len;
|
||||
|
||||
@@ -709,7 +709,13 @@ int sgetbs(STREAM* f, char* str, size_t size)
|
||||
|
||||
str[len] = 0;
|
||||
|
||||
return sread(f, str, len);
|
||||
if (sread(f, str, len) != 0) {
|
||||
/* LCOV_EXCL_START */
|
||||
return -1;
|
||||
/* LCOV_EXCL_STOP */
|
||||
}
|
||||
|
||||
return len;
|
||||
}
|
||||
|
||||
int swrite_uncached(const void* void_data, size_t size, STREAM* f)
|
||||
|
||||
+1
-1
@@ -329,7 +329,7 @@ int sgetble32(STREAM* f, uint32_t* value);
|
||||
* Read a binary string.
|
||||
* Return -1 on error or if the buffer is too small, or the number of chars read.
|
||||
*/
|
||||
int sgetbs(STREAM* f, char* str, size_t size);
|
||||
ssize_t sgetbs(STREAM* f, char* str, size_t size);
|
||||
|
||||
/****************************************************************************/
|
||||
/* put */
|
||||
|
||||
Reference in New Issue
Block a user