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
2 changed files:
Changes:
... | ... | @@ -1337,37 +1337,37 @@ |
1337 | 1337 | ;; to the stat function. fstat is different from stat and
|
1338 | 1338 | ;; lstat since it takes an fd for the first arg instead of
|
1339 | 1339 | ;; string.
|
1340 | - `(with-alien ((dev u-int64-t)
|
|
1341 | - (ino u-int64-t)
|
|
1340 | + `(with-alien ((dev c-call:long-long)
|
|
1341 | + (ino c-call:unsigned-long-long)
|
|
1342 | 1342 | (mode c-call:unsigned-int)
|
1343 | - (nlink u-int64-t)
|
|
1343 | + (nlink c-call:unsigned-long-long)
|
|
1344 | 1344 | (uid c-call:unsigned-int)
|
1345 | 1345 | (gid c-call:unsigned-int)
|
1346 | - (rdev u-int64-t)
|
|
1347 | - (size int64-t)
|
|
1348 | - (atime int64-t)
|
|
1349 | - (mtime int64-t)
|
|
1350 | - (ctime int64-t)
|
|
1346 | + (rdev c-call:unsigned-long-long)
|
|
1347 | + (size c-call:long-long)
|
|
1348 | + (atime c-call:long-long)
|
|
1349 | + (mtime c-call:long-long)
|
|
1350 | + (ctime c-call:long-long)
|
|
1351 | 1351 | (blksize c-call:long)
|
1352 | - (blocks int64-t))
|
|
1352 | + (blocks c-call:long-long))
|
|
1353 | 1353 | (let ((result
|
1354 | 1354 | (alien-funcall
|
1355 | 1355 | (extern-alien ,c-func-name
|
1356 | 1356 | (function int
|
1357 | 1357 | ,first-arg-type
|
1358 | - (* u-int64-t)
|
|
1359 | - (* u-int64-t)
|
|
1358 | + (* c-call:long-long)
|
|
1359 | + (* c-call:unsigned-long-long)
|
|
1360 | 1360 | (* c-call:unsigned-int)
|
1361 | - (* u-int64-t)
|
|
1361 | + (* c-call:unsigned-long-long)
|
|
1362 | 1362 | (* c-call:unsigned-int)
|
1363 | 1363 | (* c-call:unsigned-int)
|
1364 | - (* u-int64-t)
|
|
1365 | - (* int64-t)
|
|
1366 | - (* int64-t)
|
|
1367 | - (* int64-t)
|
|
1368 | - (* int64-t)
|
|
1364 | + (* c-call:unsigned-long-long)
|
|
1365 | + (* c-call:long-long)
|
|
1366 | + (* c-call:long-long)
|
|
1367 | + (* c-call:long-long)
|
|
1368 | + (* c-call:long-long)
|
|
1369 | 1369 | (* c-call:long)
|
1370 | - (* int64-t)))
|
|
1370 | + (* c-call:long-long)))
|
|
1371 | 1371 | ,first-arg
|
1372 | 1372 | (addr dev)
|
1373 | 1373 | (addr ino)
|
... | ... | @@ -1421,7 +1421,7 @@ |
1421 | 1421 | (declare (type unix-pathname name))
|
1422 | 1422 | (when (string= name "")
|
1423 | 1423 | (setf name "."))
|
1424 | - (call-stat "unix_stat" c-call:c-string (%name->file name)))
|
|
1424 | + (call-stat "os_stat" c-call:c-string (%name->file name)))
|
|
1425 | 1425 | |
1426 | 1426 | (defun unix-lstat (name)
|
1427 | 1427 | "Unix-lstat is similar to unix-stat except the specified
|
... | ... | @@ -1443,7 +1443,7 @@ |
1443 | 1443 | st_blocks Number of blocks allocated. (Block size is implementation dependent.)
|
1444 | 1444 | "
|
1445 | 1445 | (declare (type unix-pathname name))
|
1446 | - (call-stat "unix_lstat" c-call:c-string (%name->file name)))
|
|
1446 | + (call-stat "os_lstat" c-call:c-string (%name->file name)))
|
|
1447 | 1447 | |
1448 | 1448 | (defun unix-fstat (fd)
|
1449 | 1449 | _N"Unix-fstat is similar to unix-stat except the file is specified
|
... | ... | @@ -1465,7 +1465,7 @@ |
1465 | 1465 | st_blocks Number of blocks allocated. (Block size is implementation dependent.)
|
1466 | 1466 | "
|
1467 | 1467 | (declare (type unix-fd fd))
|
1468 | - (call-stat "unix_fstat" int fd)))
|
|
1468 | + (call-stat "os_fstat" int fd)))
|
|
1469 | 1469 | |
1470 | 1470 | (def-alien-type nil
|
1471 | 1471 | (struct rusage
|
... | ... | @@ -5,12 +5,6 @@ |
5 | 5 | |
6 | 6 | */
|
7 | 7 | |
8 | -#ifdef __linux__
|
|
9 | -/* Needed to get 64-bit objects for stat and friends on Linux. */
|
|
10 | -#define _LARGEFILE_SOURCE
|
|
11 | -#define _FILE_OFFSET_BITS 64
|
|
12 | -#endif
|
|
13 | - |
|
14 | 8 | #include <errno.h>
|
15 | 9 | #include <math.h>
|
16 | 10 | #include <netdb.h>
|
... | ... | @@ -606,17 +600,21 @@ os_sleep(double seconds) |
606 | 600 | * function that works across all OSes.
|
607 | 601 | */
|
608 | 602 | int
|
609 | -unix_stat(const char* path, u_int64_t *dev, u_int64_t *ino, unsigned int *mode, u_int64_t *nlink,
|
|
610 | - unsigned int *uid, unsigned int *gid, u_int64_t *rdev, int64_t *size,
|
|
611 | - int64_t *atime, int64_t *mtime, int64_t *ctime,
|
|
612 | - long *blksize, int64_t *blocks)
|
|
603 | +os_stat(const char* path, u_int64_t *dev, u_int64_t *ino, unsigned int *mode, u_int64_t *nlink,
|
|
604 | + unsigned int *uid, unsigned int *gid, u_int64_t *rdev, int64_t *size,
|
|
605 | + int64_t *atime, int64_t *mtime, int64_t *ctime,
|
|
606 | + long *blksize, int64_t *blocks)
|
|
613 | 607 | {
|
614 | 608 | int rc;
|
615 | 609 | struct stat buf;
|
616 | 610 | |
617 | 611 | rc = stat(path, &buf);
|
618 | 612 | |
619 | -#if 0
|
|
613 | + if (rc != 0) {
|
|
614 | + return rc;
|
|
615 | + }
|
|
616 | +
|
|
617 | +#if 1
|
|
620 | 618 | /*
|
621 | 619 | * Useful prints to see the actual size of the various
|
622 | 620 | * 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, |
655 | 653 | }
|
656 | 654 | |
657 | 655 | int
|
658 | -unix_fstat(int fd, u_int64_t *dev, u_int64_t *ino, unsigned int *mode, u_int64_t *nlink,
|
|
659 | - unsigned int *uid, unsigned int *gid, u_int64_t *rdev, int64_t *size,
|
|
660 | - int64_t *atime, int64_t *mtime, int64_t *ctime,
|
|
661 | - long *blksize, int64_t *blocks)
|
|
656 | +os_fstat(int fd, u_int64_t *dev, u_int64_t *ino, unsigned int *mode, u_int64_t *nlink,
|
|
657 | + unsigned int *uid, unsigned int *gid, u_int64_t *rdev, int64_t *size,
|
|
658 | + int64_t *atime, int64_t *mtime, int64_t *ctime,
|
|
659 | + long *blksize, int64_t *blocks)
|
|
662 | 660 | {
|
663 | 661 | int rc;
|
664 | 662 | struct stat buf;
|
665 | 663 | |
666 | 664 | rc = fstat(fd, &buf);
|
667 | 665 | |
666 | + if (rc != 0) {
|
|
667 | + return rc;
|
|
668 | + }
|
|
669 | + |
|
668 | 670 | *dev = buf.st_dev;
|
669 | 671 | *ino = buf.st_ino;
|
670 | 672 | *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 |
683 | 685 | }
|
684 | 686 | |
685 | 687 | int
|
686 | -unix_lstat(const char* path, u_int64_t *dev, u_int64_t *ino, unsigned int *mode, u_int64_t *nlink,
|
|
687 | - unsigned int *uid, unsigned int *gid, u_int64_t *rdev, int64_t *size,
|
|
688 | - int64_t *atime, int64_t *mtime, int64_t *ctime,
|
|
689 | - long *blksize, int64_t *blocks)
|
|
688 | +os_lstat(const char* path, u_int64_t *dev, u_int64_t *ino, unsigned int *mode, u_int64_t *nlink,
|
|
689 | + unsigned int *uid, unsigned int *gid, u_int64_t *rdev, int64_t *size,
|
|
690 | + int64_t *atime, int64_t *mtime, int64_t *ctime,
|
|
691 | + long *blksize, int64_t *blocks)
|
|
690 | 692 | {
|
691 | 693 | int rc;
|
692 | 694 | struct stat buf;
|
693 | 695 | |
694 | 696 | rc = lstat(path, &buf);
|
695 | 697 | |
698 | + if (rc != 0) {
|
|
699 | + return rc;
|
|
700 | + }
|
|
701 | + |
|
696 | 702 | *dev = buf.st_dev;
|
697 | 703 | *ino = buf.st_ino;
|
698 | 704 | *mode = buf.st_mode;
|