1 /*****************************************************************************
2 * libc.c: Extra libc function for some systems.
3 *****************************************************************************
4 * Copyright (C) 2002 VideoLAN
5 * $Id: libc.c,v 1.1 2002/11/10 23:41:53 sam Exp $
7 * Authors: Jon Lech Johansen <jon-vl@nanocrew.net>
8 * Samuel Hocevar <sam@zoy.org>
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA.
23 *****************************************************************************/
24 #include <string.h> /* strdup() */
29 /*****************************************************************************
30 * getenv: just in case, but it should never be called
31 *****************************************************************************/
33 char *getenv( const char *name )
39 /*****************************************************************************
40 * strdup: returns a malloc'd copy of a string
41 *****************************************************************************/
43 char *strdup( const char *string )
45 return strndup( string, strlen( string ) );
49 /*****************************************************************************
50 * strndup: returns a malloc'd copy of at most n bytes of string
51 * Does anyone know whether or not it will be present in Jaguar?
52 *****************************************************************************/
54 char *strndup( const char *string, size_t n )
57 size_t len = strlen( string );
59 len = __MIN( len, n );
60 psz = (char*)malloc( len + 1 );
64 memcpy( (void*)psz, (const void*)string, len );
72 /*****************************************************************************
73 * strcasecmp: compare two strings ignoring case
74 *****************************************************************************/
75 #if !defined( HAVE_STRCASECMP ) && !defined( HAVE_STRICMP )
76 int strcasecmp( const char *s1, const char *s2 )
80 while( !i_delta && *s1 && *s2 )
84 if( *s1 >= 'A' && *s1 <= 'Z' )
89 if( *s2 >= 'A' && *s2 <= 'Z' )
99 /*****************************************************************************
100 * strncasecmp: compare n chars from two strings ignoring case
101 *****************************************************************************/
102 #if !defined( HAVE_STRNCASECMP ) && !defined( HAVE_STRNICMP )
103 int strncasecmp( const char *s1, const char *s2, size_t n )
107 while( n-- && !i_delta && *s1 )
111 if( *s1 >= 'A' && *s1 <= 'Z' )
113 i_delta -= 'A' - 'a';
116 if( *s2 >= 'A' && *s2 <= 'Z' )
118 i_delta += 'A' - 'a';
126 /*****************************************************************************
127 * atof: convert a string to a double.
128 *****************************************************************************/
130 double atof( const char *nptr )
134 int i_len = strlen( nptr ) + 1;
136 psz_tmp = malloc( i_len * sizeof(wchar_t) );
137 MultiByteToWideChar( CP_ACP, 0, nptr, -1, psz_tmp, i_len );
138 f_result = wcstod( psz_tmp, NULL );
145 /*****************************************************************************
146 * lseek: reposition read/write file offset.
147 *****************************************************************************
148 * FIXME: this cast sucks!
149 *****************************************************************************/
150 #if !defined( HAVE_LSEEK )
151 off_t lseek( int fildes, off_t offset, int whence )
153 return SetFilePointer( (HANDLE)fildes, offset, NULL, whence );