PKUOS - Pintos
Pintos source browser for PKU Operating System course
write-boundary.c
Go to the documentation of this file.
1/** Writes data spanning two pages in virtual address space,
2 which must succeed. */
3
4#include <string.h>
5#include <syscall.h>
7#include "tests/userprog/sample.inc"
8#include "tests/lib.h"
9#include "tests/main.h"
10
11void
12test_main (void)
13{
14 int handle;
15 int byte_cnt;
16 char *sample_p;
17
18 sample_p = copy_string_across_boundary (sample);
19
20 CHECK ((handle = open ("sample.txt")) > 1, "open \"sample.txt\"");
21
22 byte_cnt = write (handle, sample_p, sizeof sample - 1);
23 if (byte_cnt != sizeof sample - 1)
24 fail ("write() returned %d instead of %zu", byte_cnt, sizeof sample - 1);
25}
static size_t byte_cnt(size_t bit_cnt)
Returns the number of bytes required for BIT_CNT bits.
Definition: bitmap.c:58
char * copy_string_across_boundary(const char *src)
Returns a copy of SRC split across the boundary between two pages.
Definition: boundary.c:29
int open(const char *file)
Definition: syscall.c:103
int write(int fd, const void *buffer, unsigned size)
Definition: syscall.c:121
void fail(const char *format,...)
Definition: lib.c:40
#define CHECK(SUCCESS,...)
Takes an expression to test for SUCCESS and a message, which may include printf-style arguments.
Definition: lib.h:29
void test_main(void)
Writes data spanning two pages in virtual address space, which must succeed.