1/* 2 * Copyright (c) 2015,2016, ETH Zuerich. 3 * All rights reserved. 4 * 5 * This file is distributed under the terms in the attached LICENSE file. 6 * If you do not find this file, copies can be found by writing to: 7 * ETH Zurich D-INFK, Haldeneggsteig 4, CH-8092 Zurich. Attn: Systems Group. 8 */ 9 10#ifndef __UTIL_H 11#define __UTIL_H 12 13#include <string.h> 14 15#define COVER(x, y) (((x) + ((y)-1)) / (y)) 16#define ROUNDUP(x, y) (COVER(x,y) * (y)) 17#define PAGE_4k (1<<12) 18#define roundpage(x) COVER((x), PAGE_4k) 19 20/* Copy a base+length string into a null-terminated string. Destination 21 * buffer must be large enough to hold the terminator i.e. n+1 characters. */ 22static inline void 23ntstring(char *dest, const char *src, size_t len) { 24 memcpy(dest, src, len); 25 dest[len]= '\0'; 26} 27 28#endif /* __UTIL_H */ 29