int __cdecl _ismbslead(
        const unsigned char *string,
        const unsigned char *current
        )
{
        if ( _ISNOTMBCP )
            return 0;

        _mlock(_MB_CP_LOCK);

        while (string <= current && *string) {
                if (_ISLEADBYTE((*string))) {
                        if (string++ == current)        /* check lead byte */
                {
                    _munlock(_MB_CP_LOCK);
                                return -1;
                }
                        if (!(*string))
                {
                    _munlock(_MB_CP_LOCK);
                                return 0;
                }
                }
                ++string;
        }

        _munlock(_MB_CP_LOCK);
        return 0;
}
Ejemplo n.º 2
0
int __cdecl _ismbstrail(
    const unsigned char *string,
    const unsigned char *current
    )
{
        if (0 == __mbcodepage)
            return 0;

        _mlock(_MB_CP_LOCK);

	while (string <= current && *string) {
		if (_ISLEADBYTE((*string))) {
			if (++string == current)	/* check trail byte */
                {
                    _munlock(_MB_CP_LOCK);
				return -1;
                }
			if (!(*string))
                {
                    _munlock(_MB_CP_LOCK);
				return 0;
                }
		}
		++string;
	}

        _munlock(_MB_CP_LOCK);
	return 0;
}
Ejemplo n.º 3
0
Archivo: time.c Proyecto: mikekap/wine
/*********************************************************************
 *      _localtime64_s (MSVCRT.@)
 */
int CDECL _localtime64_s(struct MSVCRT_tm *time, const MSVCRT___time64_t *secs)
{
    struct tm *tm;
    time_t seconds;

    if (!time || !secs || *secs < 0 || *secs > _MAX__TIME64_T)
    {
        if (time)
            write_invalid_msvcrt_tm(time);

        *MSVCRT__errno() = MSVCRT_EINVAL;
        return MSVCRT_EINVAL;
    }

    seconds = *secs;

    _mlock(_TIME_LOCK);
    if (!(tm = localtime(&seconds)))
    {
        _munlock(_TIME_LOCK);
        *MSVCRT__errno() = MSVCRT_EINVAL;
        return MSVCRT_EINVAL;
    }

    unix_tm_to_msvcrt(time, tm);
    _munlock(_TIME_LOCK);
    return 0;
}
Ejemplo n.º 4
0
int __cdecl _mbsbtype(
        const unsigned char *string,
        size_t len
        )
{
        int chartype;

        if ( _ISNOTMBCP )
            return _MBC_SINGLE;

        _mlock(_MB_CP_LOCK);

        chartype = _MBC_ILLEGAL;
        do {
            if (*string == '\0')
            {
                _munlock(_MB_CP_LOCK);
                return(_MBC_ILLEGAL);
            }

            chartype = _MBBTYPE(*string++, chartype);

        }  while (len--);

        _munlock(_MB_CP_LOCK);
        return(chartype);
}
void * __cdecl _expand_base (void * pBlock, size_t newsize)
{
    PHEADER     pHeader;
    void *      pvReturn;


    /* validate size */
    if ( newsize > _HEAP_MAXREQ )
        return NULL;

    _mlock(_HEAP_LOCK);

    //  if allocation block lies within the small-block heap,
    //  try to resize it there
    if ((pHeader = __sbh_find_block(pBlock)) != NULL)
    {
        pvReturn = NULL;
        if (newsize <= __sbh_threshold &&
                         __sbh_resize_block(pHeader, pBlock, newsize))
            pvReturn = pBlock;

        _munlock(_HEAP_LOCK);
        return pvReturn;
    }

    _munlock(_HEAP_LOCK);

    //  force nonzero size and round up to next paragraph
    if (newsize == 0)
        newsize = 1;
    newsize = (newsize + BYTES_PER_PARA - 1) & ~(BYTES_PER_PARA - 1);

    return (HeapReAlloc(_crtheap, HEAP_REALLOC_IN_PLACE_ONLY,
                                                    pBlock, newsize));
}
Ejemplo n.º 6
0
int __cdecl _chdrive (
        int drive
        )
{
        char  newdrive[3];

        if (drive < 1 || drive > 31) {
            errno = EACCES;
            _doserrno = ERROR_INVALID_DRIVE;
            return -1;
        }

        _mlock(_ENV_LOCK);

        newdrive[0] = (char)('A' + (char)drive - (char)1);
        newdrive[1] = ':';
        newdrive[2] = '\0';

        /*
         * Set new drive. If current directory on new drive exists, it
         * will become the cwd. Otherwise defaults to root directory.
         */

        if ( SetCurrentDirectory((LPSTR)newdrive) ) {
            _munlock(_ENV_LOCK);
            return 0;
        }
        else {
            _dosmaperr(GetLastError());
            _munlock(_ENV_LOCK);
            return -1;
        }
}
Ejemplo n.º 7
0
/*
 * @implemented
 */
int CDECL _pclose(FILE* file)
{
    HANDLE h;
    DWORD i;

    if (!MSVCRT_CHECK_PMT(file != NULL)) return -1;

    _mlock(_POPEN_LOCK);
    for(i=0; i<popen_handles_size; i++)
    {
        if (popen_handles[i].f == file)
            break;
    }
    if(i == popen_handles_size)
    {
        _munlock(_POPEN_LOCK);
        *_errno() = EBADF;
        return -1;
    }

    h = popen_handles[i].proc;
    popen_handles[i].f = NULL;
    _munlock(_POPEN_LOCK);

    fclose(file);
    if(WaitForSingleObject(h, INFINITE)==WAIT_FAILED || !GetExitCodeProcess(h, &i))
    {
        _dosmaperr(GetLastError());
        CloseHandle(h);
        return -1;
    }

    CloseHandle(h);
    return i;
}
unsigned char * __cdecl _mbslwr(
    unsigned char *string
    )
{
        unsigned char *cp;

        _mlock(_MB_CP_LOCK);

        for (cp=string; *cp; cp++)
        {
            if (_ISLEADBYTE(*cp))
            {

#if defined (_WIN32)

                int retval;
                unsigned char ret[4];

                if ((retval = __crtLCMapStringA(__mblcid,
                                                LCMAP_LOWERCASE,
                                                cp,
                                                2,
                                                ret,
                                                2,
                                                __mbcodepage,
                                                TRUE)) == 0)
                {
                    _munlock(_MB_CP_LOCK);
                    return NULL;
                }

                *cp = ret[0];

                if (retval > 1)
                    *(++cp) = ret[1];

#else  /* defined (_WIN32) */

                int mbval = ((*cp) << 8) + *(cp+1);

                cp++;
                if (     mbval >= _MBUPPERLOW1
                    &&   mbval <= _MBUPPERHIGH1 )
                    *cp += _MBCASEDIFF1;

                else if (mbval >= _MBUPPERLOW2
                    &&   mbval <= _MBUPPERHIGH2 )
                    *cp += _MBCASEDIFF2;
#endif  /* defined (_WIN32) */

            }
            else
                /* single byte, macro version */
                *cp = (unsigned char) _mbbtolower(*cp);
        }

        _munlock(_MB_CP_LOCK);
        return string ;
}
int __cdecl _mbsnbcmp(
        const unsigned char *s1,
        const unsigned char *s2,
        size_t n
        )
{
        unsigned short c1, c2;

        if (n==0)
                return(0);

        if ( _ISNOTMBCP )
            return strncmp(s1, s2, n);

        _mlock(_MB_CP_LOCK);

        while (n--) {

                c1 = *s1++;
                if (_ISLEADBYTE(c1)) {
                        if (n==0)
                {
                    c1 = 0; /* 'naked' lead - end of string */
                    c2 = _ISLEADBYTE(*s2) ? 0 : *s2;
                    goto test;
                }
                        c1 = ( (*s1 == '\0') ? 0 : ((c1<<8) | *s1++) );
                }

                c2 = *s2++;
                if (_ISLEADBYTE(c2)) {
                        if (n==0)
                {
                    c2 = 0; /* 'naked' lead - end of string */
                    goto test;
                }
                --n;
                        c2 = ( (*s2 == '\0') ? 0 : ((c2<<8) | *s2++) );
                }
test:
                if (c1 != c2)
            {
                _munlock(_MB_CP_LOCK);
                        return( (c1 > c2) ? 1 : -1);
            }

                if (c1 == 0)
            {
                _munlock(_MB_CP_LOCK);
                        return(0);
            }
        }

        _munlock(_MB_CP_LOCK);
        return(0);
}
Ejemplo n.º 10
0
static BOOL WINAPI ctrlevent_capture (
        DWORD CtrlType
        )
{
        _PHNDLR ctrl_action;
        _PHNDLR *pctrl_action;
        int sigcode;

        _mlock(_SIGNAL_LOCK);

        /*
         * Identify the type of event and fetch the corresponding action
         * description.
         */

        if ( CtrlType == CTRL_C_EVENT ) {
                ctrl_action = *(pctrl_action = &ctrlc_action);
                sigcode = SIGINT;
        }
        else {
                ctrl_action = *(pctrl_action = &ctrlbreak_action);
                sigcode = SIGBREAK;
        }

        if ( ctrl_action == SIG_DFL ) {
                /*
                 * return FALSE, indicating the event has NOT been handled
                 */
                _munlock(_SIGNAL_LOCK);
                return FALSE;
        }

        if ( ctrl_action != SIG_IGN ) {
                /*
                 * Reset the action to be SIG_DFL and call the user's handler.
                 */
                *pctrl_action = SIG_DFL;
                _munlock(_SIGNAL_LOCK);
                (*ctrl_action)(sigcode);
        }
        else
                /*
                 * SIG_IGN - nothing special to do except release the lock
                 */
                _munlock(_SIGNAL_LOCK);

        /*
         * Return TRUE, indicating the event has been handled (which may
         * mean it's being ignored)
         */
        return TRUE;
}
Ejemplo n.º 11
0
unsigned char * __cdecl _mbsdec(
    const unsigned char *string,
    const unsigned char *current
    )
{
	const unsigned char *temp;

	if (string >= current)
		return(NULL);

        if (0 == __mbcodepage)
            return (unsigned char *)--current;

        _mlock(_MB_CP_LOCK);

	temp = current - 1;

/*
 *  If (current-1) returns true from _ISLEADBTYE, it is a trail byte, because
 *  it is not a legal single byte MBCS character.  Therefore, is so, return
 *  (current-2) because it is the trailbyte's lead.
 */

	if (_ISLEADBYTE(*temp))
        {
            _munlock(_MB_CP_LOCK);
		return (unsigned char *)(temp - 1);
        }

/*
 *  It is unknown whether (current - 1) is a single byte character or a
 *  trail.  Now decrement temp until
 *	a)  The beginning of the string is reached, or
 *	b)  A non-lead byte (either single or trail) is found.
 *  The difference between (current-1) and temp is the number of non-single
 *  byte characters preceding (current-1).  There are two cases for this:
 *	a)  (current - temp) is odd, and
 *	b)  (current - temp) is even.
 *  If odd, then there are an odd number of "lead bytes" preceding the
 *  single/trail byte (current - 1), indicating that it is a trail byte.
 *  If even, then there are an even number of "lead bytes" preceding the
 *  single/trail byte (current - 1), indicating a single byte character.
 */

	while ((string <= --temp) && (_ISLEADBYTE(*temp)))
		;

        _munlock(_MB_CP_LOCK);
	return (unsigned char *)(current - 1 - ((current - temp) & 0x01) );

}
Ejemplo n.º 12
0
/***
*  _cputws() - _cputws() writes a wide char string to console.
*
*  Purpose:
*       Writes a wide char string to console.
*
*  Entry:
*       str:    pointer to string
*  Exit:
*       returns 0 if sucessful. Nonzero if unsucessful
*
*******************************************************************************/
int _CRTIMP __cdecl _cputws(
        const wchar_t *str
        )
{
    size_t len;
    int retval = 0;

    _VALIDATE_CLEAR_OSSERR_RETURN((str != NULL), EINVAL, -1);

    len = wcslen(str);
    _mlock(_CONIO_LOCK);
    __try {
    while(len--)
    {
        if ( _putwch_nolock(*str++) == WEOF)
        {
            retval = -1;
            break;
        }
    }
    }
    __finally {
            _munlock(_CONIO_LOCK);
    }
    return retval;
}
Ejemplo n.º 13
0
Archivo: time.c Proyecto: mikekap/wine
/*********************************************************************
 *		_tzset (MSVCRT.@)
 */
void CDECL MSVCRT__tzset(void)
{
    tzset();
#if defined(HAVE_TIMEZONE) && defined(HAVE_DAYLIGHT)
    MSVCRT___daylight = daylight;
    MSVCRT___timezone = timezone;
#else
    {
        static const time_t seconds_in_year = (365 * 24 + 6) * 3600;
        time_t t;
        struct tm *tmp;
        int zone_january, zone_july;

        _mlock(_TIME_LOCK);
        t = (time(NULL) / seconds_in_year) * seconds_in_year;
        tmp = localtime(&t);
        zone_january = -tmp->tm_gmtoff;
        t += seconds_in_year / 2;
        tmp = localtime(&t);
        zone_july = -tmp->tm_gmtoff;
        _munlock(_TIME_LOCK);

        MSVCRT___daylight = (zone_january != zone_july);
        MSVCRT___timezone = max(zone_january, zone_july);
    }
#endif
    lstrcpynA(tzname_std, tzname[0], sizeof(tzname_std));
    tzname_std[sizeof(tzname_std) - 1] = '\0';
    lstrcpynA(tzname_dst, tzname[1], sizeof(tzname_dst));
    tzname_dst[sizeof(tzname_dst) - 1] = '\0';
}
int __cdecl _heapadd (
        void * block,
        size_t size
        )
{
        int retval;

        /*
         * Validate user's input. Note that _GRANULARITY must be a power
         * of 2 for the tests below to be valid!
         */

        if ( (size == 0) ||
             ((unsigned)block & (_GRANULARITY - 1)) ||
             (size & (_GRANULARITY - 1))
           )
                return(-1);

        /*
         * Add the block to the heap.
         */

        _mlock(_HEAP_LOCK);
        retval = _heap_addblock(block, size);
        _munlock(_HEAP_LOCK);

        return(retval);

}
Ejemplo n.º 15
0
__RELIABILITY_CONTRACT
void __clean_type_info_names_internal(__type_info_node * p_type_info_root_node)
{
    bool _MustReleaseLock = false;
    __PREPARE_CONSTRAINED_REGION
    __TRY
        __BEGIN_CONSTRAINED_REGION
            System::Threading::Thread::BeginThreadAffinity();
            _mlock(_TYPEINFO_LOCK);
            _MustReleaseLock = true;
        __END_CONSTRAINED_REGION
        /*
         * Loop through the link list and delete all the entries.
         */
        for (__type_info_node *pNode = p_type_info_root_node->next, *tmpNode=NULL;
             pNode!=NULL;
             pNode = tmpNode)
        {
            tmpNode = pNode->next;
            _free_base(pNode->memPtr);
            _free_base(pNode);
        }
    __FINALLY
        if (_MustReleaseLock)
        {
            _munlock(_TYPEINFO_LOCK);
            System::Threading::Thread::EndThreadAffinity();
        }
    __END_TRY_FINALLY
}
Ejemplo n.º 16
0
void operator delete(
        void *pUserData
        )
{
        _CrtMemBlockHeader * pHead;

        RTCCALLBACK(_RTC_Free_hook, (pUserData, 0));

        if (pUserData == NULL)
            return;

        _mlock(_HEAP_LOCK);  /* block other threads */
        __TRY

            /* get a pointer to memory block header */
            pHead = pHdr(pUserData);

             /* verify block type */
            _ASSERTE(_BLOCK_TYPE_IS_VALID(pHead->nBlockUse));

            _free_dbg( pUserData, pHead->nBlockUse );

        __FINALLY
            _munlock(_HEAP_LOCK);  /* release other threads */
        __END_TRY_FINALLY

        return;
}
Ejemplo n.º 17
0
int __cdecl _cputs (
        const char *string
        )
{
        ULONG num_written;
        int error = 0;                   /* error occurred? */

        _mlock(_CONIO_LOCK);             /* acquire console lock */

        /*
         * _confh, the handle to the console output, is created the
         * first time that either _putch() or _cputs() is called.
         */

        if (_confh == -2)
            __initconout();

        /* write string to console file handle */

        if ( (_confh == -1) || !WriteConsole( (HANDLE)_confh,
                                              (LPVOID)string,
                                              strlen(string),
                                              &num_written,
                                              NULL )
           )
                /* return error indicator */
                error = -1;

        _munlock(_CONIO_LOCK);          /* release console lock */

        return error;
}
Ejemplo n.º 18
0
unsigned char * __cdecl _mbsrchr(
    const unsigned char *str,
    unsigned int c
)
{
    char *r = NULL;
    unsigned int cc;

    if (0 == __mbcodepage)
        return strrchr(str, c);

    _mlock(_MB_CP_LOCK);

    do {
        cc = *str;
        if (_ISLEADBYTE(cc)) {
            if(*++str) {
                if (c == ((cc<<8)|*str))
                    r = (char *)str - 1;
            }
            else if(!r)
                /* return pointer to '\0' */
                r = (char *)str;
        }
        else if (c == cc)
            r = (char *)str;
    }
    while (*str++);

    _munlock(_MB_CP_LOCK);
    return(r);
}
Ejemplo n.º 19
0
unsigned char * __cdecl _mbsnbcat(
    unsigned char *dst,
    const unsigned char *src,
    size_t cnt
    )
{
	unsigned char *start;

	if (!cnt)
		return(dst);

        if (0 == __mbcodepage)
            return strncat(dst, src, cnt);

        _mlock(_MB_CP_LOCK);

	start = dst;
	while (*dst++)
                ;
	--dst;		// dst now points to end of dst string


	/* if last char in string is a lead byte, back up pointer */

        if (_MBSBTYPE(start, (int) ((dst - start) - 1)) == _MBC_LEAD)
		--dst;

	/* copy over the characters */

	while (cnt--) {

		if (_ISLEADBYTE(*src)) {
			*dst++ = *src++;
			if (!cnt--) {	/* write nul if cnt exhausted */
				dst[-1] = '\0';
				break;
			}
			if ((*dst++ = *src++)=='\0') { /* or if no trail byte */
				dst[-2] = '\0';
                                break;
                        }
                }

		else if ((*dst++ = *src++) == '\0')
                        break;

        }

	/* enter final nul, if necessary */

	if (_MBSBTYPE(start, (int) ((dst - start) - 1)) == _MBC_LEAD)
	    dst[-1] = '\0';
	else
	    *dst = '\0';


        _munlock(_MB_CP_LOCK);
	return(start);
}
Ejemplo n.º 20
0
void __cdecl _heap_print_desc(void)
{
	_mlock(_HEAP_LOCK);

	_heap_print_desc_lk();

	_munlock(_HEAP_LOCK);
}
Ejemplo n.º 21
0
/*
 * type_info::~type_info() has been moved from typinfo.cpp to typname.cpp.
 * The reason being we need to clean the link list when destructing the
 * object.
 */
__RELIABILITY_CONTRACT
void type_info::_Type_info_dtor(type_info *_This)
{
    bool _MustReleaseLock = false;
    __PREPARE_CONSTRAINED_REGION
    __TRY
        __BEGIN_CONSTRAINED_REGION
            System::Threading::Thread::BeginThreadAffinity();
            _mlock(_TYPEINFO_LOCK);
            _MustReleaseLock = true;
        __END_CONSTRAINED_REGION
        if (_This->_m_data != NULL) {
            /*
             * We should first check the global link list before freeing _m_data.
             * Ideally we should always find _m_data in the linklist.
             */
            for(__type_info_node *pNode = __type_info_root_node.next,*tmpNode = &__type_info_root_node;
                pNode!=NULL;
                pNode = tmpNode)
            {
                if(pNode->memPtr == _This->_m_data) {
                    /*
                     * Once the node is found, delete it from the list and
                     * free the memroy.
                     */
                    tmpNode->next = pNode->next;
                    _free_base(pNode);
                    break;
                }
                tmpNode=pNode;
                /*
                 * This should always be true. i.e. we should always find _m_data
                 * int the global linklist.
                 */
                _ASSERTE(pNode->next != NULL);
            }
            /*
             * Ideally we should be freeing this in the loop but just in case
             * something is wrong, we make sure we don't leak the memory.
             */
            _free_base(_This->_m_data);

            /*
             * Note that the same object can exist in different threads. This
             * means to be very sure, we must always set _m_data to NULL so that
             * we don't land in the _ASSERTE in the previous lines.
             */
            _This->_m_data = NULL;
        }
    __FINALLY
        if (_MustReleaseLock)
        {
            _munlock(_TYPEINFO_LOCK);
            System::Threading::Thread::EndThreadAffinity();
        }
    __END_TRY_FINALLY

}
Ejemplo n.º 22
0
unsigned char * __cdecl _mbsspnp(
    const unsigned char *string,
    const unsigned char *charset
    )

#endif

{
        unsigned char *p, *q;

#ifndef _RETURN_PTR
        if (0 == __mbcodepage)
            return strspn(string, charset);
#else
        if (0 == __mbcodepage)
        {
            size_t retval;
            retval = strspn(string, charset);
            return (unsigned char *)(*(string + retval) ? string + retval : NULL);
        }
#endif
        _mlock(_MB_CP_LOCK);

	/* loop through the string to be inspected */
        for (q = (char *)string; *q; q++) {

		/* loop through the charset */
                for (p = (char *)charset; *p; p++) {

			if (_ISLEADBYTE(*p)) {
				if (((*p == *q) && (p[1] == q[1])) || p[1] == '\0')
					break;
				p++;
			}

			else
				if (*p == *q)
					break;
                }

		if (*p == '\0') 	/* end of charset? */
			break;		/* yes, no match on this char */

		if (_ISLEADBYTE(*q))
                        if (*++q == '\0')
                                break;
        }

        _munlock(_MB_CP_LOCK);

#ifndef _RETURN_PTR
	return((size_t) (q - string));		/* index */
#else
	return((*q) ? q : NULL);	/* pointer */
#endif


}
Ejemplo n.º 23
0
void __cdecl _print_tiddata (
        unsigned long tid
        )
{
        int i;                  /* loop index */
        int threadcnt;          /* number of active threads */

        /*
         * lock the _ptd[] table.
         */
        _mlock(_THREADDATA_LOCK);

        /*
         * see if caller want's all threads or just a specific one.
         */
        if (tid == (unsigned long) -1L) {
                /*
                 * caller want's all threads!
                 */
                for ( i = threadcnt = 0 ; i < 1024 ; i++ )
                        /*
                         * print out the fields of *_ptd[i] for each entry
                         * bound to an active thread (i.e., for each i st
                         * _ptd[i] non-NULL). also, count up the total number
                         * of active threads.
                         */
                        if ( _ptd[i] != NULL ) {
                                threadcnt++;
                                _print_tiddata1(_ptd[i]);
                        }

                printf("\nTHERE ARE %d CURRENTLY ACTIVE THREADS!\n", threadcnt);
        }
        else {
                /*
                 * caller just interested in a particular thread. search
                 * the _ptd[] table inline because a call to _getptd[] would
                 * have unpleasant side effects if tid is not (or no longer)
                 * valid.
                 */
                for ( i = 0 ; (i < 1024) && ((_ptd[i] == NULL) ||
                    (_ptd[i] == (_ptiddata)1L) || (_ptd[i]->_tid != tid)) ;
                    i++ ) ;

                if ( i < 1024 )
                        _print_tiddata1(_ptd[i]);
                else
                        printf("\nTID INVALID OR THREAD HAS TERMINATED!\n");
        }

        /*
         * unlock the _ptd[] table.
         */
        _munlock(_THREADDATA_LOCK);

}
int __cdecl _mbsncmp(
        const unsigned char *s1,
        const unsigned char *s2,
        size_t n
        )
{
        unsigned short c1, c2;

        if (n==0)
            return(0);

        if ( _ISNOTMBCP )
            return strncmp(s1, s2, n);

        _mlock(_MB_CP_LOCK);

        while (n--) {

            c1 = *s1++;
            if (_ISLEADBYTE(c1))
                c1 = ( (*s1 == '\0') ? 0 : ((c1<<8) | *s1++) );

            c2 = *s2++;
            if (_ISLEADBYTE(c2))
                c2 = ( (*s2 == '\0') ? 0 : ((c2<<8) | *s2++) );

            if (c1 != c2)
            {
                _munlock(_MB_CP_LOCK);
                return( (c1 > c2) ? 1 : -1);
            }

            if (c1 == 0)
            {
                _munlock(_MB_CP_LOCK);
                return(0);
            }
        }

        _munlock(_MB_CP_LOCK);
        return(0);
}
Ejemplo n.º 25
0
static BOOL WINAPI ctrlevent_capture (
        DWORD CtrlType
        )
{
        _PHNDLR ctrl_action;
        _PHNDLR *pctrl_action;
        int sigcode;

        _mlock(_SIGNAL_LOCK);
        __try {

        /*
         * Identify the type of event and fetch the corresponding action
         * description.
         */

        if ( CtrlType == CTRL_C_EVENT ) {
                pctrl_action = &ctrlc_action;
                ctrl_action = (_PHNDLR) _decode_pointer(*pctrl_action);
                sigcode = SIGINT;
        }
        else {
                pctrl_action = &ctrlbreak_action;
                ctrl_action = (_PHNDLR) _decode_pointer(*pctrl_action);
                sigcode = SIGBREAK;
        }

        if ( !(ctrl_action == SIG_DFL) && !(ctrl_action == SIG_IGN) )
                /*
                 * Reset the action to be SIG_DFL
                 */
                *pctrl_action = (_PHNDLR) _encoded_null();

        }
        __finally {
                _munlock(_SIGNAL_LOCK);
        }

        if ( ctrl_action == SIG_DFL )
                /*
                 * return FALSE, indicating the event has NOT been handled
                 */
                return FALSE;

        if ( ctrl_action != SIG_IGN ) {
                (*ctrl_action)(sigcode);
        }

        /*
         * Return TRUE, indicating the event has been handled (which may
         * mean it's being ignored)
         */
        return TRUE;
}
Ejemplo n.º 26
0
Archivo: time.c Proyecto: mikekap/wine
/*********************************************************************
 *      _localtime64 (MSVCRT.@)
 */
struct MSVCRT_tm* CDECL MSVCRT__localtime64(const MSVCRT___time64_t* secs)
{
    struct tm *tm;
    thread_data_t *data;
    time_t seconds = *secs;

    if (seconds < 0) return NULL;

    _mlock(_TIME_LOCK);
    if (!(tm = localtime( &seconds))) {
        _munlock(_TIME_LOCK);
        return NULL;
    }

    data = msvcrt_get_thread_data();
    unix_tm_to_msvcrt( &data->time_buffer, tm );
    _munlock(_TIME_LOCK);

    return &data->time_buffer;
}
Ejemplo n.º 27
0
void __cdecl _heap_print_regions(void)
{
	/* lock the heap
	 */
	_mlock(_HEAP_LOCK);

	_heap_print_regions_lk();

	/* release the heap lock
	 */
	_munlock(_HEAP_LOCK);
}
Ejemplo n.º 28
0
void __cdecl _heap_print_emptylist(void)
{
	/* lock the heap
	 */
	_mlock(_HEAP_LOCK);

	_heap_print_emptylist_lk();

	/* release the heap lock
	 */
	_munlock(_HEAP_LOCK);
}
Ejemplo n.º 29
0
void __cdecl _free_base (void * pBlock)
{
        PHEADER     pHeader;


        if (pBlock == NULL)
            return;

        _mlock(_HEAP_LOCK);

        if ((pHeader = __sbh_find_block(pBlock)) != NULL)
        {
            __sbh_free_block(pHeader, pBlock);
            _munlock(_HEAP_LOCK);
        }
        else
        {
            _munlock(_HEAP_LOCK);
            HeapFree(_crtheap, 0, pBlock);
        }
}
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);
}