summaryrefslogtreecommitdiff
path: root/src/io.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/io.c')
-rw-r--r--src/io.c19
1 files changed, 16 insertions, 3 deletions
diff --git a/src/io.c b/src/io.c
index be894dd..c9627d3 100644
--- a/src/io.c
+++ b/src/io.c
@@ -18,6 +18,7 @@
along with Nekopack. If not, see <http://www.gnu.org/licenses/>. */
#include <stdint.h>
+#include <stdio.h>
#include <stdlib.h>
#include <string.h>
@@ -86,9 +87,21 @@ size_t stream_tell(struct stream *s) {
}
-/* Sets the stream's position indicator to the given `pos`. */
-void stream_seek(struct stream *s, size_t pos) {
- s->_cur = s->_start + pos;
+/* Sets the stream's position indicator to the given `pos`. If `whence`
+ is set to SEEK_SET, SEEK_CUR, or SEEK_END, the offset is relative to
+ the start of the file, the current position indicator, or
+ end-of-file, respectively. */
+void stream_seek(struct stream *s, size_t pos, int whence) {
+ switch (whence) {
+ case SEEK_SET:
+ s->_cur = s->_start + pos;
+ break;
+ case SEEK_CUR:
+ s->_cur += pos;
+ break;
+ case SEEK_END:
+ s->_cur = s->_start + s->len - pos;
+ }
}