static void free_environment(Character** const environment) throw()
{
    if (!environment)
        return;

    for (Character** it = environment; *it; ++it)
        _free_crt(*it);

    _free_crt(environment);
}
示例#2
0
int __cdecl rename(
        const char *oldname,
        const char *newname )
{
    /*
       We want to use MoveFileExW but not MoveFileExA (or MoveFile).
       So convert the strings to Unicode representation and call _wrename.

       Note that minwin does not support OEM CP for conversion via
       the FileAPIs APIs. So we unconditionally use the ACP for conversion
    */
    int oldnamelen;
    int newnamelen;
    wchar_t *widenamesbuffer = NULL;
    wchar_t *oldnamew = NULL;
    wchar_t *newnamew = NULL;
    int retval;
    UINT codePage = CP_ACP;

#if !(defined (_CORESYS) || defined (_CRT_APP) || defined (_KERNELX))
    if (!__crtIsPackagedApp() && !AreFileApisANSI())
        codePage = CP_OEMCP;
#endif  /* !(defined (_CORESYS) || defined (_CRT_APP) || defined (_KERNELX)) */

    if (  ( (oldnamelen = MultiByteToWideChar(codePage, 0, oldname, -1, 0, 0) ) == 0 )
        || ( (newnamelen = MultiByteToWideChar(codePage, 0, newname, -1, 0, 0) ) == 0 ) )
    {
        _dosmaperr(GetLastError());
        return -1;
    }

    /* allocate enough space for both */
    if ( (widenamesbuffer = (wchar_t*)_malloc_crt( (oldnamelen+newnamelen) * sizeof(wchar_t) ) ) == NULL )
    {
        /* errno is set by _malloc */
        return -1;
    }

    /* now do the conversion */
    oldnamew = widenamesbuffer;
    newnamew = widenamesbuffer + oldnamelen;

    if (  ( MultiByteToWideChar(codePage, 0, oldname, -1, oldnamew, oldnamelen) == 0 )
        || ( MultiByteToWideChar(codePage, 0, newname, -1, newnamew, newnamelen) == 0 ) )
    {
        _free_crt(widenamesbuffer);
        _dosmaperr(GetLastError());
        return -1;
    }

    /* and event call the wide-character variant */
    retval = _wrename(oldnamew,newnamew);
    _free_crt(widenamesbuffer); /* _free_crt leaves errno alone if everything completes as expected */
    return retval;
}
示例#3
0
extern "C" void __cdecl __acrt_stdio_free_tmpfile_name_buffers_nolock()
{
    for (char*& p : narrow_tmpfile_buffer_pointers)
    {
        _free_crt(p);
        p = nullptr;
    }

    for (wchar_t*& p : wide_tmpfile_buffer_pointers)
    {
        _free_crt(p);
        p = nullptr;
    }
}
示例#4
0
文件: INITMON.C 项目: ngphloc/agmagic
int __cdecl __init_monetary (
        void
        )
{
        struct lconv *lc;

        if (__lc_handle[LC_MONETARY] != _CLOCALEHANDLE) {

                /* Allocate structure filled with NULL pointers */
                if ((lc = (struct lconv *)
                        _calloc_crt (1, sizeof(struct lconv))) == NULL)
                        return 1;

                if (_get_lc_lconv (lc)) {
                        _free_lc_lconv (lc);
                        _free_crt (lc);
                        return 1;
                }

                /* Copy numeric locale fields */
                lc->decimal_point = __lconv->decimal_point;
                lc->thousands_sep = __lconv->thousands_sep;
                lc->grouping = __lconv->grouping;

                __lconv = lc;                   /* point to new one */
                _free_lc_lconv (__lconv_intl);  /* free the old one */
                _free_crt (__lconv_intl);
                __lconv_intl = lc;
                return 0;

        } else {
                /*
                 *  Copy numeric locale fields (not necessarily C locale)
                 *  to static structure.  Note that __lconv_c numeric locale
                 *  fields may contain non-C locale information, but
                 *  monetary locale fields always contain C locale info.
                 */
                __lconv_c.decimal_point = __lconv->decimal_point;
                __lconv_c.thousands_sep = __lconv->thousands_sep;
                __lconv_c.grouping = __lconv->grouping;

                __lconv = &__lconv_c;           /* point to new one */

                _free_lc_lconv (__lconv_intl);  /* free the old one */
                _free_crt (__lconv_intl);
                __lconv_intl = NULL;
                return 0;
        }
}
示例#5
0
extern "C" float _CRTIMP __cdecl _wcstof_l (
    const wchar_t *nptr,
    wchar_t **endptr,
    _locale_t plocinfo
    )
{
    int len;
    char * str = NULL;

    /* get the buffer size needed for conversion */
    if  ( (len = WideCharToMultiByte(CP_ACP, 0 /* Use default flags */, nptr, -1, 0, 0, NULL, NULL) ) == 0 )
    {
        _dosmaperr(GetLastError());
        return 0;
    }

    /* allocate enough space for conversion */
    if ( (str = (char*)_malloc_crt( len * sizeof(char) ) ) == NULL )
    {
        /* malloc should set the errno */
        return 0;
    }

    /* now do the conversion */
    if ( WideCharToMultiByte(CP_ACP, 0 /* Use default flags */, nptr, -1, str, len, NULL, NULL) == 0 )
    {
        _dosmaperr(GetLastError());
        _free_crt(str);
        return 0;
    }

    _CRT_FLOAT ret;
    char *local_end_ptr = NULL;
    __crt_atoflt_l(&ret, str, plocinfo, &local_end_ptr);
    if (endptr != NULL)
    {
        if (local_end_ptr != NULL)
        {
            *endptr = (wchar_t*)(nptr + (local_end_ptr - str));
        }
        else
        {
            *endptr = NULL;
        }
    }
    _free_crt(str);
    return ret.f;
}
示例#6
0
extern "C" int __cdecl _fclose_nolock(FILE* const public_stream)
{
    __crt_stdio_stream const stream(public_stream);

    _VALIDATE_RETURN(stream.valid(), EINVAL, EOF);

    int result = EOF;

    if (stream.is_in_use())
    {
        result = __acrt_stdio_flush_nolock(stream.public_stream());
        __acrt_stdio_free_buffer_nolock(stream.public_stream());

        if (_close(_fileno(stream.public_stream())) < 0)
        {
            result = EOF;
        }
        else if (stream->_tmpfname != nullptr)
        {
            _free_crt(stream->_tmpfname);
            stream->_tmpfname = nullptr;
        }
    }

    __acrt_stdio_free_stream(stream);

    return result;
}
示例#7
0
void __cdecl _ioterm (
        void
	)
{
        int i;
#if     defined(_MT) && !defined(DLL_FOR_WIN32S)
        ioinfo *pio;
#endif

	for ( i = 0 ; i < IOINFO_ARRAYS ; i++ ) {

	    if ( __pioinfo[i] != NULL ) {
#if     defined(_MT) && !defined(DLL_FOR_WIN32S)
		/*
		 * Delete any initialized critical sections.
		 */
		for ( pio = __pioinfo[i] ;
		      pio < __pioinfo[i] + IOINFO_ARRAY_ELTS ;
		      pio++ )
		{
		    if ( pio->lockinitflag )
			DeleteCriticalSection( &(pio->lock) );
		}
#endif
		/*
		 * Free the memory which held the ioinfo array.
		 */
		_free_crt( __pioinfo[i] );
		__pioinfo[i] == NULL;
	    }
	}
}
示例#8
0
int __cdecl __init_time (
        pthreadlocinfo ploci
        )
{
    /* Temporary date/time strings */
    struct __lc_time_data *lc_time;

    if ( ploci->lc_handle[LC_TIME] != _CLOCALEHANDLE )
    {
            /* Allocate structure filled with NULL pointers */
            if ( (lc_time = (struct __lc_time_data *)
                 _calloc_crt(1, sizeof(struct __lc_time_data))) == NULL )
                    return 1;

            if (_get_lc_time(lc_time, ploci))
            {
                    __free_lc_time (lc_time);
                    _free_crt (lc_time);
                    return 1;
            }
            lc_time->refcount = 1;
    } else {
            lc_time = &__lc_time_c;      /* point to new one */
    }
    if (ploci->lc_time_curr != &__lc_time_c &&
        InterlockedDecrement(&(ploci->lc_time_curr->refcount)) == 0)
    {
        _ASSERTE(ploci->lc_time_curr->refcount > 0);
    }
    ploci->lc_time_curr = lc_time;           /* point to new one */
    return 0;
}
示例#9
0
文件: wperror.c 项目: flychen50/clib
void __cdecl _wperror (
        const wchar_t *wmessage
        )
{
        int fh = 2;
        size_t size = 0;
        char *amessage;
        const char *sysmessage;

        /* convert WCS string into ASCII string */

        if ( wmessage && *wmessage )
        {
            _ERRCHECK_EINVAL_ERANGE(wcstombs_s( &size, NULL, 0, wmessage, INT_MAX));

            if ( size==0 || (amessage = (char *)_calloc_crt(size, sizeof(char))) == NULL )
                return;

            if ( _ERRCHECK_EINVAL_ERANGE(wcstombs_s(NULL, amessage, size, wmessage, _TRUNCATE)) != 0)
            {
                _free_crt(amessage);
                return;
            }
        }
        else
            amessage = NULL;

        _lock_fh( fh );         /* acquire file handle lock */
        __try {

        if ( amessage )
        {
                _write_nolock(fh,(char *)amessage,(unsigned)strlen(amessage));
                _write_nolock(fh,": ",2);
        }

        _free_crt(amessage);    /* note: freeing NULL is legal and benign */

        sysmessage = _get_sys_err_msg( errno );
        _write_nolock(fh, sysmessage,(unsigned)strlen(sysmessage));
        _write_nolock(fh,"\n",1);

        }
        __finally {
            _unlock_fh( fh );   /* release file handle lock */
        }
}
示例#10
0
int __cdecl __wtomb_environ (
        void
        )
{
        char *envp=NULL;
        wchar_t **wenvp = _wenviron;

        /*
         * For every environment variable in the multibyte environment,
         * convert it and add it to the wide environment.
         */

        while (*wenvp)
        {
            int size;

            /* find out how much space is needed */
            if ((size = WideCharToMultiByte(CP_ACP, 0, *wenvp, -1, NULL, 0, NULL, NULL)) == 0)
                return -1;

            /* allocate space for variable */
            if ((envp = (char *) _calloc_crt(size, sizeof(char))) == NULL)
                return -1;

            /* convert it */
            if (WideCharToMultiByte(CP_ACP, 0, *wenvp, -1, envp, size, NULL, NULL) == 0)
            {
                _free_crt(envp);
                return -1;
            }

            /* set it - this is not primary call, so set primary == 0 */
            if(__crtsetenv(&envp, 0)<0)
            {
                if(envp)
                {
                    _free_crt(envp);
                    envp=NULL;
                }
            }

            wenvp++;
        }

        return 0;
}
/*
 *  Free the lconv monetary strings.
 *  Numeric values do not need to be freed.
 */
void __cdecl __free_lconv_mon(
        struct lconv *l
        )
{
    if (l == NULL)
        return;

    if ( l->int_curr_symbol != __lconv_c.int_curr_symbol )
        _free_crt(l->int_curr_symbol);

    if ( l->currency_symbol != __lconv_c.currency_symbol )
        _free_crt(l->currency_symbol);

    if ( l->mon_decimal_point != __lconv_c.mon_decimal_point )
        _free_crt(l->mon_decimal_point);

    if ( l->mon_thousands_sep != __lconv_c.mon_thousands_sep )
        _free_crt(l->mon_thousands_sep);

    if ( l->mon_grouping != __lconv_c.mon_grouping )
        _free_crt(l->mon_grouping);

    if ( l->positive_sign != __lconv_c.positive_sign )
        _free_crt(l->positive_sign);

    if ( l->negative_sign != __lconv_c.negative_sign )
        _free_crt(l->negative_sign);
}
示例#12
0
intptr_t __cdecl _tspawnle (
        int modeflag,
        const _TSCHAR *pathname,
        const _TSCHAR *arglist,
        ...
        )
{
#ifdef _M_IX86

        REG1 const _TSCHAR **argp;

        /* validation section */
        _VALIDATE_RETURN(pathname != NULL, EINVAL, -1);
        _VALIDATE_RETURN(*pathname != _T('\0'), EINVAL, -1);
        _VALIDATE_RETURN(arglist != NULL, EINVAL, -1);
        _VALIDATE_RETURN(*arglist != _T('\0'), EINVAL, -1);

        /* walk the arglist until the terminating NULL pointer is found.  The
         * next location holds the environment table pointer.
         */

        argp = &arglist;
        while (*argp++)
                ;

        return(_tspawnve(modeflag,pathname,&arglist,(_TSCHAR **)*argp));

#else  /* _M_IX86 */

        va_list vargs;
        _TSCHAR * argbuf[64];
        _TSCHAR ** argv;
        _TSCHAR ** envp;
        intptr_t result;

        /* validation section */
        _VALIDATE_RETURN(pathname != NULL, EINVAL, -1);
        _VALIDATE_RETURN(*pathname != _T('\0'), EINVAL, -1);
        _VALIDATE_RETURN(arglist != NULL, EINVAL, -1);
        _VALIDATE_RETURN(*arglist != _T('\0'), EINVAL, -1);

        va_start(vargs, arglist);
#ifdef WPRFLAG
        argv = _wcapture_argv(&vargs, arglist, argbuf, 64);
#else  /* WPRFLAG */
        argv = _capture_argv(&vargs, arglist, argbuf, 64);
#endif  /* WPRFLAG */
        envp = va_arg(vargs, _TSCHAR **);
        va_end(vargs);

        result = _tspawnve(modeflag,pathname,argv,envp);
        if (argv && argv != argbuf)
            _free_crt(argv);
        return result;

#endif  /* _M_IX86 */
}
示例#13
0
文件: mutex.c 项目: Chuyu-Team/VC-LTL
void _Mtx_destroy(_Mtx_t mtx)
	{	/* destroy mutex */
	if (mtx)
		{	/* something to do, do it */
		_Mtx_destroy_in_situ(mtx);
		_free_crt(mtx);

		}
	}
// This function is called by the operating system when a thread is being
// destroyed, to allow us the opportunity to clean up.
static void WINAPI destroy_fls(void* const pfd) throw()
{
    if (!pfd)
    {
        return;
    }

    destroy_ptd_array(static_cast<__acrt_ptd*>(pfd));
    _free_crt(pfd);
}
示例#15
0
文件: _file.c 项目: mysticTot/learn_c
void __cdecl __endstdio(void) {
    /* flush all streams */
    _flushall();

    /* if in callable exit, close all streams */
    if (_exitflag) {
        _fcloseall();
    }

    _free_crt(__piob);
}
int __cdecl _fcloseall (
        void
        )
{
        REG2 int count = 0;

#ifdef _WIN32

        REG1 i;

        _mlock(_IOB_SCAN_LOCK);

        for ( i = 3 ; i < _nstream ; i++ ) {

            if ( __piob[i] != NULL ) {
                /*
                 * if the stream is in use, close it
                 */
                if ( inuse( (FILE *)__piob[i] ) && (fclose( __piob[i] ) !=
                     EOF) )
                        count++;

                /*
                 * if stream is part of a _FILEX we allocated, free it.
                 */
                if ( i >= _IOB_ENTRIES ) {

#if defined (_MT)
                    DeleteCriticalSection( &(((_FILEX *)__piob[i])->lock) );
#endif  /* defined (_MT) */
                    _free_crt( __piob[i] );
                    __piob[i] = NULL;
                }
            }
        }

        _munlock(_IOB_SCAN_LOCK);

#else  /* _WIN32 */
#if defined (_M_MPPC) || defined (_M_M68K)

        REG1 FILE *stream = &_iob[3];

        for (; stream <= _lastiob; stream++)
                if (fclose(stream) != EOF)
                        count++;

#endif  /* defined (_M_MPPC) || defined (_M_M68K) */
#endif  /* _WIN32 */

        return(count);
}
示例#17
0
intptr_t __cdecl _texeclpe (
        const _TSCHAR *filename,
        const _TSCHAR *arglist,
        ...
        )
{
#ifdef _M_IX86

        const _TSCHAR **argp;

        /* validation section */
        _VALIDATE_RETURN(filename != NULL, EINVAL, -1);
        _VALIDATE_RETURN(*filename != _T('\0'), EINVAL, -1);
        _VALIDATE_RETURN(arglist != NULL, EINVAL, -1);
        _VALIDATE_RETURN(*arglist != _T('\0'), EINVAL, -1);

        argp = &arglist;
        while (*argp++)
                ;

        return(_texecvpe(filename,&arglist,(_TSCHAR **)*argp));

#else  /* _M_IX86 */

        va_list vargs;
        _TSCHAR * argbuf[64];
        _TSCHAR ** argv;
        _TSCHAR ** envp;
        intptr_t result;

        /* validation section */
        _VALIDATE_RETURN(filename != NULL, EINVAL, -1);
        _VALIDATE_RETURN(*filename != _T('\0'), EINVAL, -1);
        _VALIDATE_RETURN(arglist != NULL, EINVAL, -1);
        _VALIDATE_RETURN(*arglist != _T('\0'), EINVAL, -1);

        va_start(vargs, arglist);
#ifdef WPRFLAG
        argv = _wcapture_argv(&vargs, arglist, argbuf, 64);
#else  /* WPRFLAG */
        argv = _capture_argv(&vargs, arglist, argbuf, 64);
#endif  /* WPRFLAG */
        envp = va_arg(vargs, _TSCHAR **);
        va_end(vargs);

        result = _texecvpe(filename,argv,envp);
        if (argv && argv != argbuf)
            _free_crt(argv);
        return result;

#endif  /* _M_IX86 */
}
示例#18
0
int __cdecl _tspawnlpe (
        int modeflag,
        const _TSCHAR *filename,
        const _TSCHAR *arglist,
        ...
        )
{
#ifdef _M_IX86

        REG1 const _TSCHAR **argp;

        _ASSERTE(filename != NULL);
        _ASSERTE(*filename != _T('\0'));
        _ASSERTE(arglist != NULL);
        _ASSERTE(*arglist != _T('\0'));

        argp = &arglist;
        while (*argp++)
                ;

        return(_tspawnvpe(modeflag,filename,&arglist,(_TSCHAR **)*argp));

#else  /* _M_IX86 */

        va_list vargs;
        _TSCHAR * argbuf[64];
        _TSCHAR ** argv;
        _TSCHAR ** envp;
        int result;

        _ASSERTE(filename != NULL);
        _ASSERTE(*filename != _T('\0'));
        _ASSERTE(arglist != NULL);
        _ASSERTE(*arglist != _T('\0'));

        va_start(vargs, arglist);
#ifdef WPRFLAG
        argv = _wcapture_argv(&vargs, arglist, argbuf, 64);
#else  /* WPRFLAG */
        argv = _capture_argv(&vargs, arglist, argbuf, 64);
#endif  /* WPRFLAG */
        envp = va_arg(vargs, _TSCHAR **);
        va_end(vargs);

        result = _tspawnvpe(modeflag,filename,argv,envp);
        if (argv && argv != argbuf)
            _free_crt(argv);
        return result;

#endif  /* _M_IX86 */
}
void __cdecl _wperror (
        REG1 const wchar_t *wmessage
        )
{
        REG2 int fh = 2;
        int size;
        char *amessage;

        /* convert WCS string into ASCII string */

        size = wcslen(wmessage) + 1;

        if (NULL == (amessage = (char *)_malloc_crt(size * sizeof(char))))
            return;

        if (0 == (wcstombs(amessage, wmessage, size)))
        {
            _free_crt (amessage);
            return;
        }

        _lock_fh(fh);           /* acquire file handle lock */

        if (amessage && *amessage)
        {
                _write_lk(fh,(char *)amessage,strlen(amessage));
                _write_lk(fh,": ",2);
        }

        _free_crt(amessage);

        amessage = _sys_err_msg( errno );
        _write_lk(fh,(char *)amessage,strlen(amessage));
        _write_lk(fh,"\n",1);

        _unlock_fh(fh);         /* release file handle lock */
}
示例#20
0
文件: _freebuf.c 项目: flychen50/clib
void __cdecl _freebuf (
        REG1 FILE *stream
        )
{
        _ASSERTE(stream != NULL);

        if (inuse(stream) && mbuf(stream))
        {
                _free_crt(stream->_base);

                stream->_flag &= ~(_IOMYBUF | _IOSETVBUF);
                stream->_base = stream->_ptr = NULL;
                stream->_cnt = 0;
        }
}
示例#21
0
_ptiddata __cdecl _getptd_noexit (
        void
        )
{
    _ptiddata ptd;
    DWORD   TL_LastError;

    TL_LastError = GetLastError();

    /*
     * Initialize FlsGetValue function pointer in TLS
     */
    __set_flsgetvalue();

    if ( (ptd = FLS_GETVALUE(__flsindex)) == NULL ) {
        /*
         * no per-thread data structure for this thread. try to create
         * one.
         */
        if ((ptd = _calloc_crt(1, sizeof(struct _tiddata))) != NULL) {

            if (FLS_SETVALUE(__flsindex, (LPVOID)ptd) ) {

                /*
                 * Initialize of per-thread data
                 */

                _initptd(ptd,NULL);

                ptd->_tid = GetCurrentThreadId();
                ptd->_thandle = (uintptr_t)(-1);
            }
            else {

                /*
                 * Return NULL to indicate failure
                 */

                _free_crt(ptd);
                ptd = NULL;
            }
        }
    }

    SetLastError(TL_LastError);

    return(ptd);
}
示例#22
0
void __cdecl _free_locale(
        _locale_t plocinfo
        )
{
    if (plocinfo != nullptr)
    {
        __acrt_lock(__acrt_multibyte_cp_lock);
        __try
        {
            if (plocinfo->mbcinfo != nullptr &&
                    InterlockedDecrement(&(plocinfo->mbcinfo->refcount)) == 0 &&
                    plocinfo->mbcinfo != &__acrt_initial_multibyte_data )
            {
                _free_crt(plocinfo->mbcinfo);
            }
        }
        __finally
        {
            __acrt_unlock(__acrt_multibyte_cp_lock);
        }

        if (plocinfo->locinfo != nullptr)
        {
            /*
             * this portion has to be in locale lock as there may be case when
             * not this thread but some other thread is still holding to this
             * locale and is also trying to free this locale. In this case
             * we may end up leaking memory.
             */

            __acrt_lock(__acrt_locale_lock);
            __try
            {
                __acrt_release_locale_ref(plocinfo->locinfo);
                if ( (plocinfo->locinfo != nullptr) &&
                     (plocinfo->locinfo->refcount == 0) &&
                     (plocinfo->locinfo != &__acrt_initial_locale_data) )
                    __acrt_free_locale(plocinfo->locinfo);
            }
            __finally
            {
                __acrt_unlock(__acrt_locale_lock);
            }
        }
int __cdecl _texeclp (
        const _TSCHAR *filename,
        const _TSCHAR *arglist,
        ...
        )
{
#ifdef _M_IX86

        _ASSERTE(filename != NULL);
        _ASSERTE(*filename != _T('\0'));
        _ASSERTE(arglist != NULL);
        _ASSERTE(*arglist != _T('\0'));

        return(_texecvp(filename,&arglist));

#else  /* _M_IX86 */

        va_list vargs;
        _TSCHAR * argbuf[64];
        _TSCHAR ** argv;
        int result;

        _ASSERTE(filename != NULL);
        _ASSERTE(*filename != _T('\0'));
        _ASSERTE(arglist != NULL);
        _ASSERTE(*arglist != _T('\0'));

        va_start(vargs, arglist);
#ifdef WPRFLAG
        argv = _wcapture_argv(&vargs, arglist, argbuf, 64);
#else  /* WPRFLAG */
        argv = _capture_argv(&vargs, arglist, argbuf, 64);
#endif  /* WPRFLAG */
        va_end(vargs);

        result = _texecvp(filename,argbuf);
        if (argv && argv != argbuf)
            _free_crt(argv);
        return result;

#endif  /* _M_IX86 */
}
示例#24
0
static void WINAPI __dyn_tls_dtor(
    HANDLE,
    DWORD const dwReason,
    LPVOID
    )
{
    if (dwReason != DLL_THREAD_DETACH && dwReason != DLL_PROCESS_DETACH) {
        return;
    }

    CRT_WARNING_DISABLE_PUSH(22019, "Silence prefast about overflow/underflow");

    TlsDtorNode* pnext = nullptr;
    for (TlsDtorNode* pnode = dtor_list; pnode != nullptr; pnode = pnext)
    {
        for (int i = pnode->count - 1; i >= 0; --i)
        {
            if (pnode->funcs[i])
                pnode->funcs[i]();
        }
        /*
         * Free every TlsDtorNode except the original one, which is statically
         * allocated.
         */
        pnext = pnode->next;
        if (pnext)
        {
            _free_crt(pnode);
        }

        /*
         * Update the dtor_list to ensure completed destructors do not remain
         * on the list. If a destructor exits with an exception the process
         * will terminate. Windows will still invoke the TLS callback on
         * process teardown, but we do not want to re-run destructors that have
         * already run.
         */
        dtor_list = pnext;
    }
    CRT_WARNING_POP;
}
示例#25
0
文件: MLOCK.C 项目: ngphloc/agmagic
void __cdecl _mtdeletelocks(
        void
        )
{

        int locknum;

        for ( locknum = 0 ; locknum < _TOTAL_LOCKS ; locknum++ ) {

            /*
             * If the 'lock' has been created, delete it
             */
            /*
             * Delete the lock if it had been created
             */
            if ( _locktable[locknum] != NULL ) {
                if ( (locknum != _LOCKTAB_LOCK) && (locknum !=
                  _EXIT_LOCK1) && (locknum != _HEAP_LOCK) &&
                 (locknum != _SIGNAL_LOCK) )
                {
                /*
                 * Free the memory for the CritSect after deleting
                 * it.  It is okay to call free() if the heap lock
                 * is kept valid until after all calls to the heap.
                 */
                DeleteCriticalSection(_locktable[locknum]);
                _free_crt(_locktable[locknum]);
                }
            }

        }

        /*
         * Finally, clean up the special locks
         */
        DeleteCriticalSection( _locktable[_HEAP_LOCK] );
        DeleteCriticalSection( _locktable[_EXIT_LOCK1] );
        DeleteCriticalSection( _locktable[_LOCKTAB_LOCK] );
        DeleteCriticalSection( _locktable[_SIGNAL_LOCK] );

}
示例#26
0
文件: INITMON.C 项目: ngphloc/agmagic
/*
 *  Free the lconv strings.
 *  Numeric values do not need to be freed.
 */
static void __cdecl _free_lc_lconv (
        struct lconv *l
        )
{
        if (l == NULL)
                return;

        if (l->int_curr_symbol != __lconv_static_null)
        {
                _free_crt (l->int_curr_symbol);
                _free_crt (l->currency_symbol);
                _free_crt (l->mon_decimal_point);
                _free_crt (l->mon_thousands_sep);
                _free_crt (l->mon_grouping);
                _free_crt (l->positive_sign);
                _free_crt (l->negative_sign);
        }
        /* Don't need to make these pointers NULL */
}
示例#27
0
extern "C" __crt_multibyte_data* __cdecl __acrt_update_thread_multibyte_data(void)
{
        __crt_multibyte_data* ptmbci = nullptr;

        __acrt_ptd* const ptd = __acrt_getptd();
        if ((ptd->_own_locale & __globallocalestatus) == 0 || ptd->_locale_info == nullptr)
        {
            __acrt_lock(__acrt_multibyte_cp_lock);
            __try
            {
                ptmbci = ptd->_multibyte_info;
                if (ptmbci != __acrt_current_multibyte_data)
                {
                    /*
                     * Decrement the reference count in the old mbc info structure
                     * and free it, if necessary
                     */
                    if (ptmbci != nullptr &&
                        InterlockedDecrement(&ptmbci->refcount) == 0 &&
                        ptmbci != &__acrt_initial_multibyte_data)
                    {
                        /*
                         * Free it
                         */
                        _free_crt(ptmbci);
                    }

                    /*
                     * Point to the current mbc info structure and increment its
                     * reference count.
                     */
                    ptmbci = ptd->_multibyte_info = __acrt_current_multibyte_data;
                    InterlockedIncrement(&ptmbci->refcount);
                }
            }
            __finally
            {
                __acrt_unlock(__acrt_multibyte_cp_lock);
            }
        }
示例#28
0
intptr_t __cdecl _tspawnl(
    int modeflag,
    const _TSCHAR* pathname,
    const _TSCHAR* arglist,
    ...
) {
#ifdef _M_IX86
    /* validation section */
    _VALIDATE_RETURN(pathname != NULL, EINVAL, -1);
    _VALIDATE_RETURN(*pathname != _T('\0'), EINVAL, -1);
    _VALIDATE_RETURN(arglist != NULL, EINVAL, -1);
    _VALIDATE_RETURN(*arglist != _T('\0'), EINVAL, -1);
    return (_tspawnve(modeflag, pathname, &arglist, NULL));
#else  /* _M_IX86 */
    va_list vargs;
    _TSCHAR* argbuf[64];
    _TSCHAR** argv;
    intptr_t result;
    /* validation section */
    _VALIDATE_RETURN(pathname != NULL, EINVAL, -1);
    _VALIDATE_RETURN(*pathname != _T('\0'), EINVAL, -1);
    _VALIDATE_RETURN(arglist != NULL, EINVAL, -1);
    _VALIDATE_RETURN(*arglist != _T('\0'), EINVAL, -1);
    va_start(vargs, arglist);
#ifdef WPRFLAG
    argv = _wcapture_argv(&vargs, arglist, argbuf, 64);
#else  /* WPRFLAG */
    argv = _capture_argv(&vargs, arglist, argbuf, 64);
#endif  /* WPRFLAG */
    va_end(vargs);
    result = _tspawnve(modeflag, pathname, argv, NULL);

    if (argv && argv != argbuf) {
        _free_crt(argv);
    }

    return result;
#endif  /* _M_IX86 */
}
示例#29
0
文件: MLOCK.C 项目: ngphloc/agmagic
void __cdecl _lock (
        int locknum
        )
{

        PCRITICAL_SECTION pcs;


        /*
         * Create/open the lock, if necessary
         */
        if ( _locktable[locknum] == NULL ) {

            if ( (pcs = _malloc_crt(sizeof(CRITICAL_SECTION))) == NULL )
                _amsg_exit(_RT_LOCK);

            _mlock(_LOCKTAB_LOCK);  /*** WARNING: Recursive lock call ***/

            if ( _locktable[locknum] == NULL ) {
                InitializeCriticalSection(pcs);
                _locktable[locknum] = pcs;
            }
            else {
                _free_crt(pcs);
            }

            _munlock(_LOCKTAB_LOCK);
        }

        /*
         * Enter the critical section.
         */

        EnterCriticalSection( _locktable[locknum] );

}
LPVOID __cdecl __crtGetEnvironmentStringsW(
        VOID
        )
{
        static int f_use = 0;
        void *penv = NULL;
        char *pch;
        wchar_t *pwch;
        wchar_t *wbuffer;
        int total_size = 0;
        int str_size;

        /*
         * Look for unstubbed 'preferred' flavor. Otherwise use available flavor.
         * Must actually call the function to ensure it's not a stub.
         */

        if ( 0 == f_use )
        {
            if ( NULL != (penv = GetEnvironmentStringsW()) )
                f_use = USE_W;

            else if ( NULL != (penv = GetEnvironmentStringsA()) )
                f_use = USE_A;
            else
                return NULL;
        }

        /* Use "W" version */

        if ( USE_W == f_use )
        {
            if ( NULL == penv )
                if ( NULL == (penv = GetEnvironmentStringsW()) )
                    return NULL;

            /* find out how big a buffer is needed */

            pwch = penv;
            while ( *pwch != L'\0' ) {
                if ( *++pwch == L'\0' )
                    pwch++;
            }

            total_size = (char *)pwch - (char *)penv + sizeof( wchar_t );

            /* allocate the buffer */

            if ( NULL == (wbuffer = _malloc_crt( total_size )) ) {
                FreeEnvironmentStringsW( penv );
                return NULL;
            }

            /* copy environment strings to buffer */

            memcpy( wbuffer, penv, total_size );

            FreeEnvironmentStringsW( penv );

            return (LPVOID)wbuffer;
        }

        /* Use "A" version */

        if ( USE_A == f_use )
        {
            /*
             * Convert strings and return the requested information.
             */
            if ( NULL == penv )
                if ( NULL == (penv = GetEnvironmentStringsA()) )
                    return NULL;

            pch = penv;

            /* find out how big a buffer we need */
            while ( *pch != '\0' )
            {
                if ( 0 == (str_size =
                      MultiByteToWideChar( __lc_codepage,
                                           MB_PRECOMPOSED,
                                           pch,
                                           -1,
                                           NULL,
                                           0 )) )
                    return 0;

                total_size += str_size;
                pch += strlen(pch) + 1;
            }

            /* room for final NULL */
            total_size++;

            /* allocate enough space for chars */
            if ( NULL == (wbuffer = (wchar_t *)
                 _malloc_crt( total_size * sizeof( wchar_t ) )) )
            {
                FreeEnvironmentStringsA( penv );
                return NULL;
            }

            /* do the conversion */
            pch = penv;
            pwch = wbuffer;
            while (*pch != '\0')
            {
                if ( 0 == MultiByteToWideChar( __lc_codepage,
                                               MB_PRECOMPOSED,
                                               pch,
                                               -1,
                                               pwch,
                                               total_size - (pwch -
                                                 wbuffer) ) )
                {
                    _free_crt( wbuffer );
                    FreeEnvironmentStringsA( penv );
                    return NULL;
                }

                pch += strlen(pch) + 1;
                pwch += wcslen(pwch) + 1;
            }
            *pwch = L'\0';

            FreeEnvironmentStringsA( penv );

            return (LPVOID)wbuffer;

        }
        else   /* f_use is neither USE_A nor USE_W */
            return NULL;
}