//  functions.hh for bbsmount - an tool for simple mounting in X11
//
//  Copyright (c) 2001-2002 by Miroslav Jezbera, jezberam@phoenix.inf.upol.cz
//
//  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.
//
//  This program is distributed in the hope that it will be useful,
//  but WITHOUT ANY WARRANTY; without even the implied warranty of
//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
//  GNU General Public License for more details.
//
//  You should have received a copy of the GNU General Public License
//  along with this program; if not, write to the Free Software
//  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
//
// (See the included file COPYING / GPL-2.0)
//

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

#include <stdlib.h>
#include <string.h>
#include <ctype.h>

#include "functions.hh"

#ifndef HAVE_STRDUP
char *
strdup(const char *src)
{
    size_t src_len;
    char *result;

    src_len = strlen(src);
    result = (char *)malloc(sizeof(char) * src_len + 1);
    memcpy((void *)result, src, src_len + 1);
    return result;
}
#endif /* !HAVE_STRDUP */

#ifndef HAVE_STRNCASECMP
int
strncasecmp(const char *str1, const char *str2, size_t n)
{
    size_t str1_len, str2_len, max_len;
    int counter;

    str1_len = strlen(str1);
    str2_len = strlen(str2);
    max_len = (str1_len > str2_len ? str2_len : str1_len);
    for (counter = 0; counter < (int)n; counter++)
	if (counter >= (int)max_len) {
	    return (str1_len < str2_len ? 1 : -1);
	}
	else {
	    if (toupper(str1[counter]) != toupper(str2[counter]))
		return (str1[counter] < str2[counter] ? 1 : -1);
	}
    return 0;
}
#endif /* !HAVE_STRNCASECMP */

#ifndef HAVE_MEMSET
#   ifdef HAVE_BZERO
#	define memset(s,c,n)	bzero(s,n)
#   else /* !HAVE_BZERO */
#	error "memset or bzero function is not present!"
#   endif /* !HAVE_BZERO */
#endif /* !HAVE_MEMSET */


syntax highlighted by Code2HTML, v. 0.9.1