randpup.git

util.h

espurr
/* randpup - ngram text generator kernel module
 * Copyright (C) 2025 ArcNyxx
 * see LICENCE.MIT file for licensing information */

#ifndef PUP_UTIL_H
#define PUP_UTIL_H

#ifndef __KERNEL__
#define MAX(a, b) (a) > (b) ? (a) : (b)
#define MIN(a, b) (a) > (b) ? (b) : (a)
#endif /* __KERNEL__ */

#ifdef __KERNEL__
#include <asm-generic/errno.h>
#include <linux/uaccess.h>
#define CS(dest, src, len) if (copy_to_user(dest, src, len) != 0) \
	return -EFAULT;
#define CC(dest, ch) if (put_user(ch, dest) != 0) \
	return -EFAULT;
#else /* __KERNEL__ */
#include <string.h>
#define CS(dest, src, len) memcpy(dest, src, len)
#define CC(dest, ch) *(dest) = ch
#endif /* __KERNEL__ */

int pup_rand(int lower, int upper);

#endif /* PUP_UTIL_H */