[SOLVED] CS代考计算机代写 /* Grows two files in parallel and checks that their contents are

30 $

File Name: CS代考计算机代写_/*_Grows_two_files_in_parallel_and_checks_that_their_contents_are.zip
File Size: 838.38 KB

SKU: 7019769709 Category: Tags: , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , ,

Or Upload Your Assignment Here:


/* Grows two files in parallel and checks that their contents are
correct. */

#include
#include
#include “tests/lib.h”
#include “tests/main.h”

#define FILE_SIZE 8143
static char buf_a[FILE_SIZE];
static char buf_b[FILE_SIZE];

static void
write_some_bytes (const char *file_name, int fd, const char *buf, size_t *ofs)
{
if (*ofs < FILE_SIZE) {size_t block_size = random_ulong () % (FILE_SIZE / 8) + 1;size_t ret_val;if (block_size > FILE_SIZE – *ofs)
block_size = FILE_SIZE – *ofs;

ret_val = write (fd, buf + *ofs, block_size);
if (ret_val != block_size)
fail (“write %zu bytes at offset %zu in ”%s” returned %zu”,
block_size, *ofs, file_name, ret_val);
*ofs += block_size;
}
}

void
test_main (void)
{
int fd_a, fd_b;
size_t ofs_a = 0, ofs_b = 0;

random_init (0);
random_bytes (buf_a, sizeof buf_a);
random_bytes (buf_b, sizeof buf_b);

CHECK (create (“a”, 0), “create ”a””);
CHECK (create (“b”, 0), “create ”b””);

CHECK ((fd_a = open (“a”)) > 1, “open ”a””);
CHECK ((fd_b = open (“b”)) > 1, “open ”b””);

msg (“write ”a” and ”b” alternately”);
while (ofs_a < FILE_SIZE || ofs_b < FILE_SIZE) {write_some_bytes (“a”, fd_a, buf_a, &ofs_a);write_some_bytes (“b”, fd_b, buf_b, &ofs_b);}msg (“close “a””);close (fd_a);msg (“close “b””);close (fd_b);check_file (“a”, buf_a, FILE_SIZE);check_file (“b”, buf_b, FILE_SIZE);}

Reviews

There are no reviews yet.

Only logged in customers who have purchased this product may leave a review.

Shopping Cart
[SOLVED] CS代考计算机代写 /* Grows two files in parallel and checks that their contents are
30 $