memsys.c (760B)
- // Collection of Unix tools, comparable to coreutils
- // SPDX-FileCopyrightText: 2017-2022 Haelwenn (lanodan) Monnier <contact+utils@hacktivis.me>
- // SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only
- #define _POSIX_C_SOURCE 200809L
- #include <fcntl.h> /* open() */
- #include <stdio.h> /* perror() */
- #include <unistd.h> /* close(), write() */
- #define SYS_POWER_STATE "/sys/power/state"
- int
- main(void)
- {
- int fd, err = 0;
- char *entry = "mem";
- size_t entry_size = 3;
- fd = open(SYS_POWER_STATE, O_WRONLY);
- if(fd == -1)
- {
- perror("memsys: open(\"" SYS_POWER_STATE "\")");
- err++;
- }
- else
- {
- if(write(fd, entry, entry_size) < (ssize_t)entry_size)
- {
- perror("memsys: write(fd, \"mem\", 3)");
- err++;
- }
- close(fd);
- }
- return err;
- }