This commit is contained in:
Paul Sajna
2018-03-04 16:34:46 -08:00
parent fc92d95b35
commit 5cc52e4b19
11 changed files with 85 additions and 18 deletions
+5 -1
View File
@@ -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
}
}
-7
View File
@@ -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 {
-10
View File
@@ -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)
+6
View File
@@ -1,7 +1,13 @@
/alloc
/args
/brk
/chdir
/create
/create.out
/dup
/dup.out
/fchdir
/fsync
/math
/printf
/write
+5
View File
@@ -1,7 +1,12 @@
BINS=\
alloc \
brk \
args \
chdir \
create \
dup \
fchdir \
fsync \
math \
printf \
write
+8
View File
@@ -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);
}
+8
View File
@@ -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);
}
+15
View File
@@ -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
View File
@@ -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);
}
+11
View File
@@ -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);
}
+11
View File
@@ -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);
}