mirror of
https://github.com/drasko/codezero.git
synced 2026-03-17 09:41:49 +01:00
Few minor fixes
This commit is contained in:
@@ -26,10 +26,9 @@ int exectest(pid_t parent_of_all)
|
||||
int left, cnt;
|
||||
char *argv[5];
|
||||
char *envp[2];
|
||||
void *buf;
|
||||
|
||||
memset(filename, 0, 128);
|
||||
sprintf(filename, "/execfile%d", getpid());
|
||||
sprintf(filename, "/home/bahadir/execfile%d", getpid());
|
||||
|
||||
/* First create a new file and write the executable data to that file */
|
||||
if ((fd = open(filename, O_RDWR | O_CREAT | O_TRUNC, S_IRWXU)) < 0) {
|
||||
@@ -67,6 +66,7 @@ int exectest(pid_t parent_of_all)
|
||||
goto out_err;
|
||||
}
|
||||
|
||||
#if 0
|
||||
/* Reopen */
|
||||
if ((fd = open(filename, O_RDONLY, S_IRWXU)) < 0) {
|
||||
err = errno;
|
||||
@@ -82,7 +82,7 @@ int exectest(pid_t parent_of_all)
|
||||
printf("First page of read and written file doesn't match\n");
|
||||
else
|
||||
printf("First page matches.\n");
|
||||
|
||||
#endif
|
||||
/* Set up some arguments */
|
||||
argv[0] = "FIRST ARG";
|
||||
argv[1] = "SECOND ARG";
|
||||
|
||||
@@ -8,6 +8,41 @@
|
||||
#include <tests.h>
|
||||
#include <errno.h>
|
||||
|
||||
#define PAGE_SIZE 0x1000
|
||||
|
||||
int small_io_test(void)
|
||||
{
|
||||
int fd1, fd2;
|
||||
char *string = "abcdefg";
|
||||
char strbuf[30];
|
||||
char *path = "/text.txt";
|
||||
fd1 = open(path, O_TRUNC | O_RDWR | O_CREAT, S_IRWXU);
|
||||
fd2 = open(path, O_RDWR, 0);
|
||||
|
||||
printf("fd1: %d, fd2: %d\n", fd1, fd2);
|
||||
perror("OPEN");
|
||||
|
||||
for (int i = 0; i < 4; i++) {
|
||||
sprintf(strbuf, "%s%d", string, i);
|
||||
printf("Writing to %s offset %x, string: %s\n",
|
||||
path, i*PAGE_SIZE, strbuf);
|
||||
lseek(fd1, i*PAGE_SIZE, SEEK_SET);
|
||||
write(fd1, strbuf, strlen(strbuf) + 1);
|
||||
}
|
||||
close(fd1);
|
||||
|
||||
memset(strbuf, 0, 30);
|
||||
for (int i = 0; i < 4; i++) {
|
||||
lseek(fd2, i*PAGE_SIZE, SEEK_SET);
|
||||
read(fd2, strbuf, 30);
|
||||
printf("Read %s, offset %x as %s\n", path, i*PAGE_SIZE, strbuf);
|
||||
}
|
||||
|
||||
close(fd2);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int fileio(void)
|
||||
{
|
||||
int fd;
|
||||
|
||||
Reference in New Issue
Block a user