Example #1
0
/*----------------------------------------------------------------------*
                             rtp_wfile_rename
 *----------------------------------------------------------------------*/
int rtp_wfile_rename (unsigned short * name, unsigned short * newname)
{
#if (_WIN32_WINNT) >= 0x0400
#ifdef RTP_DEBUG
    int result;
    /* ----------------------------------- */
    /*  Clear the error state by setting   */
    /*  to 0.                              */
    /* ----------------------------------- */
    SetLastError (0);
#endif

    name    = _rtp_unicode_name_to_winname (name);
    newname = _rtp_unicode_name_to_winname (newname);

    if (_wrename ((const unsigned short *)name, (const unsigned short *)newname) != 0)
    {
#ifdef RTP_DEBUG
        result = GetLastError();
        RTP_DEBUG_OUTPUT_STR("rtp_wfile_rename: error returned ");
        RTP_DEBUG_OUTPUT_INT(result);
        RTP_DEBUG_OUTPUT_STR(".\n");
#endif
        return (-1);
    }
    return (0);
#endif
	return (-1);
}
Example #2
0
/*----------------------------------------------------------------------*
                           rtp_wfile_get_free
 *----------------------------------------------------------------------*/
int rtp_wfile_get_free (unsigned short * name, unsigned long *total, unsigned long *free,
                       unsigned long *sectors_per_unit, unsigned short *bytes_per_sector)
{
#if (_WIN32_WINNT) >= 0x0400
struct _diskfree_t dtable_entry = {0};
int tmpDrive;
int result;

#ifdef RTP_DEBUG
    SetLastError (0);
#endif

    name = _rtp_unicode_name_to_winname (name);
	tmpDrive = towlower((int) name[0]);
	tmpDrive = (tmpDrive - 'a') + 1;
    result = _getdiskfree (tmpDrive, &dtable_entry);

    if (result != 0)
    {
#ifdef RTP_DEBUG
		RTP_DEBUG_OUTPUT_ERRNO("rtp_wfile_get_free:");
#endif
        return (-1);
    }

    *total = (unsigned long) dtable_entry.total_clusters;
    *free  = (unsigned long) dtable_entry.avail_clusters;
    *sectors_per_unit = (unsigned long)  dtable_entry.sectors_per_cluster;
    *bytes_per_sector = (unsigned short) dtable_entry.bytes_per_sector;


    return (0);
#endif
	return (-1);
}
Example #3
0
/*----------------------------------------------------------------------*
                             rtp_wfile_gfirst
 *----------------------------------------------------------------------*/
int rtp_wfile_gfirst (void ** dirobj, unsigned short * name)
{
#if (_WIN32_WINNT) >= 0x0400
WFSOBJ* winDirObj;

#ifdef RTP_DEBUG
  
    SetLastError (0);
#endif

    winDirObj = (WFSOBJ*) malloc(sizeof(WFSOBJ));
    memset(winDirObj, 0, sizeof(WFSOBJ));

    name = _rtp_unicode_name_to_winname(name);
    winDirObj->fsObject.attrib = _A_NORMAL | _A_SUBDIR;
    winDirObj->handle = _wfindfirst((const unsigned short *) name, &(winDirObj->fsObject));
    if (winDirObj->handle == (long)(-1))
    {
        rtp_free (winDirObj);
#ifdef RTP_DEBUG
		RTP_DEBUG_OUTPUT_ERRNO("rtp_wfile_gfirst:");
#endif
        return (-1);
    }

    *dirobj = (void*) winDirObj;
    return (0);
#endif
	return (-1);
}
Example #4
0
/*----------------------------------------------------------------------*
                             rtp_wfile_rename
 *----------------------------------------------------------------------*/
int rtp_wfile_rename (unsigned short * name, unsigned short * newname)
{
#if (_WIN32_WINNT) >= 0x0400
#ifdef RTP_DEBUG
    SetLastError (0);
#endif

    name    = _rtp_unicode_name_to_winname (name);
    newname = _rtp_unicode_name_to_winname (newname);

    if (_wrename ((const unsigned short *)name, (const unsigned short *)newname) != 0)
    {
#ifdef RTP_DEBUG
		RTP_DEBUG_OUTPUT_ERRNO("rtp_wfile_rename:");
#endif
        return (-1);
    }
    return (0);
#endif
	return (-1);
}
Example #5
0
/*----------------------------------------------------------------------*
                               rtp_wfile_open
 *----------------------------------------------------------------------*/
int rtp_wfile_open (RTP_HANDLE  * fdPtr, const unsigned short * name, unsigned short flag, unsigned short mode)
{

#if (_WIN32_WINNT) >= 0x0400

long fileHandle;
int result;

#ifdef RTP_DEBUG
    /* ----------------------------------- */
    /*  Clear the error state by setting   */
    /*  to 0.                              */
    /* ----------------------------------- */
    SetLastError(0);
#endif

    name = (unsigned short *)_rtp_unicode_name_to_winname ((unsigned short *) name);
    fileHandle = (long) _wopen (name, _rtp_flag_to_operation(flag), _rtp_mode_to_permission(mode));

    if (fileHandle == (-1))
    {
        result = GetLastError();
        /* ----------------------------------- */
        /*  If trying to open a directory or   */
        /*  opening a read only file with      */
        /*  write privilages.  This can be     */
        /*  non-fatal if doing an open to      */
        /*  determine the existance of a       */
        /*  directory.                         */
        /* ----------------------------------- */
        if (result == ERROR_ACCESS_DENIED)
        {
#ifdef RTP_DEBUG
            RTP_DEBUG_OUTPUT_STR("rtp_wfile_open: non-fatal error returned ");
            RTP_DEBUG_OUTPUT_INT(result);
            RTP_DEBUG_OUTPUT_STR(".\n");
#endif
            return (-2);
        }
#ifdef RTP_DEBUG
        RTP_DEBUG_OUTPUT_STR("rtp_wfile_open: error returned ");
        RTP_DEBUG_OUTPUT_INT(result);
        RTP_DEBUG_OUTPUT_STR(".\n");
#endif
        return (-1);
    }
    *fdPtr = (RTP_HANDLE) fileHandle;
    return (0);

#endif
	return (-1);
}
Example #6
0
/*----------------------------------------------------------------------*
                           rtp_wfile_chmode
 *----------------------------------------------------------------------*/
int rtp_wfile_chmode (unsigned short * name, unsigned char attributes)
{
#if (_WIN32_WINNT) >= 0x0400
int winmode;

#ifdef RTP_DEBUG
    int result;
    /* ----------------------------------- */
    /*  Clear the error state by setting   */
    /*  to 0.                              */
    /* ----------------------------------- */
    SetLastError (0);
#endif

    winmode  = 0;
    winmode |= (attributes & RTP_FILE_ATTRIB_RDONLY)  ? FILE_ATTRIBUTE_READONLY  : 0;
    winmode |= (attributes & RTP_FILE_ATTRIB_ARCHIVE) ? FILE_ATTRIBUTE_ARCHIVE   : 0;
    winmode |= (attributes & RTP_FILE_ATTRIB_HIDDEN)  ? FILE_ATTRIBUTE_HIDDEN    : 0;
    winmode |= (attributes & RTP_FILE_ATTRIB_SYSTEM)  ? FILE_ATTRIBUTE_SYSTEM    : 0;
    
	/* ----------------------------------- */
    /*  If no attributes are specified,    */
	/*  set to normal, which is 0x80, not  */
	/*  0x00                               */
    /* ----------------------------------- */
	if (winmode == 0)  
	{
		winmode = FILE_ATTRIBUTE_NORMAL;
	}

        name = _rtp_unicode_name_to_winname (name);

    if (SetFileAttributesW((const unsigned short *)name, winmode) < 0)
    {
#ifdef RTP_DEBUG
        result = GetLastError();
        RTP_DEBUG_OUTPUT_STR("rtp_wfile_chmode: error returned ");
        RTP_DEBUG_OUTPUT_INT(result);
        RTP_DEBUG_OUTPUT_STR(".\n");
#endif
        return (-1);
    }
    return (0);
#endif
	return (-1);
}
Example #7
0
/*----------------------------------------------------------------------*
                           rtp_wfile_get_free
 *----------------------------------------------------------------------*/
int rtp_wfile_get_free (unsigned short * name, unsigned long *total, unsigned long *free,
                       unsigned long *sectors_per_unit, unsigned short *bytes_per_sector)
{
#if (_WIN32_WINNT) >= 0x0400
struct _diskfree_t dtable_entry = {0};
int tmpDrive;
int result;

#ifdef RTP_DEBUG
    /* ----------------------------------- */
    /*  Clear the error state by setting   */
    /*  to 0.                              */
    /* ----------------------------------- */
    SetLastError (0);
#endif

    name = _rtp_unicode_name_to_winname (name);
	tmpDrive = towlower((int) name[0]);
	tmpDrive = (tmpDrive - 'a') + 1;
    result = _getdiskfree (tmpDrive, &dtable_entry);

    if (result != 0)
    {
#ifdef RTP_DEBUG
        result = GetLastError();
        RTP_DEBUG_OUTPUT_STR("rtp_wfile_get_free: error returned ");
        RTP_DEBUG_OUTPUT_INT(result);
        RTP_DEBUG_OUTPUT_STR(".\n");
#endif
        return (-1);
    }

    *total = (unsigned long) dtable_entry.total_clusters;
    *free  = (unsigned long) dtable_entry.avail_clusters;
    *sectors_per_unit = (unsigned long)  dtable_entry.sectors_per_cluster;
    *bytes_per_sector = (unsigned short) dtable_entry.bytes_per_sector;


    return (0);
#endif
	return (-1);
}
Example #8
0
/*----------------------------------------------------------------------*
                             rtp_wfile_gfirst
 *----------------------------------------------------------------------*/
int rtp_wfile_gfirst (void ** dirobj, unsigned short * name)
{
#if (_WIN32_WINNT) >= 0x0400
WFSOBJ* winDirObj;

#ifdef RTP_DEBUG
    int result;
    /* ----------------------------------- */
    /*  Clear the error state by setting   */
    /*  to 0.                              */
    /* ----------------------------------- */
    SetLastError (0);
#endif

    winDirObj = (WFSOBJ*) malloc(sizeof(WFSOBJ));
    memset(winDirObj, 0, sizeof(WFSOBJ));

    name = _rtp_unicode_name_to_winname(name);
    winDirObj->fsObject.attrib = _A_NORMAL | _A_SUBDIR;
    winDirObj->handle = _wfindfirst((const unsigned short *) name, &(winDirObj->fsObject));
    if (winDirObj->handle == (long)(-1))
    {
        rtp_free (winDirObj);
#ifdef RTP_DEBUG
        result = GetLastError();
        RTP_DEBUG_OUTPUT_STR("rtp_wfile_gfirst: error returned ");
        RTP_DEBUG_OUTPUT_INT(result);
        RTP_DEBUG_OUTPUT_STR(".\n");
#endif
        return (-1);
    }

    *dirobj = (void*) winDirObj;
    return (0);
#endif
	return (-1);
}