mirror of
https://github.com/Noratrieb/libuwuc.git
synced 2026-01-14 19:55:07 +01:00
fd
This commit is contained in:
parent
8d1795ad1a
commit
4d4af78afe
10 changed files with 59 additions and 9 deletions
29
tests/c/fd.c
Normal file
29
tests/c/fd.c
Normal 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");
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue