aboutsummaryrefslogtreecommitdiff
path: root/snippets/fileHandling.s
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--snippets/fileHandling.s16
1 files changed, 16 insertions, 0 deletions
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