diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/fileio.c | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/src/fileio.c b/src/fileio.c index adb3534532c..11370279d1b 100644 --- a/src/fileio.c +++ b/src/fileio.c | |||
| @@ -96,6 +96,7 @@ along with GNU Emacs. If not, see <https://www.gnu.org/licenses/>. */ | |||
| 96 | #include <acl.h> | 96 | #include <acl.h> |
| 97 | #include <allocator.h> | 97 | #include <allocator.h> |
| 98 | #include <careadlinkat.h> | 98 | #include <careadlinkat.h> |
| 99 | #include <fsusage.h> | ||
| 99 | #include <stat-time.h> | 100 | #include <stat-time.h> |
| 100 | #include <tempname.h> | 101 | #include <tempname.h> |
| 101 | 102 | ||
| @@ -5765,6 +5766,40 @@ effect except for flushing STREAM's data. */) | |||
| 5765 | return (set_binary_mode (fileno (fp), binmode) == O_BINARY) ? Qt : Qnil; | 5766 | return (set_binary_mode (fileno (fp), binmode) == O_BINARY) ? Qt : Qnil; |
| 5766 | } | 5767 | } |
| 5767 | 5768 | ||
| 5769 | #ifndef DOS_NT | ||
| 5770 | |||
| 5771 | /* Yield a Lisp float as close as possible to BLOCKSIZE * BLOCKS, with | ||
| 5772 | the result negated if NEGATE. */ | ||
| 5773 | static Lisp_Object | ||
| 5774 | blocks_to_bytes (uintmax_t blocksize, uintmax_t blocks, bool negate) | ||
| 5775 | { | ||
| 5776 | /* On typical platforms the following code is accurate to 53 bits, | ||
| 5777 | which is close enough. BLOCKSIZE is invariably a power of 2, so | ||
| 5778 | converting it to double does not lose information. */ | ||
| 5779 | double bs = blocksize; | ||
| 5780 | return make_float (negate ? -bs * -blocks : bs * blocks); | ||
| 5781 | } | ||
| 5782 | |||
| 5783 | DEFUN ("file-system-info", Ffile_system_info, Sfile_system_info, 1, 1, 0, | ||
| 5784 | doc: /* Return storage information about the file system FILENAME is on. | ||
| 5785 | Value is a list of numbers (TOTAL FREE AVAIL), where TOTAL is the total | ||
| 5786 | storage of the file system, FREE is the free storage, and AVAIL is the | ||
| 5787 | storage available to a non-superuser. All 3 numbers are in bytes. | ||
| 5788 | If the underlying system call fails, value is nil. */) | ||
| 5789 | (Lisp_Object filename) | ||
| 5790 | { | ||
| 5791 | Lisp_Object encoded = ENCODE_FILE (Fexpand_file_name (filename, Qnil)); | ||
| 5792 | struct fs_usage u; | ||
| 5793 | if (get_fs_usage (SSDATA (encoded), NULL, &u) != 0) | ||
| 5794 | return Qnil; | ||
| 5795 | return list3 (blocks_to_bytes (u.fsu_blocksize, u.fsu_blocks, false), | ||
| 5796 | blocks_to_bytes (u.fsu_blocksize, u.fsu_bfree, false), | ||
| 5797 | blocks_to_bytes (u.fsu_blocksize, u.fsu_bavail, | ||
| 5798 | u.fsu_bavail_top_bit_set)); | ||
| 5799 | } | ||
| 5800 | |||
| 5801 | #endif /* !DOS_NT */ | ||
| 5802 | |||
| 5768 | void | 5803 | void |
| 5769 | init_fileio (void) | 5804 | init_fileio (void) |
| 5770 | { | 5805 | { |
| @@ -6115,6 +6150,10 @@ This includes interactive calls to `delete-file' and | |||
| 6115 | 6150 | ||
| 6116 | defsubr (&Sset_binary_mode); | 6151 | defsubr (&Sset_binary_mode); |
| 6117 | 6152 | ||
| 6153 | #ifndef DOS_NT | ||
| 6154 | defsubr (&Sfile_system_info); | ||
| 6155 | #endif | ||
| 6156 | |||
| 6118 | #ifdef HAVE_SYNC | 6157 | #ifdef HAVE_SYNC |
| 6119 | defsubr (&Sunix_sync); | 6158 | defsubr (&Sunix_sync); |
| 6120 | #endif | 6159 | #endif |