[Git][cmucl/cmucl][issue-125-unix-stat-wrong] Address review comments

Raymond Toy (@rtoy) gitlab at common-lisp.net
Sun Aug 14 00:52:20 UTC 2022



Raymond Toy pushed to branch issue-125-unix-stat-wrong at cmucl / cmucl


Commits:
6f0f8c05 by Raymond Toy at 2022-08-13T17:51:12-07:00
Address review comments

In unix.lisp, use `c-call:long-long` and `c-call:unsigned-long-long`
instead of `int64-t` and `u-int64-t`.

Renamed functions from `unix_stat` to `os_stat`.

In `os_stat` and friends, if the syscall fails, just return with the
code instead of copying random stuff.

- - - - -


2 changed files:

- src/code/unix.lisp
- src/lisp/os-common.c


Changes:

=====================================
src/code/unix.lisp
=====================================
@@ -1337,37 +1337,37 @@
        ;; to the stat function.  fstat is different from stat and
        ;; lstat since it takes an fd for the first arg instead of
        ;; string.
-       `(with-alien ((dev u-int64-t)
-		     (ino u-int64-t)
+       `(with-alien ((dev c-call:long-long)
+		     (ino c-call:unsigned-long-long)
 		     (mode c-call:unsigned-int)
-		     (nlink u-int64-t)
+		     (nlink c-call:unsigned-long-long)
 		     (uid c-call:unsigned-int)
 		     (gid c-call:unsigned-int)
-		     (rdev u-int64-t)
-		     (size int64-t)
-		     (atime int64-t)
-		     (mtime int64-t)
-		     (ctime int64-t)
+		     (rdev c-call:unsigned-long-long)
+		     (size c-call:long-long)
+		     (atime c-call:long-long)
+		     (mtime c-call:long-long)
+		     (ctime c-call:long-long)
 		     (blksize c-call:long)
-		     (blocks int64-t))
+		     (blocks c-call:long-long))
 	  (let ((result
 		  (alien-funcall
 		   (extern-alien ,c-func-name
 				 (function int
 					   ,first-arg-type
-					   (* u-int64-t)
-					   (* u-int64-t)
+					   (* c-call:long-long)
+					   (* c-call:unsigned-long-long)
 					   (* c-call:unsigned-int)
-					   (* u-int64-t)
+					   (* c-call:unsigned-long-long)
 					   (* c-call:unsigned-int)
 					   (* c-call:unsigned-int)
-					   (* u-int64-t)
-					   (* int64-t)
-					   (* int64-t)
-					   (* int64-t)
-					   (* int64-t)
+					   (* c-call:unsigned-long-long)
+					   (* c-call:long-long)
+					   (* c-call:long-long)
+					   (* c-call:long-long)
+					   (* c-call:long-long)
 					   (* c-call:long)
-					   (* int64-t)))
+					   (* c-call:long-long)))
 		   ,first-arg
 		   (addr dev)
 		   (addr ino)
@@ -1421,7 +1421,7 @@
     (declare (type unix-pathname name))
     (when (string= name "")
       (setf name "."))
-    (call-stat "unix_stat" c-call:c-string (%name->file name)))
+    (call-stat "os_stat" c-call:c-string (%name->file name)))
 
   (defun unix-lstat (name)
     "Unix-lstat is similar to unix-stat except the specified
@@ -1443,7 +1443,7 @@
      st_blocks     Number of blocks allocated. (Block size is implementation dependent.)
 "
     (declare (type unix-pathname name))
-    (call-stat "unix_lstat" c-call:c-string (%name->file name)))
+    (call-stat "os_lstat" c-call:c-string (%name->file name)))
 
   (defun unix-fstat (fd)
     _N"Unix-fstat is similar to unix-stat except the file is specified
@@ -1465,7 +1465,7 @@
      st_blocks     Number of blocks allocated. (Block size is implementation dependent.)
 "
     (declare (type unix-fd fd))
-    (call-stat "unix_fstat" int fd)))
+    (call-stat "os_fstat" int fd)))
 
 (def-alien-type nil
   (struct rusage


=====================================
src/lisp/os-common.c
=====================================
@@ -5,12 +5,6 @@
 
 */
 
-#ifdef __linux__
-/* Needed to get 64-bit objects for stat and friends on Linux. */
-#define _LARGEFILE_SOURCE
-#define _FILE_OFFSET_BITS 64
-#endif
-
 #include <errno.h>
 #include <math.h>
 #include <netdb.h>
@@ -606,17 +600,21 @@ os_sleep(double seconds)
  * function that works across all OSes.
  */
 int
-unix_stat(const char* path, u_int64_t *dev, u_int64_t *ino, unsigned int *mode, u_int64_t *nlink,
-          unsigned int *uid, unsigned int *gid, u_int64_t *rdev, int64_t *size,
-          int64_t *atime, int64_t *mtime, int64_t *ctime,
-          long *blksize, int64_t *blocks)
+os_stat(const char* path, u_int64_t *dev, u_int64_t *ino, unsigned int *mode, u_int64_t *nlink,
+        unsigned int *uid, unsigned int *gid, u_int64_t *rdev, int64_t *size,
+        int64_t *atime, int64_t *mtime, int64_t *ctime,
+        long *blksize, int64_t *blocks)
 {
     int rc;
     struct stat buf;
 
     rc = stat(path, &buf);
 
-#if 0
+    if (rc != 0) {
+        return rc;
+    }
+        
+#if 1
     /*
      * Useful prints to see the actual size of the various
      * fields. Helpful for porting this to other OSes that we haven't
@@ -655,16 +653,20 @@ unix_stat(const char* path, u_int64_t *dev, u_int64_t *ino, unsigned int *mode,
 }
 
 int
-unix_fstat(int fd, u_int64_t *dev, u_int64_t *ino, unsigned int *mode, u_int64_t *nlink,
-           unsigned int *uid, unsigned int *gid, u_int64_t *rdev, int64_t *size,
-           int64_t *atime, int64_t *mtime, int64_t *ctime,
-           long *blksize, int64_t *blocks)
+os_fstat(int fd, u_int64_t *dev, u_int64_t *ino, unsigned int *mode, u_int64_t *nlink,
+         unsigned int *uid, unsigned int *gid, u_int64_t *rdev, int64_t *size,
+         int64_t *atime, int64_t *mtime, int64_t *ctime,
+         long *blksize, int64_t *blocks)
 {
     int rc;
     struct stat buf;
 
     rc = fstat(fd, &buf);
 
+    if (rc != 0) {
+        return rc;
+    }
+
     *dev = buf.st_dev;
     *ino = buf.st_ino;
     *mode = buf.st_mode;
@@ -683,16 +685,20 @@ unix_fstat(int fd, u_int64_t *dev, u_int64_t *ino, unsigned int *mode, u_int64_t
 }
 
 int
-unix_lstat(const char* path, u_int64_t *dev, u_int64_t *ino, unsigned int *mode, u_int64_t *nlink,
-           unsigned int *uid, unsigned int *gid, u_int64_t *rdev, int64_t *size,
-           int64_t *atime, int64_t *mtime, int64_t *ctime,
-           long *blksize, int64_t *blocks)
+os_lstat(const char* path, u_int64_t *dev, u_int64_t *ino, unsigned int *mode, u_int64_t *nlink,
+         unsigned int *uid, unsigned int *gid, u_int64_t *rdev, int64_t *size,
+         int64_t *atime, int64_t *mtime, int64_t *ctime,
+         long *blksize, int64_t *blocks)
 {
     int rc;
     struct stat buf;
 
     rc = lstat(path, &buf);
 
+    if (rc != 0) {
+        return rc;
+    }
+
     *dev = buf.st_dev;
     *ino = buf.st_ino;
     *mode = buf.st_mode;



View it on GitLab: https://gitlab.common-lisp.net/cmucl/cmucl/-/commit/6f0f8c0501d22d6e63d237fd094aeef4260a269e

-- 
View it on GitLab: https://gitlab.common-lisp.net/cmucl/cmucl/-/commit/6f0f8c0501d22d6e63d237fd094aeef4260a269e
You're receiving this email because of your account on gitlab.common-lisp.net.


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mailman.common-lisp.net/pipermail/cmucl-cvs/attachments/20220814/41b2fae5/attachment-0001.html>


More information about the cmucl-cvs mailing list