This commit is contained in:
nora 2023-10-08 11:52:35 +02:00
parent 8d1795ad1a
commit 4d4af78afe
10 changed files with 59 additions and 9 deletions

29
tests/c/fd.c Normal file
View file

@ -0,0 +1,29 @@
#include <unistd.h>
#include <fcntl.h>
#include <assert.h>
int main(int argc, char *argv[])
{
int alphabet = open("data/alphabet.txt", O_RDONLY);
assert(alphabet != -1 && "failed to open file");
off_t off;
off = lseek(alphabet, 10, SEEK_SET);
assert(off != -1 && "failed to seek file");
char buf[1];
ssize_t amount;
amount = read(alphabet, buf, 1);
assert(amount == 1 && "failed to read from alphabet");
assert(buf[0] == 'k' && "character at offest 10 is not k");
off = lseek(alphabet, 1, SEEK_CUR);
assert(off != -1 && "failed to seek file");
amount = read(alphabet, buf, 1);
assert(amount == 1 && "failed to read from alphabet");
assert(buf[0] == 'm' && "character at offest 12 is not m");
}