File: compat.c

package info (click to toggle)
moc 1%3A2.6.0~svn-r3005-1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 2,656 kB
  • sloc: ansic: 31,749; sh: 929; cpp: 487; makefile: 240
file content (55 lines) | stat: -rw-r--r-- 1,221 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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
/*
 * MOC - music on console
 * Copyright (C) 2005 Damian Pietras <daper@daper.net>
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 */

#ifdef HAVE_CONFIG_H
# include "config.h"
#endif

/* Various functions which some systems lack. */

#ifndef HAVE_STRCASESTR
#include <string.h>
#include <ctype.h>

/* Case insensitive version of strstr(). */
char *strcasestr (const char *haystack, const char *needle)
{
	char *haystack_i, *needle_i;
	char *c;
	char *res;

	haystack_i = xstrdup (haystack);
	needle_i = xstrdup (needle);

	c = haystack_i;
	while (*c) {
		*c = tolower (*c);
		c++;
	}

	c = needle_i;
	while (*c) {
		*c = tolower (*c);
		c++;
	}

	res = strstr (haystack_i, needle_i);
	free (haystack_i);
	free (needle_i);
	return res ? res - haystack_i + (char *)haystack : NULL;
}
#endif

/* This is required to prevent an "empty translation unit" warning
   if neither strcasestr() nor clock_gettime() get defined. */
#if defined(HAVE_STRCASESTR) && defined(HAVE_CLOCK_GETTIME)
int compat_is_empty;
#endif