Skip to content
Snippets Groups Projects
dos_fs.c 38.2 KiB
Newer Older
Alexandre Julliard's avatar
Alexandre Julliard committed
/*************************************************************************
 *           FindFirstFile16   (KERNEL.413)
 */
HANDLE16 FindFirstFile16( LPCSTR path, WIN32_FIND_DATA32A *data )
{
    HGLOBAL16 handle;
    FIND_FIRST_INFO *info;
    LPCSTR ptr;

    if (!path) return 0;
    if (!(ptr = DOSFS_GetUnixFileName( path, FALSE )))
        return INVALID_HANDLE_VALUE16;
    if (!(handle = GlobalAlloc16( GMEM_MOVEABLE, sizeof(FIND_FIRST_INFO) )))
        return INVALID_HANDLE_VALUE16;
    info = (FIND_FIRST_INFO *)GlobalLock16( handle );
    info->path = HEAP_strdupA( SystemHeap, 0, ptr );
    info->mask = strrchr( info->path, '/' );
    *(info->mask++) = '\0';
    if (path[0] && (path[1] == ':')) info->drive = toupper(*path) - 'A';
    else info->drive = DRIVE_GetCurrentDrive();
    info->skip = 0;
    GlobalUnlock16( handle );
    if (!FindNextFile16( handle, data ))
    {
        FindClose16( handle );
        DOS_ERROR( ER_NoMoreFiles, EC_MediaError, SA_Abort, EL_Disk );
        return INVALID_HANDLE_VALUE16;
    }
    return handle;
}


/*************************************************************************
 *           FindFirstFile32A   (KERNEL32.123)
 */
HANDLE32 FindFirstFile32A( LPCSTR path, WIN32_FIND_DATA32A *data )
{
    HANDLE32 handle = FindFirstFile16( path, data );
    if (handle == INVALID_HANDLE_VALUE16) return INVALID_HANDLE_VALUE32;
    return handle;
}


/*************************************************************************
 *           FindFirstFile32W   (KERNEL32.124)
 */
HANDLE32 FindFirstFile32W( LPCWSTR path, WIN32_FIND_DATA32W *data )
{
    WIN32_FIND_DATA32A dataA;
    LPSTR pathA = HEAP_strdupWtoA( GetProcessHeap(), 0, path );
    HANDLE32 handle = FindFirstFile32A( pathA, &dataA );
    HeapFree( GetProcessHeap(), 0, pathA );
    if (handle != INVALID_HANDLE_VALUE32)
    {
        data->dwFileAttributes = dataA.dwFileAttributes;
        data->ftCreationTime   = dataA.ftCreationTime;
        data->ftLastAccessTime = dataA.ftLastAccessTime;
        data->ftLastWriteTime  = dataA.ftLastWriteTime;
        data->nFileSizeHigh    = dataA.nFileSizeHigh;
        data->nFileSizeLow     = dataA.nFileSizeLow;
        lstrcpyAtoW( data->cFileName, dataA.cFileName );
        lstrcpyAtoW( data->cAlternateFileName, dataA.cAlternateFileName );
    }
    return handle;
}


/*************************************************************************
 *           FindNextFile16   (KERNEL.414)
 */
BOOL16 FindNextFile16( HANDLE16 handle, WIN32_FIND_DATA32A *data )
{
    FIND_FIRST_INFO *info;
    int count;

    if (!(info = (FIND_FIRST_INFO *)GlobalLock16( handle )))
    {
        DOS_ERROR( ER_InvalidHandle, EC_ProgramError, SA_Abort, EL_Disk );
        return FALSE;
    }
    GlobalUnlock16( handle );
    if (!info->path)
    {
        DOS_ERROR( ER_NoMoreFiles, EC_MediaError, SA_Abort, EL_Disk );
        return FALSE;
    }
    if (!(count = DOSFS_FindNext( info->path, NULL, info->mask, info->drive,
                                  0xff, info->skip, data )))
    {
        HeapFree( SystemHeap, 0, info->path );
        info->path = info->mask = NULL;
        DOS_ERROR( ER_NoMoreFiles, EC_MediaError, SA_Abort, EL_Disk );
        return FALSE;
    }
    info->skip += count;
    return TRUE;
}


/*************************************************************************
 *           FindNextFile32A   (KERNEL32.126)
 */
BOOL32 FindNextFile32A( HANDLE32 handle, WIN32_FIND_DATA32A *data )
{
    return FindNextFile16( handle, data );
}


/*************************************************************************
 *           FindNextFile32W   (KERNEL32.127)
 */
BOOL32 FindNextFile32W( HANDLE32 handle, WIN32_FIND_DATA32W *data )
{
    WIN32_FIND_DATA32A dataA;
    if (!FindNextFile32A( handle, &dataA )) return FALSE;
    data->dwFileAttributes = dataA.dwFileAttributes;
    data->ftCreationTime   = dataA.ftCreationTime;
    data->ftLastAccessTime = dataA.ftLastAccessTime;
    data->ftLastWriteTime  = dataA.ftLastWriteTime;
    data->nFileSizeHigh    = dataA.nFileSizeHigh;
    data->nFileSizeLow     = dataA.nFileSizeLow;
    lstrcpyAtoW( data->cFileName, dataA.cFileName );
    lstrcpyAtoW( data->cAlternateFileName, dataA.cAlternateFileName );
    return TRUE;
}


/*************************************************************************
 *           FindClose16   (KERNEL.415)
 */
BOOL16 FindClose16( HANDLE16 handle )
{
    FIND_FIRST_INFO *info;

    if ((handle == INVALID_HANDLE_VALUE16) ||
        !(info = (FIND_FIRST_INFO *)GlobalLock16( handle )))
    {
        DOS_ERROR( ER_InvalidHandle, EC_ProgramError, SA_Abort, EL_Disk );
        return FALSE;
    }
    if (info->path) HeapFree( SystemHeap, 0, info->path );
    GlobalUnlock16( handle );
    GlobalFree16( handle );
    return TRUE;
}


/*************************************************************************
 *           FindClose32   (KERNEL32.119)
 */
BOOL32 FindClose32( HANDLE32 handle )
{
    return FindClose16( (HANDLE16)handle );
}


Alexandre Julliard's avatar
Alexandre Julliard committed
/***********************************************************************
Alexandre Julliard's avatar
Alexandre Julliard committed
 *           GetShortPathName32A   (KERNEL32.271)
Alexandre Julliard's avatar
Alexandre Julliard committed
 */
DWORD GetShortPathName32A( LPCSTR longpath, LPSTR shortpath, DWORD shortlen )
{
    LPCSTR dostruename;

    dprintf_dosfs( stddeb, "GetShortPathName32A(%s,%p,%ld)\n",
                   longpath, shortpath, shortlen );

Alexandre Julliard's avatar
Alexandre Julliard committed
    dostruename = DOSFS_GetDosTrueName( longpath, TRUE );
Alexandre Julliard's avatar
Alexandre Julliard committed
    lstrcpyn32A( shortpath, dostruename, shortlen );
    return strlen(dostruename);
}


/***********************************************************************
 *           GetShortPathNameW   (KERNEL32.272)
 */
DWORD GetShortPathName32W( LPCWSTR longpath, LPWSTR shortpath, DWORD shortlen )
{
Alexandre Julliard's avatar
Alexandre Julliard committed
    LPSTR longpatha = HEAP_strdupWtoA( GetProcessHeap(), 0, longpath );
Alexandre Julliard's avatar
Alexandre Julliard committed
    LPCSTR dostruename = DOSFS_GetDosTrueName( longpatha, TRUE );
Alexandre Julliard's avatar
Alexandre Julliard committed
    HeapFree( GetProcessHeap(), 0, longpatha );
Alexandre Julliard's avatar
Alexandre Julliard committed
    lstrcpynAtoW( shortpath, dostruename, shortlen );
    return strlen(dostruename);
}
Alexandre Julliard's avatar
Alexandre Julliard committed
/***********************************************************************
 *           GetFullPathNameA   (KERNEL32.272)
 */
Alexandre Julliard's avatar
Alexandre Julliard committed
DWORD GetFullPathName32A( LPCSTR fn, DWORD buflen, LPSTR buf, LPSTR *lastpart)
{
Alexandre Julliard's avatar
Alexandre Julliard committed
	dprintf_file(stddeb,"GetFullPathNameA(%s)\n",fn);
	/* FIXME */
Alexandre Julliard's avatar
Alexandre Julliard committed
        if (buf) {
Alexandre Julliard's avatar
Alexandre Julliard committed
            lstrcpyn32A(buf,fn,buflen);
Alexandre Julliard's avatar
Alexandre Julliard committed
            if (lastpart) {
		*lastpart = strrchr(buf,'\\');
		if (!*lastpart) *lastpart=buf;
	    }
Alexandre Julliard's avatar
Alexandre Julliard committed
	}
Alexandre Julliard's avatar
Alexandre Julliard committed
	return strlen(fn);
}
Alexandre Julliard's avatar
Alexandre Julliard committed
/***********************************************************************
 *           GetFullPathName32W   (KERNEL32.273)
 */
DWORD GetFullPathName32W(LPCWSTR fn,DWORD buflen,LPWSTR buf,LPWSTR *lastpart) {
	LPWSTR  x;

	dprintf_file(stddeb,"GetFullPathNameW(%p)\n",fn);
	/* FIXME */
	if (buf) {
		lstrcpyn32W(buf,fn,buflen);
		if (lastpart) {
			x = buf+lstrlen32W(buf)-1;
			while (x>=buf && *x!='\\')
			x--;
			if (x>=buf)
				*lastpart=x;
			else
				*lastpart=buf;
		}
	}
	return lstrlen32W(fn);
}

Alexandre Julliard's avatar
Alexandre Julliard committed

/***********************************************************************
 *           DosDateTimeToFileTime   (KERNEL32.76)
 */
BOOL32 DosDateTimeToFileTime( WORD fatdate, WORD fattime, LPFILETIME ft )
{
    time_t unixtime = DOSFS_DosDateTimeToUnixTime(fatdate,fattime);
    DOSFS_UnixTimeToFileTime(unixtime,ft);
    return TRUE;
}


/***********************************************************************
 *           FileTimeToDosDateTime   (KERNEL32.111)
 */
Alexandre Julliard's avatar
Alexandre Julliard committed
BOOL32 FileTimeToDosDateTime( const FILETIME *ft, LPWORD fatdate,
                              LPWORD fattime )
Alexandre Julliard's avatar
Alexandre Julliard committed
{
    time_t unixtime = DOSFS_FileTimeToUnixTime(ft);
    DOSFS_ToDosDateTime(unixtime,fatdate,fattime);
    return TRUE;
}


/***********************************************************************
 *           LocalFileTimeToFileTime   (KERNEL32.373)
 */
Alexandre Julliard's avatar
Alexandre Julliard committed
BOOL32 LocalFileTimeToFileTime( const FILETIME *localft, LPFILETIME utcft )
Alexandre Julliard's avatar
Alexandre Julliard committed
{
    struct tm *xtm;

    /* convert from local to UTC. Perhaps not correct. FIXME */
    xtm = gmtime((time_t*)&(localft->dwLowDateTime));
    utcft->dwLowDateTime  = mktime(xtm);
    utcft->dwHighDateTime = 0;
    return TRUE; 
}


/***********************************************************************
 *           FileTimeToLocalFileTime   (KERNEL32.112)
 */
Alexandre Julliard's avatar
Alexandre Julliard committed
BOOL32 FileTimeToLocalFileTime( const FILETIME *utcft, LPFILETIME localft )
Alexandre Julliard's avatar
Alexandre Julliard committed
{
    struct tm *xtm;

    /* convert from UTC to local. Perhaps not correct. FIXME */
    xtm = localtime((time_t*)&(utcft->dwLowDateTime));
    localft->dwLowDateTime  = mktime(xtm);
    localft->dwHighDateTime = 0;
    return TRUE; 
}


/***********************************************************************
 *           FileTimeToSystemTime   (KERNEL32.113)
 */
Alexandre Julliard's avatar
Alexandre Julliard committed
BOOL32 FileTimeToSystemTime( const FILETIME *ft, LPSYSTEMTIME syst )
Alexandre Julliard's avatar
Alexandre Julliard committed
{
    struct tm *xtm;
    time_t xtime = DOSFS_FileTimeToUnixTime(ft);
    xtm = gmtime(&xtime);
    syst->wYear      = xtm->tm_year;
    syst->wMonth     = xtm->tm_mon;
    syst->wDayOfWeek = xtm->tm_wday;
    syst->wDay	     = xtm->tm_mday;
    syst->wHour	     = xtm->tm_hour;
    syst->wMinute    = xtm->tm_min;
    syst->wSecond    = xtm->tm_sec;
    syst->wMilliseconds	= 0; /* FIXME */
    return TRUE; 
}


/***********************************************************************
 *           SystemTimeToFileTime   (KERNEL32.526)
 */
Alexandre Julliard's avatar
Alexandre Julliard committed
BOOL32 SystemTimeToFileTime( const SYSTEMTIME *syst, LPFILETIME ft )
Alexandre Julliard's avatar
Alexandre Julliard committed
{
    struct tm xtm;

    xtm.tm_year	= syst->wYear;
    xtm.tm_mon	= syst->wMonth;
    xtm.tm_wday	= syst->wDayOfWeek;
    xtm.tm_mday	= syst->wDay;
    xtm.tm_hour	= syst->wHour;
    xtm.tm_min	= syst->wMinute;
    xtm.tm_sec	= syst->wSecond;
    DOSFS_UnixTimeToFileTime(mktime(&xtm),ft);
    return TRUE; 
}