From 703af39239b9dbb8a4159cc39fc483e4cc8df1b6 Mon Sep 17 00:00:00 2001 From: mithe24 Date: Mon, 29 Sep 2025 16:53:18 +0200 Subject: chore: Added provided code snippets --- snippets/fileHandling.s | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 snippets/fileHandling.s (limited to 'snippets/fileHandling.s') diff --git a/snippets/fileHandling.s b/snippets/fileHandling.s new file mode 100644 index 0000000..17a9428 --- /dev/null +++ b/snippets/fileHandling.s @@ -0,0 +1,16 @@ +# int getFileSize(int fd) +# +# Returns the size (in bytes) of the file indicated by the file descriptor. +.section .data +.Lstat: .space 144 # size of the fstat struct +.section .text +.globl getFileSize +.type getFileSize, @function +getFileSize: + movq $5, %rax # fstat + # rdi already contains the fd + movq $.Lstat, %rsi # buffer to write fstat data into + syscall + movq $.Lstat, %rax + movq 48(%rax), %rax # position of size in the struct + ret -- cgit v1.2.3-70-g09d2