logo

utils

~/.local/bin tools and git-hooks
commit: ac87ab150f2422b2a5a7ad006690018fddaea576
parent: e130be699a76758f5642efc2659bb6e0c7ebc099
Author: Haelwenn (lanodan) Monnier <contact@hacktivis.me>
Date:   Wed,  6 May 2020 08:29:55 +0200

sbin/memsys: New

Diffstat:

MMakefile3+++
Asbin/Makefile9+++++++++
Asbin/Makefile.config1+
Asbin/memsys.c27+++++++++++++++++++++++++++
4 files changed, 40 insertions(+), 0 deletions(-)

diff --git a/Makefile b/Makefile @@ -1,8 +1,11 @@ all: cd bin ; $(MAKE) + cd sbin ; $(MAKE) clean: cd bin ; $(MAKE) clean + cd sbin ; $(MAKE) clean install: cd bin ; $(MAKE) install + cd sbin ; $(MAKE) install diff --git a/sbin/Makefile b/sbin/Makefile @@ -0,0 +1,9 @@ +# POSIX-ish Makefile with extensions common to *BSD and GNU such as: +# - Usage of backticks for shell evaluation +# - Usage of ?= for defining variables when not already defined +# - Usage of += for appending to a variable + +include Makefile.config +include ../Makefile.common + +BINDIR = $(PREFIX)/sbin diff --git a/sbin/Makefile.config b/sbin/Makefile.config @@ -0,0 +1 @@ +EXE = memsys diff --git a/sbin/memsys.c b/sbin/memsys.c @@ -0,0 +1,27 @@ +// Copyright 2020 Haelwenn (lanodan) Monnier <contact@hacktivis.me> +// Distributed under the terms of the CC-BY-4.0 license + +#define _POSIX_C_SOURCE 200809L +#include <fcntl.h> /* open() */ +#include <unistd.h> /* close(), write() */ +#include <stdio.h> /* perror() */ + +#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 { + write(fd, &entry, entry_size); + close(fd); + } + + return 0; +}