RustForge

foundry

Foundry OS: the operating system built on the Rustbelt kernel

foundry / rust / coreutils-rs / src / bin / touch.rs
576 bytes ยท raw
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
//! touch file... -- create empty files (existing files are left alone;
//! there are no timestamps to update yet).
#![no_std]
#![no_main]

#[macro_use]
#[path = "../../../rbrt/ulib.rs"]
mod ulib;

use ulib::*;

fn main() -> i64 {
    let mut status = 0;
    for i in 1..argc() {
        let path = arg(i).unwrap_or("");
        let fd = open(path, O_WRONLY | O_CREAT); // no O_TRUNC: keep the contents
        if fd < 0 {
            eprintln!("touch: {}: {}", path, strerror(fd));
            status = 1;
        } else {
            close(fd);
        }
    }
    status
}