ubase

suckless linux base utils
git clone git://git.2f30.org/ubase
Log | Files | Refs | README | LICENSE

commit 97975ff092c1d7e4fc2d8dfec69641a236925d6e
parent 0476f601b201aca990b7f8eff7d710015d083b38
Author: sin <sin@2f30.org>
Date:   Tue, 29 Oct 2013 15:36:18 +0000

Add pagesize(1)

This program is useful in constructing portable shell scripts.

Diffstat:
MMakefile | 1+
Apagesize.c | 31+++++++++++++++++++++++++++++++
2 files changed, 32 insertions(+), 0 deletions(-)

diff --git a/Makefile b/Makefile @@ -32,6 +32,7 @@ SRC = \ mkswap.c \ mount.c \ mountpoint.c \ + pagesize.c \ pidof.c \ pivot_root.c \ ps.c \ diff --git a/pagesize.c b/pagesize.c @@ -0,0 +1,31 @@ +/* See LICENSE file for copyright and license details. */ +#include <unistd.h> +#include <stdio.h> +#include <stdlib.h> +#include "util.h" + +static void +usage(void) +{ + eprintf("usage: %s\n", argv0); +} + +int +main(int argc, char *argv[]) +{ + long pagesz; + + ARGBEGIN { + default: + usage(); + } ARGEND; + + pagesz = sysconf(_SC_PAGESIZE); + if (pagesz < 0) { + pagesz = sysconf(_SC_PAGE_SIZE); + if (pagesz < 0) + enprintf(EXIT_FAILURE, "can't determine pagesize\n"); + } + printf("%ld\n", pagesz); + return EXIT_SUCCESS; +}