ref: d8f3a8ba78e93d6c421d0fad28cf3359ebb729da
parent: d193ea7221257855663b31a409adbbd77bf86110
author: Sigrid Solveig Haflínudóttir <sigrid@ftrv.se>
date: Thu May 11 10:53:12 EDT 2023
qw/sys: use dir(f)stat in place of raw stat reading
--- a/qw/sys.c
+++ b/qw/sys.c
@@ -54,11 +54,14 @@
int
Sys_FileTime(char *path)
{
- uchar bs[1024];
+ Dir *d;
+ ulong t;
- if(stat(path, bs, sizeof bs) < 0)
- return -1;
- return *((int *)(bs+2+2+4+1+4+8+4+4)); /* mtime[4] */
+ t = 0;
+ if((d = dirstat(path)) != nil)
+ t = d->mtime;
+ free(d);
+ return t;
}
int
@@ -79,13 +82,14 @@
vlong
flen(int fd)
{
- uchar bs[1024];
+ Dir *d;
+ vlong sz;
- if(fstat(fd, bs, sizeof bs) < 0){
- fprint(2, "flen:fstat: %r\n");
- return -1;
- }
- return *((vlong *)(bs+2+2+4+1+4+8+4+4+4)); /* length[8] */
+ sz = -1;
+ if((d = dirfstat(fd)) != nil)
+ sz = d->length;
+ free(d);
+ return sz;
}
double