xref: /openbsd/lib/libsndio/debug.c (revision 91f110e0)
1 /*	$OpenBSD: debug.c,v 1.3 2013/11/13 22:38:22 ratchov Exp $	*/
2 /*
3  * Copyright (c) 2011 Alexandre Ratchov <alex@caoua.org>
4  *
5  * Permission to use, copy, modify, and distribute this software for any
6  * purpose with or without fee is hereby granted, provided that the above
7  * copyright notice and this permission notice appear in all copies.
8  *
9  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
16  */
17 
18 #include <stdio.h>
19 #include <stdlib.h>
20 #include <unistd.h>
21 
22 #include "debug.h"
23 
24 #ifdef DEBUG
25 /*
26  * debug level, -1 means uninitialized
27  */
28 int _sndio_debug = -1;
29 
30 void
31 _sndio_debug_init(void)
32 {
33 	char *dbg;
34 
35 	if (_sndio_debug < 0) {
36 		dbg = issetugid() ? NULL : getenv("SNDIO_DEBUG");
37 		if (!dbg || sscanf(dbg, "%u", &_sndio_debug) != 1)
38 			_sndio_debug = 0;
39 	}
40 }
41 #endif
42 
43 const char *
44 _sndio_parsetype(const char *str, char *type)
45 {
46 	while (*type) {
47 		if (*type != *str)
48 			return NULL;
49 		type++;
50 		str++;
51 	}
52 	if (*str >= 'a' && *str <= 'z')
53 		return NULL;
54 	return str;
55 }
56