tests
This commit is contained in:
@@ -4,7 +4,11 @@ const AT_FDCWD: c_int = -100;
|
||||
|
||||
pub fn brk(addr: *const c_void) -> c_int {
|
||||
unsafe {
|
||||
syscall!(BRK, addr) as c_int
|
||||
let newbrk = syscall!(BRK, addr);
|
||||
if newbrk < addr as usize {
|
||||
return -1
|
||||
}
|
||||
0
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -190,13 +190,6 @@ pub extern "C" fn getchar_unlocked() -> c_int {
|
||||
unimplemented!();
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub extern "C" fn getopt(argc: c_int,
|
||||
argv: *const *const c_char,
|
||||
optstring: c_char) -> c_int {
|
||||
unimplemented!();
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub extern "C" fn gets(s: *mut c_char)
|
||||
-> *mut c_char {
|
||||
|
||||
@@ -74,16 +74,6 @@ pub extern "C" fn crypt(key: *const c_char, salt: *const c_char) -> *mut c_char
|
||||
unimplemented!();
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub extern "C" fn ctermid(s: *mut c_char) -> *mut c_char {
|
||||
unimplemented!();
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub extern "C" fn cuserid(s: *mut c_char) -> *mut c_char {
|
||||
unimplemented!();
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub extern "C" fn dup(fildes: c_int) -> c_int {
|
||||
platform::dup(fildes)
|
||||
|
||||
@@ -1,7 +1,13 @@
|
||||
/alloc
|
||||
/args
|
||||
/brk
|
||||
/chdir
|
||||
/create
|
||||
/create.out
|
||||
/dup
|
||||
/dup.out
|
||||
/fchdir
|
||||
/fsync
|
||||
/math
|
||||
/printf
|
||||
/write
|
||||
|
||||
@@ -1,7 +1,12 @@
|
||||
BINS=\
|
||||
alloc \
|
||||
brk \
|
||||
args \
|
||||
chdir \
|
||||
create \
|
||||
dup \
|
||||
fchdir \
|
||||
fsync \
|
||||
math \
|
||||
printf \
|
||||
write
|
||||
|
||||
@@ -9,4 +9,12 @@ int main(int argc, char ** argv) {
|
||||
ptr[i] = (char)i;
|
||||
}
|
||||
free(ptr);
|
||||
|
||||
char * ptrc = (char *)calloc(256,1);
|
||||
printf("calloc %p\n", ptrc);
|
||||
for(int i = 0; i < 256; i++) {
|
||||
ptrc[i] = (char)i;
|
||||
}
|
||||
free(ptrc);
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,8 @@
|
||||
#include <unistd.h>
|
||||
#include <stdio.h>
|
||||
|
||||
int main(int argc, char** argv) {
|
||||
int status = brk((void*)100);
|
||||
printf("brk exited with status code %d\n", status);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,15 @@
|
||||
#include <unistd.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
int main(int argc, char** argv) {
|
||||
char* cwd1 = malloc(4096*sizeof(char));//(char*) calloc(4096 + 1, sizeof(char));
|
||||
getcwd(cwd1, 4096);
|
||||
printf("initial cwd: %s\n", cwd1);
|
||||
free(cwd1);
|
||||
chdir("..");
|
||||
char* cwd2 = malloc(4096*sizeof(char));//(char*) calloc(4096 + 1, sizeof(char));
|
||||
getcwd(cwd2, 4096);
|
||||
printf("final cwd: %s\n", cwd2);
|
||||
free(cwd2);
|
||||
}
|
||||
+16
@@ -0,0 +1,16 @@
|
||||
#include <unistd.h>
|
||||
#include <fcntl.h>
|
||||
#include <stdio.h>
|
||||
|
||||
int main(int argc, char** argv) {
|
||||
creat("dup.out", 0777);
|
||||
int fd1 = open("dup.out", 0, 0);
|
||||
int fd2 = dup(fd1);
|
||||
printf("fd %d duped into fd %d\n", fd1, fd2);
|
||||
close(fd1);
|
||||
close(fd2);
|
||||
int fd3 = open("dup.out", 0x0002, 0x1000);
|
||||
dup2(fd3, 1);
|
||||
printf("hello fd %d", fd3);
|
||||
close(fd3);
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
#include <unistd.h>
|
||||
#include <fcntl.h>
|
||||
#include <stdio.h>
|
||||
|
||||
int main (int argc, char** argv) {
|
||||
int fd = open("..", 0, 0);
|
||||
int status;
|
||||
status = fchdir(fd);
|
||||
printf("fchdir exited with status code %d\n", status);
|
||||
close(fd);
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
#include <unistd.h>
|
||||
#include <fcntl.h>
|
||||
#include <stdio.h>
|
||||
|
||||
int main (int argc, char** argv) {
|
||||
int fd = open(".", 0, 0);
|
||||
int status;
|
||||
status = fsync(fd);
|
||||
printf("fsync exited with status code %d\n", status);
|
||||
close(fd);
|
||||
}
|
||||
Reference in New Issue
Block a user