diff options
| author | Ivan Molodetskikh <yalterz@gmail.com> | 2023-10-24 19:22:02 +0400 |
|---|---|---|
| committer | Ivan Molodetskikh <yalterz@gmail.com> | 2023-10-24 19:22:02 +0400 |
| commit | 64ac31668dfd89c9e700d683d8f4c1aae1728703 (patch) | |
| tree | e92cf39a9dd7aec0e353107d330be06f853985eb /src/utils.rs | |
| parent | 909a45db6f7a9ec04e9b45c086a499e5d6f38eb9 (diff) | |
| download | niri-64ac31668dfd89c9e700d683d8f4c1aae1728703.tar.gz niri-64ac31668dfd89c9e700d683d8f4c1aae1728703.tar.bz2 niri-64ac31668dfd89c9e700d683d8f4c1aae1728703.zip | |
Remove time crate in favor of manual impl
Cuts down a few more dependencies.
Diffstat (limited to 'src/utils.rs')
| -rw-r--r-- | src/utils.rs | 32 |
1 files changed, 22 insertions, 10 deletions
diff --git a/src/utils.rs b/src/utils.rs index 80f5a0a1..134112dc 100644 --- a/src/utils.rs +++ b/src/utils.rs @@ -1,15 +1,16 @@ use std::ffi::OsStr; use std::io::{self, Write}; +use std::os::unix::prelude::OsStrExt; use std::os::unix::process::CommandExt; use std::path::PathBuf; use std::process::{Command, Stdio}; +use std::ptr::null_mut; use std::time::Duration; -use anyhow::Context; +use anyhow::{ensure, Context}; use directories::UserDirs; use smithay::reexports::rustix::time::{clock_gettime, ClockId}; use smithay::utils::{Logical, Point, Rectangle}; -use time::OffsetDateTime; pub fn get_monotonic_time() -> Duration { let ts = clock_gettime(ClockId::Monotonic); @@ -29,16 +30,27 @@ pub fn make_screenshot_path() -> anyhow::Result<PathBuf> { }); path.push("Screenshots"); + let mut buf = [0u8; 256]; + let name; unsafe { - // are you kidding me - time::util::local_offset::set_soundness(time::util::local_offset::Soundness::Unsound); - }; + let time = libc::time(null_mut()); + ensure!(time != -1, "error in time()"); + + let tm = libc::localtime(&time); + ensure!(!tm.is_null(), "error in localtime()"); + + let format = b"Screenshot from %Y-%m-%d %H-%M-%S.png\0"; + let rv = libc::strftime( + buf.as_mut_ptr().cast(), + buf.len(), + format.as_ptr().cast(), + tm, + ); + ensure!(rv != 0, "error formatting time"); + + name = OsStr::from_bytes(&buf[..rv]); + } - let now = OffsetDateTime::now_local().unwrap_or_else(|_| OffsetDateTime::now_utc()); - let desc = time::macros::format_description!( - "Screenshot from [year]-[month]-[day] [hour]-[minute]-[second].png" - ); - let name = now.format(desc).context("error formatting time")?; path.push(name); Ok(path) |
