Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add testing user app:sfs_filetest1.c in lab8
- Loading branch information
Showing
1 changed file
with
43 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
#include <ulib.h> | ||
#include <stdio.h> | ||
#include <stdlib.h> | ||
#include <string.h> | ||
#include <stat.h> | ||
#include <file.h> | ||
#include <dir.h> | ||
#include <unistd.h> | ||
|
||
#define printf(...) fprintf(1, __VA_ARGS__) | ||
|
||
static int safe_open(const char *path, int open_flags) | ||
{ | ||
int fd = open(path, open_flags); | ||
printf("fd is %d\n",fd); | ||
assert(fd >= 0); | ||
return fd; | ||
} | ||
|
||
static struct stat *safe_fstat(int fd) | ||
{ | ||
static struct stat __stat, *stat = &__stat; | ||
int ret = fstat(fd, stat); | ||
assert(ret == 0); | ||
return stat; | ||
} | ||
|
||
|
||
static void safe_read(int fd, void *data, size_t len) | ||
{ | ||
int ret = read(fd, data, len); | ||
assert(ret == len); | ||
} | ||
|
||
|
||
int main(void) | ||
{ | ||
int fd1 = safe_open("sfs_filetest1", O_RDONLY); | ||
struct stat *stat = safe_fstat(fd1); | ||
assert(stat->st_size >= 0 && stat->st_blocks >= 0); | ||
printf("sfs_filetest1 pass.\n"); | ||
return 0; | ||
} |