mirror of
https://github.com/reactos/reactos.git
synced 2025-08-06 15:53:03 +00:00
Create a branch for cmake bringup.
svn path=/branches/cmake-bringup/; revision=48236
This commit is contained in:
parent
a28e798006
commit
c424146e2c
20602 changed files with 0 additions and 1140137 deletions
55
lib/sdk/crt/stdlib/_exit.c
Normal file
55
lib/sdk/crt/stdlib/_exit.c
Normal file
|
@ -0,0 +1,55 @@
|
|||
#include <precomp.h>
|
||||
#include <internal/atexit.h>
|
||||
|
||||
extern void _atexit_cleanup(void);
|
||||
|
||||
struct __atexit *__atexit_ptr = 0;
|
||||
|
||||
/*
|
||||
* @implemented
|
||||
*/
|
||||
void exit(int status)
|
||||
{
|
||||
//int i;
|
||||
|
||||
/*
|
||||
if (__stdio_cleanup_hook)
|
||||
__stdio_cleanup_hook();
|
||||
for (i=0; i<djgpp_last_dtor-djgpp_first_dtor; i++)
|
||||
djgpp_first_dtor[i]();
|
||||
*/
|
||||
/* in case the program set it this way */
|
||||
_setmode(0, _O_TEXT);
|
||||
_atexit_cleanup();
|
||||
_exit(status);
|
||||
for(;;);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* @implemented
|
||||
*/
|
||||
void _exit(int _status)
|
||||
{
|
||||
// FIXME: _exit and _c_exit should prevent atexit routines from being called during DLL unload
|
||||
ExitProcess(_status);
|
||||
for(;;);
|
||||
}
|
||||
|
||||
/*
|
||||
* @unimplemented
|
||||
*/
|
||||
void _cexit( void )
|
||||
{
|
||||
_atexit_cleanup();
|
||||
// flush
|
||||
}
|
||||
|
||||
/*
|
||||
* @unimplemented
|
||||
*/
|
||||
void _c_exit( void )
|
||||
{
|
||||
// FIXME: _exit and _c_exit should prevent atexit routines from being called during DLL unload
|
||||
// reset interup vectors
|
||||
}
|
27
lib/sdk/crt/stdlib/abort.c
Normal file
27
lib/sdk/crt/stdlib/abort.c
Normal file
|
@ -0,0 +1,27 @@
|
|||
/*
|
||||
* COPYRIGHT: See COPYING in the top level directory
|
||||
* PROJECT: ReactOS system libraries
|
||||
* FILE: lib/crt/??????
|
||||
* PURPOSE: Unknown
|
||||
* PROGRAMER: Unknown
|
||||
* UPDATE HISTORY:
|
||||
* 25/11/05: Added license header
|
||||
*/
|
||||
|
||||
#include <precomp.h>
|
||||
#include <signal.h>
|
||||
|
||||
char *msg ="Abort\n\r";
|
||||
|
||||
/*
|
||||
* @implemented
|
||||
*/
|
||||
void abort()
|
||||
{
|
||||
fflush(NULL);
|
||||
_fcloseall();
|
||||
raise(SIGABRT);
|
||||
_write(stderr->_file, msg, sizeof(msg)-1);
|
||||
exit(3);
|
||||
}
|
||||
|
69
lib/sdk/crt/stdlib/atexit.c
Normal file
69
lib/sdk/crt/stdlib/atexit.c
Normal file
|
@ -0,0 +1,69 @@
|
|||
/* Copyright (C) 1994 DJ Delorie, see COPYING.DJ for details */
|
||||
#include <precomp.h>
|
||||
|
||||
void _atexit_cleanup(void)
|
||||
{
|
||||
struct __atexit *next, *a = __atexit_ptr;
|
||||
__atexit_ptr = 0; /* to prevent infinite loops */
|
||||
while (a)
|
||||
{
|
||||
(a->__function)();
|
||||
next = a->__next;
|
||||
free(a);
|
||||
a = next;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* @implemented
|
||||
*
|
||||
* Ported from WINE
|
||||
* Copyright (C) 2000 Jon Griffiths
|
||||
*/
|
||||
_onexit_t __dllonexit(_onexit_t func, _onexit_t **start, _onexit_t **end)
|
||||
{
|
||||
_onexit_t *tmp;
|
||||
int len;
|
||||
|
||||
if (!start || !*start || !end || !*end)
|
||||
return NULL;
|
||||
|
||||
len = (*end - *start);
|
||||
if (++len <= 0)
|
||||
return NULL;
|
||||
|
||||
tmp = (_onexit_t *)realloc(*start, len * sizeof(tmp));
|
||||
if (!tmp)
|
||||
return NULL;
|
||||
|
||||
*start = tmp;
|
||||
*end = tmp + len;
|
||||
tmp[len - 1] = func;
|
||||
|
||||
return func;
|
||||
}
|
||||
|
||||
/*
|
||||
* @implemented
|
||||
*/
|
||||
_onexit_t _onexit(_onexit_t a)
|
||||
{
|
||||
struct __atexit *ap;
|
||||
if (a == 0)
|
||||
return NULL;
|
||||
ap = (struct __atexit *)malloc(sizeof(struct __atexit));
|
||||
if (!ap)
|
||||
return NULL;
|
||||
ap->__next = __atexit_ptr;
|
||||
ap->__function = (void (*)(void))a;
|
||||
__atexit_ptr = ap;
|
||||
return a;
|
||||
}
|
||||
|
||||
/*
|
||||
* @implemented
|
||||
*/
|
||||
int atexit(void (*a)(void))
|
||||
{
|
||||
return _onexit((_onexit_t)a) == (_onexit_t)a ? 0 : -1;
|
||||
}
|
8
lib/sdk/crt/stdlib/atold.c
Normal file
8
lib/sdk/crt/stdlib/atold.c
Normal file
|
@ -0,0 +1,8 @@
|
|||
/* Copyright (C) 1994 DJ Delorie, see COPYING.DJ for details */
|
||||
#include <stdlib.h>
|
||||
|
||||
long double
|
||||
_atold(const char *ascii)
|
||||
{
|
||||
return _strtold(ascii, 0);
|
||||
}
|
82
lib/sdk/crt/stdlib/doserrmap.h
Normal file
82
lib/sdk/crt/stdlib/doserrmap.h
Normal file
|
@ -0,0 +1,82 @@
|
|||
/* doserrmap.h: auto-generated from winerror.h and errno.h using undoc'd _dosmaperr. */
|
||||
|
||||
#ifndef doserrmap_h
|
||||
#define doserrmap_h
|
||||
|
||||
struct {
|
||||
unsigned long winerr;
|
||||
int en;
|
||||
} doserrmap[] = {
|
||||
{ ERROR_FILE_NOT_FOUND, ENOENT },
|
||||
{ ERROR_PATH_NOT_FOUND, ENOENT },
|
||||
{ ERROR_TOO_MANY_OPEN_FILES, EMFILE },
|
||||
{ ERROR_ACCESS_DENIED, EACCES },
|
||||
{ ERROR_INVALID_HANDLE, EBADF },
|
||||
{ ERROR_ARENA_TRASHED, ENOMEM },
|
||||
{ ERROR_NOT_ENOUGH_MEMORY, ENOMEM },
|
||||
{ ERROR_INVALID_BLOCK, ENOMEM },
|
||||
{ ERROR_BAD_ENVIRONMENT, E2BIG },
|
||||
{ ERROR_BAD_FORMAT, ENOEXEC },
|
||||
{ ERROR_INVALID_DRIVE, ENOENT },
|
||||
{ ERROR_CURRENT_DIRECTORY, EACCES },
|
||||
{ ERROR_NOT_SAME_DEVICE, EXDEV },
|
||||
{ ERROR_NO_MORE_FILES, ENOENT },
|
||||
{ ERROR_WRITE_PROTECT, EACCES },
|
||||
{ ERROR_BAD_UNIT, EACCES },
|
||||
{ ERROR_NOT_READY, EACCES },
|
||||
{ ERROR_BAD_COMMAND, EACCES },
|
||||
{ ERROR_CRC, EACCES },
|
||||
{ ERROR_BAD_LENGTH, EACCES },
|
||||
{ ERROR_SEEK, EACCES },
|
||||
{ ERROR_NOT_DOS_DISK, EACCES },
|
||||
{ ERROR_SECTOR_NOT_FOUND, EACCES },
|
||||
{ ERROR_OUT_OF_PAPER, EACCES },
|
||||
{ ERROR_WRITE_FAULT, EACCES },
|
||||
{ ERROR_READ_FAULT, EACCES },
|
||||
{ ERROR_GEN_FAILURE, EACCES },
|
||||
{ ERROR_SHARING_VIOLATION, EACCES },
|
||||
{ ERROR_LOCK_VIOLATION, EACCES },
|
||||
{ ERROR_WRONG_DISK, EACCES },
|
||||
{ ERROR_SHARING_BUFFER_EXCEEDED, EACCES },
|
||||
{ ERROR_BAD_NETPATH, ENOENT },
|
||||
{ ERROR_NETWORK_ACCESS_DENIED, EACCES },
|
||||
{ ERROR_BAD_NET_NAME, ENOENT },
|
||||
{ ERROR_FILE_EXISTS, EEXIST },
|
||||
{ ERROR_CANNOT_MAKE, EACCES },
|
||||
{ ERROR_FAIL_I24, EACCES },
|
||||
{ ERROR_NO_PROC_SLOTS, EAGAIN },
|
||||
{ ERROR_DRIVE_LOCKED, EACCES },
|
||||
{ ERROR_BROKEN_PIPE, EPIPE },
|
||||
{ ERROR_DISK_FULL, ENOSPC },
|
||||
{ ERROR_INVALID_TARGET_HANDLE, EBADF },
|
||||
{ ERROR_WAIT_NO_CHILDREN, ECHILD },
|
||||
{ ERROR_CHILD_NOT_COMPLETE, ECHILD },
|
||||
{ ERROR_DIRECT_ACCESS_HANDLE, EBADF },
|
||||
{ ERROR_SEEK_ON_DEVICE, EACCES },
|
||||
{ ERROR_DIR_NOT_EMPTY, ENOTEMPTY },
|
||||
{ ERROR_NOT_LOCKED, EACCES },
|
||||
{ ERROR_BAD_PATHNAME, ENOENT },
|
||||
{ ERROR_MAX_THRDS_REACHED, EAGAIN },
|
||||
{ ERROR_LOCK_FAILED, EACCES },
|
||||
{ ERROR_ALREADY_EXISTS, EEXIST },
|
||||
{ ERROR_INVALID_STARTING_CODESEG, ENOEXEC },
|
||||
{ ERROR_INVALID_STACKSEG, ENOEXEC },
|
||||
{ ERROR_INVALID_MODULETYPE, ENOEXEC },
|
||||
{ ERROR_INVALID_EXE_SIGNATURE, ENOEXEC },
|
||||
{ ERROR_EXE_MARKED_INVALID, ENOEXEC },
|
||||
{ ERROR_BAD_EXE_FORMAT, ENOEXEC },
|
||||
{ ERROR_ITERATED_DATA_EXCEEDS_64k, ENOEXEC },
|
||||
{ ERROR_INVALID_MINALLOCSIZE, ENOEXEC },
|
||||
{ ERROR_DYNLINK_FROM_INVALID_RING, ENOEXEC },
|
||||
{ ERROR_IOPL_NOT_ENABLED, ENOEXEC },
|
||||
{ ERROR_INVALID_SEGDPL, ENOEXEC },
|
||||
{ ERROR_AUTODATASEG_EXCEEDS_64k, ENOEXEC },
|
||||
{ ERROR_RING2SEG_MUST_BE_MOVABLE, ENOEXEC },
|
||||
{ ERROR_RELOC_CHAIN_XEEDS_SEGLIM, ENOEXEC },
|
||||
{ ERROR_INFLOOP_IN_RELOC_CHAIN, ENOEXEC },
|
||||
{ ERROR_FILENAME_EXCED_RANGE, ENOENT },
|
||||
{ ERROR_NESTING_NOT_ALLOWED, EAGAIN },
|
||||
{ ERROR_NOT_ENOUGH_QUOTA, ENOMEM }
|
||||
};
|
||||
|
||||
#endif /* doserrmap_h */
|
117
lib/sdk/crt/stdlib/ecvt.c
Normal file
117
lib/sdk/crt/stdlib/ecvt.c
Normal file
|
@ -0,0 +1,117 @@
|
|||
/*
|
||||
* PROJECT: ReactOS CRT
|
||||
* LICENSE: See COPYING in the top level directory
|
||||
* PURPOSE: CRT's ecvt
|
||||
* FILE: lib/sdk/crt/stdlib/ecvt.c
|
||||
* PROGRAMERS: Gregor Schneider (parts based on ecvtbuf.c by DJ Delorie)
|
||||
*/
|
||||
|
||||
#include <precomp.h>
|
||||
#define NUMBER_EFMT 18 /* sign, dot, null, 15 for alignment */
|
||||
|
||||
/*
|
||||
* @implemented
|
||||
*/
|
||||
char *
|
||||
_ecvt (double value, int ndigits, int *decpt, int *sign)
|
||||
{
|
||||
static char ecvtbuf[DBL_MAX_10_EXP + 10];
|
||||
char *cvtbuf, *s, *d;
|
||||
|
||||
s = cvtbuf = (char*)malloc(ndigits + NUMBER_EFMT);
|
||||
d = ecvtbuf;
|
||||
|
||||
*sign = 0;
|
||||
*decpt = 0;
|
||||
|
||||
if (cvtbuf == NULL)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
sprintf(cvtbuf, "%-+.*E", ndigits, value);
|
||||
/* Treat special values */
|
||||
if (strncmp(s, "NaN", 3) == 0)
|
||||
{
|
||||
memcpy(ecvtbuf, s, 4);
|
||||
}
|
||||
else if (strncmp(s + 1, "Inf", 3) == 0)
|
||||
{
|
||||
memcpy(ecvtbuf, s, 5);
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Set the sign */
|
||||
if (*s && *s == '-')
|
||||
{
|
||||
*sign = 1;
|
||||
}
|
||||
s++;
|
||||
/* Copy the first digit */
|
||||
if (*s && *s != '.')
|
||||
{
|
||||
if (d - ecvtbuf < ndigits)
|
||||
{
|
||||
*d++ = *s++;
|
||||
}
|
||||
else
|
||||
{
|
||||
s++;
|
||||
}
|
||||
}
|
||||
/* Skip the decimal point */
|
||||
if (*s && *s == '.')
|
||||
{
|
||||
s++;
|
||||
}
|
||||
/* Copy fractional digits */
|
||||
while (*s && *s != 'E')
|
||||
{
|
||||
if (d - ecvtbuf < ndigits)
|
||||
{
|
||||
*d++ = *s++;
|
||||
}
|
||||
else
|
||||
{
|
||||
s++;
|
||||
}
|
||||
}
|
||||
/* Skip the exponent */
|
||||
if (*s && *s == 'E')
|
||||
{
|
||||
s++;
|
||||
}
|
||||
/* Set the decimal point to the exponent value plus the one digit we copied */
|
||||
*decpt = atoi(s) + 1;
|
||||
/* Handle special decimal point cases */
|
||||
if (cvtbuf[1] == '0')
|
||||
{
|
||||
*decpt = 0;
|
||||
}
|
||||
if (ndigits < 1)
|
||||
{
|
||||
/* Need enhanced precision*/
|
||||
char* tbuf = (char*)malloc(NUMBER_EFMT);
|
||||
if (tbuf == NULL)
|
||||
{
|
||||
free(cvtbuf);
|
||||
return NULL;
|
||||
}
|
||||
sprintf(tbuf, "%-+.*E", ndigits + 2, value);
|
||||
if (tbuf[1] >= '5')
|
||||
{
|
||||
(*decpt)++;
|
||||
}
|
||||
free(tbuf);
|
||||
}
|
||||
/* Pad with zeroes */
|
||||
while (d - ecvtbuf < ndigits)
|
||||
{
|
||||
*d++ = '0';
|
||||
}
|
||||
/* Terminate */
|
||||
*d = '\0';
|
||||
}
|
||||
free(cvtbuf);
|
||||
return ecvtbuf;
|
||||
}
|
151
lib/sdk/crt/stdlib/errno.c
Normal file
151
lib/sdk/crt/stdlib/errno.c
Normal file
|
@ -0,0 +1,151 @@
|
|||
/*
|
||||
* COPYRIGHT: See COPYING in the top level directory
|
||||
* PROJECT: ReactOS system libraries
|
||||
* FILE: lib/crt/errno.c
|
||||
* PURPOSE: Unknown
|
||||
* PROGRAMER: Unknown
|
||||
*
|
||||
*/
|
||||
#include <precomp.h>
|
||||
#include "doserrmap.h"
|
||||
#include <errno.h>
|
||||
#include <internal/wine/msvcrt.h>
|
||||
|
||||
static _invalid_parameter_handler invalid_parameter_handler = NULL;
|
||||
|
||||
/*
|
||||
* @implemented
|
||||
*/
|
||||
unsigned long* __doserrno(void)
|
||||
{
|
||||
return (unsigned long*)(&GetThreadData()->tdoserrno);
|
||||
}
|
||||
|
||||
/*
|
||||
* @implemented
|
||||
*/
|
||||
int *_errno(void)
|
||||
{
|
||||
return(&GetThreadData()->terrno);
|
||||
}
|
||||
|
||||
|
||||
int __set_doserrno(int error)
|
||||
{
|
||||
PTHREADDATA ThreadData;
|
||||
|
||||
ThreadData = GetThreadData();
|
||||
if (ThreadData)
|
||||
ThreadData->tdoserrno = error;
|
||||
|
||||
return(error);
|
||||
}
|
||||
|
||||
int __set_errno(int error)
|
||||
{
|
||||
PTHREADDATA ThreadData;
|
||||
|
||||
ThreadData = GetThreadData();
|
||||
if (ThreadData)
|
||||
ThreadData->terrno = error;
|
||||
|
||||
return(error);
|
||||
}
|
||||
|
||||
/*
|
||||
* This function sets both doserrno to the passed in OS error code
|
||||
* and also maps this to an appropriate errno code. The mapping
|
||||
* has been deduced automagically by running this functions, which
|
||||
* exists in MSVCRT but is undocumented, on all the error codes in
|
||||
* winerror.h.
|
||||
*/
|
||||
void _dosmaperr(unsigned long oserror)
|
||||
{
|
||||
int pos, base, lim;
|
||||
|
||||
__set_doserrno(oserror);
|
||||
|
||||
/* Use binary chop to find the corresponding errno code */
|
||||
for (base=0, lim=sizeof(doserrmap)/sizeof(doserrmap[0]); lim; lim >>= 1) {
|
||||
pos = base+(lim >> 1);
|
||||
if (doserrmap[pos].winerr == oserror) {
|
||||
__set_errno(doserrmap[pos].en);
|
||||
return;
|
||||
} else if (doserrmap[pos].winerr < oserror) {
|
||||
base = pos + 1;
|
||||
--lim;
|
||||
}
|
||||
}
|
||||
/* EINVAL appears to be the default */
|
||||
__set_errno(EINVAL);
|
||||
}
|
||||
|
||||
/******************************************************************************
|
||||
* _set_error_mode (MSVCRT.@)
|
||||
*
|
||||
* Set the error mode, which describes where the C run-time writes error
|
||||
* messages.
|
||||
*
|
||||
* PARAMS
|
||||
* mode - the new error mode
|
||||
*
|
||||
* RETURNS
|
||||
* The old error mode.
|
||||
*
|
||||
* TODO
|
||||
* This function does not have a proper implementation; the error mode is
|
||||
* never used.
|
||||
*/
|
||||
int CDECL _set_error_mode(int mode)
|
||||
{
|
||||
static int current_mode = MSVCRT__OUT_TO_DEFAULT;
|
||||
|
||||
const int old = current_mode;
|
||||
if ( MSVCRT__REPORT_ERRMODE != mode ) {
|
||||
current_mode = mode;
|
||||
|
||||
}
|
||||
return old;
|
||||
}
|
||||
|
||||
/******************************************************************************
|
||||
* _seterrormode (MSVCRT.@)
|
||||
*/
|
||||
void CDECL _seterrormode(int mode)
|
||||
{
|
||||
SetErrorMode( mode );
|
||||
}
|
||||
|
||||
/******************************************************************************
|
||||
* _invalid_parameter (MSVCRT.@)
|
||||
*/
|
||||
void __cdecl _invalid_parameter(const wchar_t *expr, const wchar_t *func,
|
||||
const wchar_t *file, unsigned int line, uintptr_t arg)
|
||||
{
|
||||
if (invalid_parameter_handler) invalid_parameter_handler( expr, func, file, line, arg );
|
||||
else
|
||||
{
|
||||
ERR( "%s:%u %s: %s %lx\n", debugstr_w(file), line, debugstr_w(func), debugstr_w(expr), arg );
|
||||
RaiseException( STATUS_INVALID_CRUNTIME_PARAMETER, EXCEPTION_NONCONTINUABLE, 0, NULL );
|
||||
}
|
||||
}
|
||||
|
||||
/* _get_invalid_parameter_handler - not exported in native msvcrt, added in msvcr80 */
|
||||
_invalid_parameter_handler CDECL _get_invalid_parameter_handler(void)
|
||||
{
|
||||
TRACE("\n");
|
||||
return invalid_parameter_handler;
|
||||
}
|
||||
|
||||
/* _set_invalid_parameter_handler - not exproted in native msvcrt, added in msvcr80 */
|
||||
_invalid_parameter_handler CDECL _set_invalid_parameter_handler(
|
||||
_invalid_parameter_handler handler)
|
||||
{
|
||||
_invalid_parameter_handler old = invalid_parameter_handler;
|
||||
|
||||
TRACE("(%p)\n", handler);
|
||||
|
||||
invalid_parameter_handler = handler;
|
||||
return old;
|
||||
}
|
||||
/* EOF */
|
14
lib/sdk/crt/stdlib/fcvt.c
Normal file
14
lib/sdk/crt/stdlib/fcvt.c
Normal file
|
@ -0,0 +1,14 @@
|
|||
/* Copyright (C) 1998 DJ Delorie, see COPYING.DJ for details */
|
||||
#include <precomp.h>
|
||||
|
||||
char *fcvtbuf (double, int, int *, int *, char *);
|
||||
|
||||
/*
|
||||
* @implemented
|
||||
*/
|
||||
char *
|
||||
_fcvt (double value, int ndigits, int *decpt, int *sign)
|
||||
{
|
||||
static char fcvt_buf[2 * DBL_MAX_10_EXP + 10];
|
||||
return fcvtbuf (value, ndigits, decpt, sign, fcvt_buf);
|
||||
}
|
126
lib/sdk/crt/stdlib/fcvtbuf.c
Normal file
126
lib/sdk/crt/stdlib/fcvtbuf.c
Normal file
|
@ -0,0 +1,126 @@
|
|||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <float.h>
|
||||
#include <math.h>
|
||||
#include <malloc.h>
|
||||
// #include <msvcrt/locale.h>
|
||||
|
||||
// replace fjgpp fcvtbuf from project http://www.jbox.dk/sanos/source/lib/fcvt.c.html
|
||||
// with small modification's to match ReactOS arch
|
||||
|
||||
// Floating point to string conversion routines
|
||||
//
|
||||
// Copyright (C) 2002 Michael Ringgaard. All rights reserved.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without
|
||||
// modification, are permitted provided that the following conditions
|
||||
// are met:
|
||||
//
|
||||
// 1. Redistributions of source code must retain the above copyright
|
||||
// notice, this list of conditions and the following disclaimer.
|
||||
// 2. Redistributions in binary form must reproduce the above copyright
|
||||
// notice, this list of conditions and the following disclaimer in the
|
||||
// documentation and/or other materials provided with the distribution.
|
||||
// 3. Neither the name of the project nor the names of its contributors
|
||||
// may be used to endorse or promote products derived from this software
|
||||
// without specific prior written permission.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||
// ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE
|
||||
// FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
// DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
// OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
// HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
// LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
// OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
// SUCH DAMAGE.
|
||||
//
|
||||
|
||||
|
||||
//#include <math.h>
|
||||
#define CVTBUFSIZE 2 * DBL_MAX_10_EXP + 10
|
||||
static char *cvt(double arg, int ndigits, int *decpt, int *sign, char *buf, int eflag)
|
||||
{
|
||||
int r2;
|
||||
double fi, fj;
|
||||
char *p, *p1;
|
||||
|
||||
if (ndigits >= CVTBUFSIZE - 1) ndigits = CVTBUFSIZE - 2;
|
||||
r2 = 0;
|
||||
*sign = 0;
|
||||
p = &buf[0];
|
||||
if (arg < 0)
|
||||
{
|
||||
*sign = 1;
|
||||
arg = -arg;
|
||||
}
|
||||
arg = modf(arg, &fi);
|
||||
p1 = &buf[CVTBUFSIZE];
|
||||
|
||||
if (fi != 0)
|
||||
{
|
||||
p1 = &buf[CVTBUFSIZE];
|
||||
while (fi != 0)
|
||||
{
|
||||
fj = modf(fi / 10, &fi);
|
||||
*--p1 = (int)((fj + .03) * 10) + '0';
|
||||
r2++;
|
||||
}
|
||||
while (p1 < &buf[CVTBUFSIZE]) *p++ = *p1++;
|
||||
}
|
||||
else if (arg > 0)
|
||||
{
|
||||
while ((fj = arg * 10) < 1)
|
||||
{
|
||||
arg = fj;
|
||||
r2--;
|
||||
}
|
||||
}
|
||||
p1 = &buf[ndigits];
|
||||
if (eflag == 0) p1 += r2;
|
||||
*decpt = r2;
|
||||
if (p1 < &buf[0])
|
||||
{
|
||||
buf[0] = '\0';
|
||||
return buf;
|
||||
}
|
||||
while (p <= p1 && p < &buf[CVTBUFSIZE])
|
||||
{
|
||||
arg *= 10;
|
||||
arg = modf(arg, &fj);
|
||||
*p++ = (int) fj + '0';
|
||||
}
|
||||
if (p1 >= &buf[CVTBUFSIZE])
|
||||
{
|
||||
buf[CVTBUFSIZE - 1] = '\0';
|
||||
return buf;
|
||||
}
|
||||
p = p1;
|
||||
*p1 += 5;
|
||||
while (*p1 > '9')
|
||||
{
|
||||
*p1 = '0';
|
||||
if (p1 > buf)
|
||||
++*--p1;
|
||||
else
|
||||
{
|
||||
*p1 = '1';
|
||||
(*decpt)++;
|
||||
if (eflag == 0)
|
||||
{
|
||||
if (p > buf) *p = '0';
|
||||
p++;
|
||||
}
|
||||
}
|
||||
}
|
||||
*p = '\0';
|
||||
return buf;
|
||||
}
|
||||
|
||||
char *fcvtbuf(double arg, int ndigits, int *decpt, int *sign, char *buf)
|
||||
{
|
||||
return cvt(arg, ndigits, decpt, sign, buf, 0);
|
||||
}
|
33
lib/sdk/crt/stdlib/fullpath.c
Normal file
33
lib/sdk/crt/stdlib/fullpath.c
Normal file
|
@ -0,0 +1,33 @@
|
|||
/*
|
||||
* COPYRIGHT: See COPYING in the top level directory
|
||||
* PROJECT: ReactOS system libraries
|
||||
* FILE: lib/msvcrt/stdlib/fullpath.c
|
||||
* PURPOSE: Gets the fullpathname
|
||||
* PROGRAMER: Ariadne
|
||||
* UPDATE HISTORY:
|
||||
* 28/12/98: Created
|
||||
*/
|
||||
|
||||
#include <precomp.h>
|
||||
#include <tchar.h>
|
||||
|
||||
/*
|
||||
* @implemented
|
||||
*/
|
||||
_TCHAR* _tfullpath(_TCHAR* absPath, const _TCHAR* relPath, size_t maxLength)
|
||||
{
|
||||
_TCHAR* lpFilePart;
|
||||
DWORD copied;
|
||||
|
||||
if (!absPath)
|
||||
{
|
||||
maxLength = MAX_PATH;
|
||||
absPath = malloc(maxLength);
|
||||
}
|
||||
|
||||
copied = GetFullPathName(relPath,maxLength,absPath,&lpFilePart);
|
||||
if (copied == 0 || copied > maxLength)
|
||||
return NULL;
|
||||
|
||||
return absPath;
|
||||
}
|
32
lib/sdk/crt/stdlib/gcvt.c
Normal file
32
lib/sdk/crt/stdlib/gcvt.c
Normal file
|
@ -0,0 +1,32 @@
|
|||
/* Copyright (C) 1998 DJ Delorie, see COPYING.DJ for details */
|
||||
#include <precomp.h>
|
||||
|
||||
/*
|
||||
* @implemented
|
||||
*/
|
||||
char *
|
||||
_gcvt (double value, int ndigits, char *buf)
|
||||
{
|
||||
char *p = buf;
|
||||
|
||||
sprintf (buf, "%-#.*g", ndigits, value);
|
||||
|
||||
/* It seems they expect us to return .XXXX instead of 0.XXXX */
|
||||
if (*p == '-')
|
||||
p++;
|
||||
if (*p == '0' && p[1] == '.')
|
||||
memmove (p, p + 1, strlen (p + 1) + 1);
|
||||
|
||||
/* They want Xe-YY, not X.e-YY, and XXXX instead of XXXX. */
|
||||
p = strchr (buf, 'e');
|
||||
if (!p)
|
||||
{
|
||||
p = buf + strlen (buf);
|
||||
/* They don't want trailing zeroes. */
|
||||
while (p[-1] == '0' && p > buf + 2)
|
||||
*--p = '\0';
|
||||
}
|
||||
if (p > buf && p[-1] == '.')
|
||||
memmove (p - 1, p, strlen (p) + 1);
|
||||
return buf;
|
||||
}
|
48
lib/sdk/crt/stdlib/getenv.c
Normal file
48
lib/sdk/crt/stdlib/getenv.c
Normal file
|
@ -0,0 +1,48 @@
|
|||
/*
|
||||
* COPYRIGHT: See COPYING in the top level directory
|
||||
* PROJECT: ReactOS system libraries
|
||||
* FILE: lib/crt/??????
|
||||
* PURPOSE: Unknown
|
||||
* PROGRAMER: Unknown
|
||||
* UPDATE HISTORY:
|
||||
* 25/11/05: Added license header
|
||||
*/
|
||||
|
||||
#include <precomp.h>
|
||||
//#undef environ
|
||||
|
||||
/*
|
||||
* @implemented
|
||||
*/
|
||||
char *getenv(const char *name)
|
||||
{
|
||||
char **environ;
|
||||
unsigned int length = strlen(name);
|
||||
|
||||
for (environ = *__p__environ(); *environ; environ++)
|
||||
{
|
||||
char *str = *environ;
|
||||
char *pos = strchr(str,'=');
|
||||
if (pos && ((unsigned int)(pos - str) == length) && !_strnicmp(str, name, length))
|
||||
return pos + 1;
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/*
|
||||
* @implemented
|
||||
*/
|
||||
wchar_t *_wgetenv(const wchar_t *name)
|
||||
{
|
||||
wchar_t **environ;
|
||||
unsigned int length = wcslen(name);
|
||||
|
||||
for (environ = *__p__wenviron(); *environ; environ++)
|
||||
{
|
||||
wchar_t *str = *environ;
|
||||
wchar_t *pos = wcschr(str, L'=');
|
||||
if (pos && ((unsigned int)(pos - str) == length) && !_wcsnicmp(str, name, length))
|
||||
return pos + 1;
|
||||
}
|
||||
return NULL;
|
||||
}
|
57
lib/sdk/crt/stdlib/makepath.c
Normal file
57
lib/sdk/crt/stdlib/makepath.c
Normal file
|
@ -0,0 +1,57 @@
|
|||
/*
|
||||
* PROJECT: ReactOS CRT library
|
||||
* LICENSE: See COPYING in the top level directory
|
||||
* FILE: lib/sdk/crt/stdlib/makepath.c
|
||||
* PURPOSE: Creates a path
|
||||
* PROGRAMMERS: Wine team
|
||||
* Copyright 1996,1998 Marcus Meissner
|
||||
* Copyright 1996 Jukka Iivonen
|
||||
* Copyright 1997,2000 Uwe Bonnes
|
||||
* Copyright 2000 Jon Griffiths
|
||||
*
|
||||
*/
|
||||
|
||||
/* $Id$
|
||||
*/
|
||||
#include <precomp.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
/*
|
||||
* @implemented
|
||||
*/
|
||||
void _makepath(char* path, const char* drive, const char* dir, const char* fname, const char* ext)
|
||||
{
|
||||
char *p = path;
|
||||
|
||||
if ( !path )
|
||||
return;
|
||||
|
||||
if (drive && drive[0])
|
||||
{
|
||||
*p++ = drive[0];
|
||||
*p++ = ':';
|
||||
}
|
||||
if (dir && dir[0])
|
||||
{
|
||||
unsigned int len = strlen(dir);
|
||||
memmove(p, dir, len);
|
||||
p += len;
|
||||
if (p[-1] != '/' && p[-1] != '\\')
|
||||
*p++ = '\\';
|
||||
}
|
||||
if (fname && fname[0])
|
||||
{
|
||||
unsigned int len = strlen(fname);
|
||||
memmove(p, fname, len);
|
||||
p += len;
|
||||
}
|
||||
if (ext && ext[0])
|
||||
{
|
||||
if (ext[0] != '.')
|
||||
*p++ = '.';
|
||||
strcpy(p, ext);
|
||||
}
|
||||
else
|
||||
*p = '\0';
|
||||
}
|
120
lib/sdk/crt/stdlib/makepath_s.c
Normal file
120
lib/sdk/crt/stdlib/makepath_s.c
Normal file
|
@ -0,0 +1,120 @@
|
|||
/*
|
||||
* PROJECT: ReactOS CRT library
|
||||
* LICENSE: See COPYING in the top level directory
|
||||
* FILE: lib/sdk/crt/stdlib/makepath_s.c
|
||||
* PURPOSE: Creates a path
|
||||
* PROGRAMMERS: Wine team
|
||||
* Copyright 1996,1998 Marcus Meissner
|
||||
* Copyright 1996 Jukka Iivonen
|
||||
* Copyright 1997,2000 Uwe Bonnes
|
||||
* Copyright 2000 Jon Griffiths
|
||||
*
|
||||
*/
|
||||
|
||||
#include <precomp.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
/*********************************************************************
|
||||
* _makepath_s (MSVCRT.@)
|
||||
*
|
||||
* Safe version of _makepath.
|
||||
*/
|
||||
int CDECL _makepath_s(char *path, size_t size, const char *drive,
|
||||
const char *directory, const char *filename,
|
||||
const char *extension)
|
||||
{
|
||||
char *p = path;
|
||||
|
||||
if (!path || !size)
|
||||
{
|
||||
*_errno() = EINVAL;
|
||||
return EINVAL;
|
||||
}
|
||||
|
||||
if (drive && drive[0])
|
||||
{
|
||||
if (size <= 2)
|
||||
goto range;
|
||||
|
||||
*p++ = drive[0];
|
||||
*p++ = ':';
|
||||
size -= 2;
|
||||
}
|
||||
|
||||
if (directory && directory[0])
|
||||
{
|
||||
unsigned int len = strlen(directory);
|
||||
unsigned int needs_separator = directory[len - 1] != '/' && directory[len - 1] != '\\';
|
||||
unsigned int copylen = min(size - 1, len);
|
||||
|
||||
if (size < 2)
|
||||
goto range;
|
||||
|
||||
memmove(p, directory, copylen);
|
||||
|
||||
if (size <= len)
|
||||
goto range;
|
||||
|
||||
p += copylen;
|
||||
size -= copylen;
|
||||
|
||||
if (needs_separator)
|
||||
{
|
||||
if (size < 2)
|
||||
goto range;
|
||||
|
||||
*p++ = '\\';
|
||||
size -= 1;
|
||||
}
|
||||
}
|
||||
|
||||
if (filename && filename[0])
|
||||
{
|
||||
unsigned int len = strlen(filename);
|
||||
unsigned int copylen = min(size - 1, len);
|
||||
|
||||
if (size < 2)
|
||||
goto range;
|
||||
|
||||
memmove(p, filename, copylen);
|
||||
|
||||
if (size <= len)
|
||||
goto range;
|
||||
|
||||
p += len;
|
||||
size -= len;
|
||||
}
|
||||
|
||||
if (extension && extension[0])
|
||||
{
|
||||
unsigned int len = strlen(extension);
|
||||
unsigned int needs_period = extension[0] != '.';
|
||||
unsigned int copylen;
|
||||
|
||||
if (size < 2)
|
||||
goto range;
|
||||
|
||||
if (needs_period)
|
||||
{
|
||||
*p++ = '.';
|
||||
size -= 1;
|
||||
}
|
||||
|
||||
copylen = min(size - 1, len);
|
||||
memcpy(p, extension, copylen);
|
||||
|
||||
if (size <= len)
|
||||
goto range;
|
||||
|
||||
p += copylen;
|
||||
}
|
||||
|
||||
*p = '\0';
|
||||
return 0;
|
||||
|
||||
range:
|
||||
path[0] = '\0';
|
||||
*_errno() = ERANGE;
|
||||
return ERANGE;
|
||||
}
|
158
lib/sdk/crt/stdlib/malloc.c
Normal file
158
lib/sdk/crt/stdlib/malloc.c
Normal file
|
@ -0,0 +1,158 @@
|
|||
/*
|
||||
* msvcrt.dll heap functions
|
||||
*
|
||||
* Copyright 2000 Jon Griffiths
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library 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
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*
|
||||
* Note: Win32 heap operations are MT safe. We only lock the new
|
||||
* handler and non atomic heap operations
|
||||
*/
|
||||
|
||||
#include <precomp.h>
|
||||
#include <stdlib.h>
|
||||
#include <malloc.h>
|
||||
|
||||
#define ROUND_DOWN(n, align) \
|
||||
(((ULONG)n) & ~((align) - 1l))
|
||||
|
||||
#define ROUND_UP(n, align) \
|
||||
ROUND_DOWN(((ULONG)n) + (align) - 1, (align))
|
||||
|
||||
/* round to 16 bytes + alloc at minimum 16 bytes */
|
||||
#define ROUND_SIZE(size) (max(16, ROUND_UP(size, 16)))
|
||||
|
||||
/*
|
||||
* @implemented
|
||||
*/
|
||||
void* malloc(size_t _size)
|
||||
{
|
||||
size_t nSize = ROUND_SIZE(_size);
|
||||
|
||||
if (nSize<_size)
|
||||
return NULL;
|
||||
|
||||
return HeapAlloc(GetProcessHeap(), 0, nSize);
|
||||
}
|
||||
|
||||
/*
|
||||
* @implemented
|
||||
*/
|
||||
void free(void* _ptr)
|
||||
{
|
||||
HeapFree(GetProcessHeap(),0,_ptr);
|
||||
}
|
||||
|
||||
/*
|
||||
* @implemented
|
||||
*/
|
||||
void* calloc(size_t _nmemb, size_t _size)
|
||||
{
|
||||
size_t nSize = _nmemb * _size;
|
||||
size_t cSize = ROUND_SIZE(nSize);
|
||||
|
||||
if ( (_nmemb > ((size_t)-1 / _size)) || (cSize<nSize))
|
||||
return NULL;
|
||||
|
||||
return HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, cSize );
|
||||
}
|
||||
|
||||
/*
|
||||
* @implemented
|
||||
*/
|
||||
void* realloc(void* _ptr, size_t _size)
|
||||
{
|
||||
size_t nSize;
|
||||
|
||||
if (_ptr == NULL)
|
||||
return malloc(_size);
|
||||
|
||||
if (_size == 0)
|
||||
{
|
||||
free(_ptr);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
nSize = ROUND_SIZE(_size);
|
||||
|
||||
/* check for integer overflow */
|
||||
if (nSize<_size)
|
||||
return NULL;
|
||||
|
||||
return HeapReAlloc(GetProcessHeap(), 0, _ptr, nSize);
|
||||
}
|
||||
|
||||
/*
|
||||
* @implemented
|
||||
*/
|
||||
void* _expand(void* _ptr, size_t _size)
|
||||
{
|
||||
size_t nSize;
|
||||
|
||||
nSize = ROUND_SIZE(_size);
|
||||
|
||||
if (nSize<_size)
|
||||
return NULL;
|
||||
|
||||
return HeapReAlloc(GetProcessHeap(), HEAP_REALLOC_IN_PLACE_ONLY, _ptr, nSize);
|
||||
}
|
||||
|
||||
/*
|
||||
* @implemented
|
||||
*/
|
||||
size_t _msize(void* _ptr)
|
||||
{
|
||||
return HeapSize(GetProcessHeap(), 0, _ptr);
|
||||
}
|
||||
|
||||
/*
|
||||
* @implemented
|
||||
*/
|
||||
int _heapchk(void)
|
||||
{
|
||||
if (!HeapValidate(GetProcessHeap(), 0, NULL))
|
||||
return -1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
* @implemented
|
||||
*/
|
||||
int _heapmin(void)
|
||||
{
|
||||
if (!HeapCompact(GetProcessHeap(), 0))
|
||||
return -1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
* @implemented
|
||||
*/
|
||||
int _heapset(unsigned int unFill)
|
||||
{
|
||||
if (_heapchk() == -1)
|
||||
return -1;
|
||||
return 0;
|
||||
|
||||
}
|
||||
|
||||
/*
|
||||
* @implemented
|
||||
*/
|
||||
int _heapwalk(struct _heapinfo* entry)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
28
lib/sdk/crt/stdlib/mbstowcs.c
Normal file
28
lib/sdk/crt/stdlib/mbstowcs.c
Normal file
|
@ -0,0 +1,28 @@
|
|||
#include <precomp.h>
|
||||
|
||||
|
||||
/*
|
||||
* @implemented
|
||||
*/
|
||||
size_t mbstowcs (wchar_t *widechar, const char *multibyte, size_t number)
|
||||
{
|
||||
int bytes;
|
||||
size_t n = 0;
|
||||
|
||||
while (n < number) {
|
||||
|
||||
if ((bytes = mbtowc (widechar, multibyte, MB_LEN_MAX)) < 0)
|
||||
return (size_t) -1;
|
||||
|
||||
if (bytes == 0) {
|
||||
*widechar = (wchar_t) '\0';
|
||||
return n;
|
||||
}
|
||||
|
||||
widechar++;
|
||||
multibyte += bytes;
|
||||
n++;
|
||||
}
|
||||
|
||||
return n;
|
||||
}
|
45
lib/sdk/crt/stdlib/mbtowc.c
Normal file
45
lib/sdk/crt/stdlib/mbtowc.c
Normal file
|
@ -0,0 +1,45 @@
|
|||
/*
|
||||
* COPYRIGHT: See COPYING in the top level directory
|
||||
* PROJECT: ReactOS system libraries
|
||||
* FILE: lib/crt/??????
|
||||
* PURPOSE: Unknown
|
||||
* PROGRAMER: Unknown
|
||||
* UPDATE HISTORY:
|
||||
* 25/11/05: Added license header
|
||||
*/
|
||||
|
||||
#include <precomp.h>
|
||||
|
||||
|
||||
/*
|
||||
* @implemented
|
||||
*/
|
||||
|
||||
int mbtowc (wchar_t *charptr, const char *address, size_t number)
|
||||
{
|
||||
int bytes;
|
||||
|
||||
if (address == 0)
|
||||
return 0;
|
||||
|
||||
if ((bytes = mblen (address, number)) < 0)
|
||||
return bytes;
|
||||
|
||||
if (charptr) {
|
||||
switch (bytes) {
|
||||
case 0:
|
||||
if (number > 0)
|
||||
*charptr = (wchar_t) '\0';
|
||||
break;
|
||||
case 1:
|
||||
*charptr = (wchar_t) ((unsigned char) address[0]);
|
||||
break;
|
||||
case 2:
|
||||
*charptr = (wchar_t) (((unsigned char) address[0] << 8)
|
||||
| (unsigned char) address[1]);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return bytes;
|
||||
}
|
24
lib/sdk/crt/stdlib/obsol.c
Normal file
24
lib/sdk/crt/stdlib/obsol.c
Normal file
|
@ -0,0 +1,24 @@
|
|||
#include <precomp.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#undef _cpumode
|
||||
unsigned char _cpumode = 0;
|
||||
unsigned char *_cpumode_dll = &_cpumode;
|
||||
|
||||
/*
|
||||
* @implemented
|
||||
*/
|
||||
void _beep(unsigned nFreq, unsigned nDur)
|
||||
{
|
||||
Beep(nFreq,nDur);
|
||||
return;
|
||||
}
|
||||
|
||||
/*
|
||||
* @implemented
|
||||
*/
|
||||
void _sleep(unsigned long ulTime)
|
||||
{
|
||||
Sleep(ulTime);
|
||||
return;
|
||||
}
|
31
lib/sdk/crt/stdlib/putenv.c
Normal file
31
lib/sdk/crt/stdlib/putenv.c
Normal file
|
@ -0,0 +1,31 @@
|
|||
/*
|
||||
* COPYRIGHT: See COPYING in the top level directory
|
||||
* PROJECT: ReactOS system libraries
|
||||
* FILE: lib/crt/??????
|
||||
* PURPOSE: Unknown
|
||||
* PROGRAMER: Unknown
|
||||
* UPDATE HISTORY:
|
||||
* 25/11/05: Added license header
|
||||
*/
|
||||
#include <precomp.h>
|
||||
|
||||
/* misc/environ.c */
|
||||
int SetEnv(const wchar_t *option);
|
||||
|
||||
/*
|
||||
* @implemented
|
||||
*/
|
||||
int _putenv(const char* val)
|
||||
{
|
||||
int size, result;
|
||||
wchar_t *woption;
|
||||
|
||||
size = MultiByteToWideChar(CP_ACP, 0, val, -1, NULL, 0);
|
||||
woption = malloc(size* sizeof(wchar_t));
|
||||
if (woption == NULL)
|
||||
return -1;
|
||||
MultiByteToWideChar(CP_ACP, 0, val, -1, woption, size);
|
||||
result = SetEnv(woption);
|
||||
free(woption);
|
||||
return result;
|
||||
}
|
242
lib/sdk/crt/stdlib/qsort.c
Normal file
242
lib/sdk/crt/stdlib/qsort.c
Normal file
|
@ -0,0 +1,242 @@
|
|||
/* Copyright (C) 1994 DJ Delorie, see COPYING.DJ for details */
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <search.h>
|
||||
|
||||
/*-
|
||||
* Copyright (c) 1980, 1983 The Regents of the University of California.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms are permitted
|
||||
* provided that: (1) source distributions retain this entire copyright
|
||||
* notice and comment, and (2) distributions including binaries display
|
||||
* the following acknowledgement: ``This product includes software
|
||||
* developed by the University of California, Berkeley and its contributors''
|
||||
* in the documentation or other materials provided with the distribution
|
||||
* and in all advertising materials mentioning features or use of this
|
||||
* software. Neither the name of the University nor the names of its
|
||||
* contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
|
||||
* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
|
||||
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
|
||||
*/
|
||||
|
||||
/*
|
||||
* qsort.c:
|
||||
* Our own version of the system qsort routine which is faster by an average
|
||||
* of 25%, with lows and highs of 10% and 50%.
|
||||
* The THRESHold below is the insertion sort threshold, and has been adjusted
|
||||
* for records of size 48 bytes.
|
||||
* The MTHREShold is where we stop finding a better median.
|
||||
*/
|
||||
|
||||
#define THRESH 4 /* threshold for insertion */
|
||||
#define MTHRESH 6 /* threshold for median */
|
||||
|
||||
/*
|
||||
* qst:
|
||||
* Do a quicksort
|
||||
* First, find the median element, and put that one in the first place as the
|
||||
* discriminator. (This "median" is just the median of the first, last and
|
||||
* middle elements). (Using this median instead of the first element is a big
|
||||
* win). Then, the usual partitioning/swapping, followed by moving the
|
||||
* discriminator into the right place. Then, figure out the sizes of the two
|
||||
* partions, do the smaller one recursively and the larger one via a repeat of
|
||||
* this code. Stopping when there are less than THRESH elements in a partition
|
||||
* and cleaning up with an insertion sort (in our caller) is a huge win.
|
||||
* All data swaps are done in-line, which is space-losing but time-saving.
|
||||
* (And there are only three places where this is done).
|
||||
*/
|
||||
|
||||
static void
|
||||
qst(size_t size, int (__cdecl *compar)(const void*, const void*), char *base, char *max)
|
||||
{
|
||||
char c, *i, *j, *jj;
|
||||
int ii;
|
||||
char *mid, *tmp;
|
||||
int lo, hi;
|
||||
size_t thresh;
|
||||
size_t mthresh;
|
||||
|
||||
thresh = size * THRESH;
|
||||
mthresh = size * MTHRESH;
|
||||
|
||||
/*
|
||||
* At the top here, lo is the number of characters of elements in the
|
||||
* current partition. (Which should be max - base).
|
||||
* Find the median of the first, last, and middle element and make
|
||||
* that the middle element. Set j to largest of first and middle.
|
||||
* If max is larger than that guy, then it's that guy, else compare
|
||||
* max with loser of first and take larger. Things are set up to
|
||||
* prefer the middle, then the first in case of ties.
|
||||
*/
|
||||
lo = max - base; /* number of elements as chars */
|
||||
do {
|
||||
mid = i = base + size * ((lo / size) >> 1);
|
||||
if (lo >= mthresh)
|
||||
{
|
||||
j = (compar((jj = base), i) > 0 ? jj : i);
|
||||
if (compar(j, (tmp = max - size)) > 0)
|
||||
{
|
||||
/* switch to first loser */
|
||||
j = (j == jj ? i : jj);
|
||||
if (compar(j, tmp) < 0)
|
||||
j = tmp;
|
||||
}
|
||||
if (j != i)
|
||||
{
|
||||
ii = size;
|
||||
do {
|
||||
c = *i;
|
||||
*i++ = *j;
|
||||
*j++ = c;
|
||||
} while (--ii);
|
||||
}
|
||||
}
|
||||
/*
|
||||
* Semi-standard quicksort partitioning/swapping
|
||||
*/
|
||||
for (i = base, j = max - size; ; )
|
||||
{
|
||||
while (i < mid && compar(i, mid) <= 0)
|
||||
i += size;
|
||||
while (j > mid)
|
||||
{
|
||||
if (compar(mid, j) <= 0)
|
||||
{
|
||||
j -= size;
|
||||
continue;
|
||||
}
|
||||
tmp = i + size; /* value of i after swap */
|
||||
if (i == mid)
|
||||
{
|
||||
/* j <-> mid, new mid is j */
|
||||
mid = jj = j;
|
||||
}
|
||||
else
|
||||
{
|
||||
/* i <-> j */
|
||||
jj = j;
|
||||
j -= size;
|
||||
}
|
||||
goto swap;
|
||||
}
|
||||
if (i == mid)
|
||||
{
|
||||
break;
|
||||
}
|
||||
else
|
||||
{
|
||||
/* i <-> mid, new mid is i */
|
||||
jj = mid;
|
||||
tmp = mid = i; /* value of i after swap */
|
||||
j -= size;
|
||||
}
|
||||
swap:
|
||||
ii = size;
|
||||
do {
|
||||
c = *i;
|
||||
*i++ = *jj;
|
||||
*jj++ = c;
|
||||
} while (--ii);
|
||||
i = tmp;
|
||||
}
|
||||
/*
|
||||
* Look at sizes of the two partitions, do the smaller
|
||||
* one first by recursion, then do the larger one by
|
||||
* making sure lo is its size, base and max are update
|
||||
* correctly, and branching back. But only repeat
|
||||
* (recursively or by branching) if the partition is
|
||||
* of at least size THRESH.
|
||||
*/
|
||||
i = (j = mid) + size;
|
||||
if ((lo = j - base) <= (hi = max - i))
|
||||
{
|
||||
if (lo >= thresh)
|
||||
qst(size, compar, base, j);
|
||||
base = i;
|
||||
lo = hi;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (hi >= thresh)
|
||||
qst(size, compar, i, max);
|
||||
max = j;
|
||||
}
|
||||
} while (lo >= thresh);
|
||||
}
|
||||
|
||||
/*
|
||||
* qsort:
|
||||
* First, set up some global parameters for qst to share. Then, quicksort
|
||||
* with qst(), and then a cleanup insertion sort ourselves. Sound simple?
|
||||
* It's not...
|
||||
*
|
||||
* @implemented
|
||||
*/
|
||||
void
|
||||
qsort(void *base0, size_t n, size_t size, int (__cdecl *compar)(const void*, const void*))
|
||||
{
|
||||
char *base = (char *)base0;
|
||||
char c, *i, *j, *lo, *hi;
|
||||
char *min, *max;
|
||||
size_t thresh;
|
||||
|
||||
if (n <= 1)
|
||||
return;
|
||||
|
||||
size = size;
|
||||
compar = compar;
|
||||
thresh = size * THRESH;
|
||||
max = base + n * size;
|
||||
if (n >= THRESH)
|
||||
{
|
||||
qst(size, compar, base, max);
|
||||
hi = base + thresh;
|
||||
}
|
||||
else
|
||||
{
|
||||
hi = max;
|
||||
}
|
||||
/*
|
||||
* First put smallest element, which must be in the first THRESH, in
|
||||
* the first position as a sentinel. This is done just by searching
|
||||
* the first THRESH elements (or the first n if n < THRESH), finding
|
||||
* the min, and swapping it into the first position.
|
||||
*/
|
||||
for (j = lo = base; (lo += size) < hi; )
|
||||
if (compar(j, lo) > 0)
|
||||
j = lo;
|
||||
if (j != base)
|
||||
{
|
||||
/* swap j into place */
|
||||
for (i = base, hi = base + size; i < hi; )
|
||||
{
|
||||
c = *j;
|
||||
*j++ = *i;
|
||||
*i++ = c;
|
||||
}
|
||||
}
|
||||
/*
|
||||
* With our sentinel in place, we now run the following hyper-fast
|
||||
* insertion sort. For each remaining element, min, from [1] to [n-1],
|
||||
* set hi to the index of the element AFTER which this one goes.
|
||||
* Then, do the standard insertion sort shift on a character at a time
|
||||
* basis for each element in the frob.
|
||||
*/
|
||||
for (min = base; (hi = min += size) < max; )
|
||||
{
|
||||
while (compar(hi -= size, min) > 0)
|
||||
/* void */;
|
||||
if ((hi += size) != min) {
|
||||
for (lo = min + size; --lo >= min; )
|
||||
{
|
||||
c = *lo;
|
||||
for (i = j = lo; (j -= size) >= hi; i = j)
|
||||
*i = *j;
|
||||
*i = c;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
69
lib/sdk/crt/stdlib/rot.c
Normal file
69
lib/sdk/crt/stdlib/rot.c
Normal file
|
@ -0,0 +1,69 @@
|
|||
/*
|
||||
* COPYRIGHT: See COPYING in the top level directory
|
||||
* PROJECT: ReactOS system libraries
|
||||
* FILE: lib/msvcrt/stdlib/rot.c
|
||||
* PURPOSE: Performs a bitwise rotation
|
||||
* PROGRAMER: Ariadne
|
||||
* UPDATE HISTORY:
|
||||
* 03/04/99: Created
|
||||
*/
|
||||
|
||||
#include <stdlib.h>
|
||||
|
||||
unsigned int _rotr( unsigned int value, int shift );
|
||||
/*
|
||||
* @implemented
|
||||
*/
|
||||
unsigned int _rotl( unsigned int value, int shift )
|
||||
{
|
||||
int max_bits = sizeof(unsigned int)<<3;
|
||||
if ( shift < 0 )
|
||||
return _rotr(value,-shift);
|
||||
|
||||
if ( shift > max_bits )
|
||||
shift = shift % max_bits;
|
||||
return (value << shift) | (value >> (max_bits-shift));
|
||||
}
|
||||
|
||||
/*
|
||||
* @implemented
|
||||
*/
|
||||
unsigned int _rotr( unsigned int value, int shift )
|
||||
{
|
||||
int max_bits = sizeof(unsigned int)<<3;
|
||||
if ( shift < 0 )
|
||||
return _rotl(value,-shift);
|
||||
|
||||
if ( shift > max_bits<<3 )
|
||||
shift = shift % max_bits;
|
||||
return (value >> shift) | (value << (max_bits-shift));
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* @implemented
|
||||
*/
|
||||
unsigned long _lrotl( unsigned long value, int shift )
|
||||
{
|
||||
int max_bits = sizeof(unsigned long)<<3;
|
||||
if ( shift < 0 )
|
||||
return _lrotr(value,-shift);
|
||||
|
||||
if ( shift > max_bits )
|
||||
shift = shift % max_bits;
|
||||
return (value << shift) | (value >> (max_bits-shift));
|
||||
}
|
||||
|
||||
/*
|
||||
* @implemented
|
||||
*/
|
||||
unsigned long _lrotr( unsigned long value, int shift )
|
||||
{
|
||||
int max_bits = sizeof(unsigned long)<<3;
|
||||
if ( shift < 0 )
|
||||
return _lrotl(value,-shift);
|
||||
|
||||
if ( shift > max_bits )
|
||||
shift = shift % max_bits;
|
||||
return (value >> shift) | (value << (max_bits-shift));
|
||||
}
|
52
lib/sdk/crt/stdlib/senv.c
Normal file
52
lib/sdk/crt/stdlib/senv.c
Normal file
|
@ -0,0 +1,52 @@
|
|||
/*
|
||||
* COPYRIGHT: See COPYING in the top level directory
|
||||
* PROJECT: ReactOS system libraries
|
||||
* FILE: lib/crt/??????
|
||||
* PURPOSE: Unknown
|
||||
* PROGRAMER: Unknown
|
||||
* UPDATE HISTORY:
|
||||
* 25/11/05: Added license header
|
||||
*/
|
||||
|
||||
#include <precomp.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <tchar.h>
|
||||
|
||||
#ifdef _UNICODE
|
||||
#define sT "S"
|
||||
#else
|
||||
#define sT "s"
|
||||
#endif
|
||||
|
||||
#define MK_STR(s) #s
|
||||
|
||||
|
||||
/*
|
||||
* @implemented
|
||||
*/
|
||||
void _tsearchenv(const _TCHAR* file,const _TCHAR* var,_TCHAR* path)
|
||||
{
|
||||
_TCHAR* env = _tgetenv(var);
|
||||
_TCHAR* x;
|
||||
_TCHAR* y;
|
||||
_TCHAR* FilePart;
|
||||
|
||||
TRACE(MK_STR(_tsearchenv)"()\n");
|
||||
|
||||
x = _tcschr(env,'=');
|
||||
if ( x != NULL ) {
|
||||
*x = 0;
|
||||
x++;
|
||||
}
|
||||
y = _tcschr(env,';');
|
||||
while ( y != NULL ) {
|
||||
*y = 0;
|
||||
if ( SearchPath(x,file,NULL,MAX_PATH,path,&FilePart) > 0 ) {
|
||||
return;
|
||||
}
|
||||
x = y+1;
|
||||
y = _tcschr(env,';');
|
||||
}
|
||||
return;
|
||||
}
|
33
lib/sdk/crt/stdlib/swab.c
Normal file
33
lib/sdk/crt/stdlib/swab.c
Normal file
|
@ -0,0 +1,33 @@
|
|||
/*
|
||||
* COPYRIGHT: See COPYING in the top level directory
|
||||
* PROJECT: ReactOS system libraries
|
||||
* FILE: lib/crt/??????
|
||||
* PURPOSE: Unknown
|
||||
* PROGRAMER: Unknown
|
||||
* UPDATE HISTORY:
|
||||
* 25/11/05: Added license header
|
||||
*/
|
||||
|
||||
#include <precomp.h>
|
||||
|
||||
/*
|
||||
* @implemented
|
||||
*
|
||||
* copy this swab from wine cvs 2006-05-24
|
||||
*/
|
||||
void _swab (char * src, char * dst, int sizeToCopy)
|
||||
|
||||
{
|
||||
if (sizeToCopy > 1)
|
||||
{
|
||||
sizeToCopy = (unsigned)sizeToCopy >> 1;
|
||||
|
||||
while (sizeToCopy--) {
|
||||
char s0 = src[0];
|
||||
char s1 = src[1];
|
||||
*dst++ = s1;
|
||||
*dst++ = s0;
|
||||
src = src + 2;
|
||||
}
|
||||
}
|
||||
}
|
5
lib/sdk/crt/stdlib/wfulpath.c
Normal file
5
lib/sdk/crt/stdlib/wfulpath.c
Normal file
|
@ -0,0 +1,5 @@
|
|||
|
||||
#define _UNICODE
|
||||
#define UNICODE
|
||||
|
||||
#include "fullpath.c"
|
55
lib/sdk/crt/stdlib/wmakpath.c
Normal file
55
lib/sdk/crt/stdlib/wmakpath.c
Normal file
|
@ -0,0 +1,55 @@
|
|||
/*
|
||||
* PROJECT: ReactOS CRT library
|
||||
* LICENSE: See COPYING in the top level directory
|
||||
* FILE: lib/sdk/crt/stdlib/wmakpath.c
|
||||
* PURPOSE: Creates a unicode path
|
||||
* PROGRAMMERS: Wine team
|
||||
* Copyright 1996,1998 Marcus Meissner
|
||||
* Copyright 1996 Jukka Iivonen
|
||||
* Copyright 1997,2000 Uwe Bonnes
|
||||
* Copyright 2000 Jon Griffiths
|
||||
*
|
||||
*/
|
||||
|
||||
/* $Id$
|
||||
*/
|
||||
#include <precomp.h>
|
||||
|
||||
/*
|
||||
* @implemented
|
||||
*/
|
||||
void _wmakepath(wchar_t* path, const wchar_t* drive, const wchar_t* dir, const wchar_t* fname, const wchar_t* ext)
|
||||
{
|
||||
wchar_t *p = path;
|
||||
|
||||
if ( !path )
|
||||
return;
|
||||
|
||||
if (drive && drive[0])
|
||||
{
|
||||
*p++ = drive[0];
|
||||
*p++ = ':';
|
||||
}
|
||||
if (dir && dir[0])
|
||||
{
|
||||
unsigned int len = strlenW(dir);
|
||||
memmove(p, dir, len * sizeof(wchar_t));
|
||||
p += len;
|
||||
if (p[-1] != '/' && p[-1] != '\\')
|
||||
*p++ = '\\';
|
||||
}
|
||||
if (fname && fname[0])
|
||||
{
|
||||
unsigned int len = strlenW(fname);
|
||||
memmove(p, fname, len * sizeof(wchar_t));
|
||||
p += len;
|
||||
}
|
||||
if (ext && ext[0])
|
||||
{
|
||||
if (ext[0] != '.')
|
||||
*p++ = '.';
|
||||
strcpyW(p, ext);
|
||||
}
|
||||
else
|
||||
*p = '\0';
|
||||
}
|
121
lib/sdk/crt/stdlib/wmakpath_s.c
Normal file
121
lib/sdk/crt/stdlib/wmakpath_s.c
Normal file
|
@ -0,0 +1,121 @@
|
|||
/*
|
||||
* PROJECT: ReactOS CRT library
|
||||
* LICENSE: See COPYING in the top level directory
|
||||
* FILE: lib/sdk/crt/stdlib/wmakpath_s.c
|
||||
* PURPOSE: Creates a path
|
||||
* PROGRAMMERS: Wine team
|
||||
* Copyright 1996,1998 Marcus Meissner
|
||||
* Copyright 1996 Jukka Iivonen
|
||||
* Copyright 1997,2000 Uwe Bonnes
|
||||
* Copyright 2000 Jon Griffiths
|
||||
*
|
||||
*/
|
||||
|
||||
#include <precomp.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
/*********************************************************************
|
||||
* _wmakepath_s (MSVCRT.@)
|
||||
*
|
||||
* Safe version of _wmakepath.
|
||||
*/
|
||||
int CDECL _wmakepath_s(wchar_t *path, size_t size, const wchar_t *drive,
|
||||
const wchar_t *directory, const wchar_t *filename,
|
||||
const wchar_t *extension)
|
||||
{
|
||||
wchar_t *p = path;
|
||||
|
||||
if (!path || !size)
|
||||
{
|
||||
*_errno() = EINVAL;
|
||||
return EINVAL;
|
||||
}
|
||||
|
||||
if (drive && drive[0])
|
||||
{
|
||||
if (size <= 2)
|
||||
goto range;
|
||||
|
||||
*p++ = drive[0];
|
||||
*p++ = ':';
|
||||
size -= 2;
|
||||
}
|
||||
|
||||
if (directory && directory[0])
|
||||
{
|
||||
unsigned int len = strlenW(directory);
|
||||
unsigned int needs_separator = directory[len - 1] != '/' && directory[len - 1] != '\\';
|
||||
unsigned int copylen = min(size - 1, len);
|
||||
|
||||
if (size < 2)
|
||||
goto range;
|
||||
|
||||
memmove(p, directory, copylen * sizeof(wchar_t));
|
||||
|
||||
if (size <= len)
|
||||
goto range;
|
||||
|
||||
p += copylen;
|
||||
size -= copylen;
|
||||
|
||||
if (needs_separator)
|
||||
{
|
||||
if (size < 2)
|
||||
goto range;
|
||||
|
||||
*p++ = '\\';
|
||||
size -= 1;
|
||||
}
|
||||
}
|
||||
|
||||
if (filename && filename[0])
|
||||
{
|
||||
unsigned int len = strlenW(filename);
|
||||
unsigned int copylen = min(size - 1, len);
|
||||
|
||||
if (size < 2)
|
||||
goto range;
|
||||
|
||||
memmove(p, filename, copylen * sizeof(wchar_t));
|
||||
|
||||
if (size <= len)
|
||||
goto range;
|
||||
|
||||
p += len;
|
||||
size -= len;
|
||||
}
|
||||
|
||||
if (extension && extension[0])
|
||||
{
|
||||
unsigned int len = strlenW(extension);
|
||||
unsigned int needs_period = extension[0] != '.';
|
||||
unsigned int copylen;
|
||||
|
||||
if (size < 2)
|
||||
goto range;
|
||||
|
||||
if (needs_period)
|
||||
{
|
||||
*p++ = '.';
|
||||
size -= 1;
|
||||
}
|
||||
|
||||
copylen = min(size - 1, len);
|
||||
memcpy(p, extension, copylen * sizeof(wchar_t));
|
||||
|
||||
if (size <= len)
|
||||
goto range;
|
||||
|
||||
p += copylen;
|
||||
}
|
||||
|
||||
*p = '\0';
|
||||
return 0;
|
||||
|
||||
range:
|
||||
path[0] = '\0';
|
||||
*_errno() = ERANGE;
|
||||
return ERANGE;
|
||||
}
|
||||
|
13
lib/sdk/crt/stdlib/wputenv.c
Normal file
13
lib/sdk/crt/stdlib/wputenv.c
Normal file
|
@ -0,0 +1,13 @@
|
|||
#include <precomp.h>
|
||||
|
||||
|
||||
/* misc/environ.c */
|
||||
int SetEnv(const wchar_t *option);
|
||||
|
||||
/*
|
||||
* @implemented
|
||||
*/
|
||||
int _wputenv(const wchar_t* val)
|
||||
{
|
||||
return SetEnv(val);
|
||||
}
|
5
lib/sdk/crt/stdlib/wsenv.c
Normal file
5
lib/sdk/crt/stdlib/wsenv.c
Normal file
|
@ -0,0 +1,5 @@
|
|||
|
||||
#define _UNICODE
|
||||
#define UNICODE
|
||||
|
||||
#include "senv.c"
|
Loading…
Add table
Add a link
Reference in a new issue