File: misc.c

package info (click to toggle)
lcrq 0.3.1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 52,868 kB
  • sloc: ansic: 11,513; sh: 3,130; makefile: 338
file content (29 lines) | stat: -rw-r--r-- 599 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
/* SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only */
/* Copyright (c) 2020-2022 Brett Sheffield <bacs@librecast.net> */

#include <stdarg.h>
#include <stdio.h>
#include "misc.h"

/* Public Domain, credit to Sean Anderson from
 * https://graphics.stanford.edu/~seander/bithacks.html#RoundUpPowerOf2 */
uint32_t next_pow2(uint32_t v)
{
	v--;
	v |= v >> 1;
	v |= v >> 2;
	v |= v >> 4;
	v |= v >> 8;
	v |= v >> 16;
	return ++v;
}

int _vscprintf (const char * format, va_list argp)
{
	int r;
	va_list argc;
	va_copy(argc, argp);
	r = vsnprintf(NULL, 0, format, argc);
	va_end(argc);
	return r;
}