FreeRDP
winpr/libwinpr/file/file.c File Reference
#include <winpr/config.h>
#include <winpr/debug.h>
#include <winpr/assert.h>
#include <winpr/wtypes.h>
#include <winpr/crt.h>
#include <winpr/file.h>
#include "../log.h"
#include <winpr/wlog.h>
#include <winpr/string.h>
#include "file.h"
#include <errno.h>
#include <fcntl.h>
#include <sys/file.h>
#include <sys/stat.h>
#include <sys/time.h>
#include <sys/statvfs.h>

Macros

#define TAG   WINPR_TAG("file")
 
#define MIN(x, y)   (((x) < (y)) ? (x) : (y))
 
#define STATVFS   statvfs
 

Functions

static BOOL FileIsHandled (HANDLE handle)
 
static int FileGetFd (HANDLE handle)
 
static BOOL FileCloseHandle (HANDLE handle)
 
static BOOL FileSetEndOfFile (HANDLE hFile)
 
static DWORD FileSetFilePointer (HANDLE hFile, LONG lDistanceToMove, PLONG lpDistanceToMoveHigh, DWORD dwMoveMethod)
 
static BOOL FileSetFilePointerEx (HANDLE hFile, LARGE_INTEGER liDistanceToMove, PLARGE_INTEGER lpNewFilePointer, DWORD dwMoveMethod)
 
static BOOL FileRead (PVOID Object, LPVOID lpBuffer, DWORD nNumberOfBytesToRead, LPDWORD lpNumberOfBytesRead, LPOVERLAPPED lpOverlapped)
 
static BOOL FileWrite (PVOID Object, LPCVOID lpBuffer, DWORD nNumberOfBytesToWrite, LPDWORD lpNumberOfBytesWritten, LPOVERLAPPED lpOverlapped)
 
static DWORD FileGetFileSize (HANDLE Object, LPDWORD lpFileSizeHigh)
 
static BOOL FileGetFileInformationByHandle (HANDLE hFile, LPBY_HANDLE_FILE_INFORMATION lpFileInformation)
 
static BOOL FileLockFileEx (HANDLE hFile, DWORD dwFlags, DWORD dwReserved, DWORD nNumberOfBytesToLockLow, DWORD nNumberOfBytesToLockHigh, LPOVERLAPPED lpOverlapped)
 
static BOOL FileUnlockFile (HANDLE hFile, DWORD dwFileOffsetLow, DWORD dwFileOffsetHigh, DWORD nNumberOfBytesToUnlockLow, DWORD nNumberOfBytesToUnlockHigh)
 
static BOOL FileUnlockFileEx (HANDLE hFile, DWORD dwReserved, DWORD nNumberOfBytesToUnlockLow, DWORD nNumberOfBytesToUnlockHigh, LPOVERLAPPED lpOverlapped)
 
static UINT64 FileTimeToUS (const FILETIME *ft)
 
static BOOL FileSetFileTime (HANDLE hFile, const FILETIME *lpCreationTime, const FILETIME *lpLastAccessTime, const FILETIME *lpLastWriteTime)
 
static const char * FileGetMode (DWORD dwDesiredAccess, DWORD dwCreationDisposition, BOOL *create)
 
UINT32 map_posix_err (int fs_errno)
 
static HANDLE FileCreateFileA (LPCSTR lpFileName, DWORD dwDesiredAccess, DWORD dwShareMode, LPSECURITY_ATTRIBUTES lpSecurityAttributes, DWORD dwCreationDisposition, DWORD dwFlagsAndAttributes, HANDLE hTemplateFile)
 
static BOOL IsFileDevice (LPCTSTR lpDeviceName)
 
HANDLE_CREATORGetFileHandleCreator (void)
 
static WINPR_FILE * FileHandle_New (FILE *fp)
 
HANDLE GetStdHandle (DWORD nStdHandle)
 
BOOL SetStdHandle (DWORD nStdHandle, HANDLE hHandle)
 
BOOL SetStdHandleEx (DWORD dwStdHandle, HANDLE hNewHandle, HANDLE *phOldHandle)
 
BOOL GetDiskFreeSpaceA (LPCSTR lpRootPathName, LPDWORD lpSectorsPerCluster, LPDWORD lpBytesPerSector, LPDWORD lpNumberOfFreeClusters, LPDWORD lpTotalNumberOfClusters)
 
BOOL GetDiskFreeSpaceW (LPCWSTR lpwRootPathName, LPDWORD lpSectorsPerCluster, LPDWORD lpBytesPerSector, LPDWORD lpNumberOfFreeClusters, LPDWORD lpTotalNumberOfClusters)
 
BOOL ValidFileNameComponent (LPCWSTR lpFileName)
 
HANDLE GetFileHandleForFileDescriptor (int fd)
 
FILE * winpr_fopen (const char *path, const char *mode)
 

Variables

static HANDLE_OPS fileOps
 
static HANDLE_OPS shmOps
 
static HANDLE_CREATOR _FileHandleCreator = { IsFileDevice, FileCreateFileA }
 

Macro Definition Documentation

◆ MIN

#define MIN (   x,
  y 
)    (((x) < (y)) ? (x) : (y))

◆ STATVFS

#define STATVFS   statvfs

◆ TAG

#define TAG   WINPR_TAG("file")

WinPR: Windows Portable Runtime File Functions

Copyright 2015 Thincast Technologies GmbH Copyright 2015 Bernhard Miklautz bernh.nosp@m.ard..nosp@m.mikla.nosp@m.utz@.nosp@m.thinc.nosp@m.ast..nosp@m.com Copyright 2016 David PHAM-VAN d.pha.nosp@m.mvan.nosp@m.@inuv.nosp@m.ika..nosp@m.com

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Function Documentation

◆ FileCloseHandle()

static BOOL FileCloseHandle ( HANDLE  handle)
static
Here is the call graph for this function:
Here is the caller graph for this function:

◆ FileCreateFileA()

static HANDLE FileCreateFileA ( LPCSTR  lpFileName,
DWORD  dwDesiredAccess,
DWORD  dwShareMode,
LPSECURITY_ATTRIBUTES  lpSecurityAttributes,
DWORD  dwCreationDisposition,
DWORD  dwFlagsAndAttributes,
HANDLE  hTemplateFile 
)
static
Here is the call graph for this function:

◆ FileGetFd()

static int FileGetFd ( HANDLE  handle)
static
Here is the call graph for this function:

◆ FileGetFileInformationByHandle()

static BOOL FileGetFileInformationByHandle ( HANDLE  hFile,
LPBY_HANDLE_FILE_INFORMATION  lpFileInformation 
)
static
Here is the call graph for this function:

◆ FileGetFileSize()

static DWORD FileGetFileSize ( HANDLE  Object,
LPDWORD  lpFileSizeHigh 
)
static
Here is the call graph for this function:

◆ FileGetMode()

static const char* FileGetMode ( DWORD  dwDesiredAccess,
DWORD  dwCreationDisposition,
BOOL *  create 
)
static
Here is the caller graph for this function:

◆ FileHandle_New()

static WINPR_FILE* FileHandle_New ( FILE *  fp)
static
Here is the call graph for this function:
Here is the caller graph for this function:

◆ FileIsHandled()

static BOOL FileIsHandled ( HANDLE  handle)
static
Here is the call graph for this function:
Here is the caller graph for this function:

◆ FileLockFileEx()

static BOOL FileLockFileEx ( HANDLE  hFile,
DWORD  dwFlags,
DWORD  dwReserved,
DWORD  nNumberOfBytesToLockLow,
DWORD  nNumberOfBytesToLockHigh,
LPOVERLAPPED  lpOverlapped 
)
static
Here is the call graph for this function:

◆ FileRead()

static BOOL FileRead ( PVOID  Object,
LPVOID  lpBuffer,
DWORD  nNumberOfBytesToRead,
LPDWORD  lpNumberOfBytesRead,
LPOVERLAPPED  lpOverlapped 
)
static
Here is the call graph for this function:

◆ FileSetEndOfFile()

static BOOL FileSetEndOfFile ( HANDLE  hFile)
static
Here is the call graph for this function:

◆ FileSetFilePointer()

static DWORD FileSetFilePointer ( HANDLE  hFile,
LONG  lDistanceToMove,
PLONG  lpDistanceToMoveHigh,
DWORD  dwMoveMethod 
)
static
Here is the call graph for this function:

◆ FileSetFilePointerEx()

static BOOL FileSetFilePointerEx ( HANDLE  hFile,
LARGE_INTEGER  liDistanceToMove,
PLARGE_INTEGER  lpNewFilePointer,
DWORD  dwMoveMethod 
)
static
Here is the call graph for this function:

◆ FileSetFileTime()

static BOOL FileSetFileTime ( HANDLE  hFile,
const FILETIME *  lpCreationTime,
const FILETIME *  lpLastAccessTime,
const FILETIME *  lpLastWriteTime 
)
static

◆ FileTimeToUS()

static UINT64 FileTimeToUS ( const FILETIME *  ft)
static

◆ FileUnlockFile()

static BOOL FileUnlockFile ( HANDLE  hFile,
DWORD  dwFileOffsetLow,
DWORD  dwFileOffsetHigh,
DWORD  nNumberOfBytesToUnlockLow,
DWORD  nNumberOfBytesToUnlockHigh 
)
static
Here is the call graph for this function:

◆ FileUnlockFileEx()

static BOOL FileUnlockFileEx ( HANDLE  hFile,
DWORD  dwReserved,
DWORD  nNumberOfBytesToUnlockLow,
DWORD  nNumberOfBytesToUnlockHigh,
LPOVERLAPPED  lpOverlapped 
)
static
Here is the call graph for this function:

◆ FileWrite()

static BOOL FileWrite ( PVOID  Object,
LPCVOID  lpBuffer,
DWORD  nNumberOfBytesToWrite,
LPDWORD  lpNumberOfBytesWritten,
LPOVERLAPPED  lpOverlapped 
)
static
Here is the call graph for this function:

◆ GetDiskFreeSpaceA()

BOOL GetDiskFreeSpaceA ( LPCSTR  lpRootPathName,
LPDWORD  lpSectorsPerCluster,
LPDWORD  lpBytesPerSector,
LPDWORD  lpNumberOfFreeClusters,
LPDWORD  lpTotalNumberOfClusters 
)
Here is the caller graph for this function:

◆ GetDiskFreeSpaceW()

BOOL GetDiskFreeSpaceW ( LPCWSTR  lpwRootPathName,
LPDWORD  lpSectorsPerCluster,
LPDWORD  lpBytesPerSector,
LPDWORD  lpNumberOfFreeClusters,
LPDWORD  lpTotalNumberOfClusters 
)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ GetFileHandleCreator()

HANDLE_CREATOR* GetFileHandleCreator ( void  )
Here is the caller graph for this function:

◆ GetFileHandleForFileDescriptor()

HANDLE GetFileHandleForFileDescriptor ( int  fd)
Here is the call graph for this function:

◆ GetStdHandle()

HANDLE GetStdHandle ( DWORD  nStdHandle)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ IsFileDevice()

static BOOL IsFileDevice ( LPCTSTR  lpDeviceName)
static

◆ map_posix_err()

UINT32 map_posix_err ( int  fs_errno)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ SetStdHandle()

BOOL SetStdHandle ( DWORD  nStdHandle,
HANDLE  hHandle 
)

◆ SetStdHandleEx()

BOOL SetStdHandleEx ( DWORD  dwStdHandle,
HANDLE  hNewHandle,
HANDLE *  phOldHandle 
)

◆ ValidFileNameComponent()

BOOL ValidFileNameComponent ( LPCWSTR  lpFileName)

Check if a file name component is valid.

Some file names are not valid on Windows. See "Naming Files, Paths, and Namespaces": https://msdn.microsoft.com/en-us/library/windows/desktop/aa365247(v=vs.85).aspx

Here is the caller graph for this function:

◆ winpr_fopen()

FILE* winpr_fopen ( const char *  path,
const char *  mode 
)
Here is the call graph for this function:
Here is the caller graph for this function:

Variable Documentation

◆ _FileHandleCreator

HANDLE_CREATOR _FileHandleCreator = { IsFileDevice, FileCreateFileA }
static

◆ fileOps

HANDLE_OPS fileOps
static
Initial value:
= {
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
}
if availableBytes return NULL
Definition: TPCircularBuffer.h:109
static BOOL FileIsHandled(HANDLE handle)
Definition: winpr/libwinpr/file/file.c:59
static BOOL FileLockFileEx(HANDLE hFile, DWORD dwFlags, DWORD dwReserved, DWORD nNumberOfBytesToLockLow, DWORD nNumberOfBytesToLockHigh, LPOVERLAPPED lpOverlapped)
Definition: winpr/libwinpr/file/file.c:391
static BOOL FileWrite(PVOID Object, LPCVOID lpBuffer, DWORD nNumberOfBytesToWrite, LPDWORD lpNumberOfBytesWritten, LPOVERLAPPED lpOverlapped)
Definition: winpr/libwinpr/file/file.c:243
static BOOL FileUnlockFile(HANDLE hFile, DWORD dwFileOffsetLow, DWORD dwFileOffsetHigh, DWORD nNumberOfBytesToUnlockLow, DWORD nNumberOfBytesToUnlockHigh)
Definition: winpr/libwinpr/file/file.c:464
static BOOL FileGetFileInformationByHandle(HANDLE hFile, LPBY_HANDLE_FILE_INFORMATION lpFileInformation)
Definition: winpr/libwinpr/file/file.c:326
static DWORD FileSetFilePointer(HANDLE hFile, LONG lDistanceToMove, PLONG lpDistanceToMoveHigh, DWORD dwMoveMethod)
Definition: winpr/libwinpr/file/file.c:119
static BOOL FileSetFilePointerEx(HANDLE hFile, LARGE_INTEGER liDistanceToMove, PLARGE_INTEGER lpNewFilePointer, DWORD dwMoveMethod)
Definition: winpr/libwinpr/file/file.c:164
static BOOL FileSetFileTime(HANDLE hFile, const FILETIME *lpCreationTime, const FILETIME *lpLastAccessTime, const FILETIME *lpLastWriteTime)
Definition: winpr/libwinpr/file/file.c:659
static BOOL FileCloseHandle(HANDLE handle)
Definition: winpr/libwinpr/file/file.c:74
static int FileGetFd(HANDLE handle)
Definition: winpr/libwinpr/file/file.c:64
static BOOL FileUnlockFileEx(HANDLE hFile, DWORD dwReserved, DWORD nNumberOfBytesToUnlockLow, DWORD nNumberOfBytesToUnlockHigh, LPOVERLAPPED lpOverlapped)
Definition: winpr/libwinpr/file/file.c:507
static DWORD FileGetFileSize(HANDLE Object, LPDWORD lpFileSizeHigh)
Definition: winpr/libwinpr/file/file.c:273
static BOOL FileSetEndOfFile(HANDLE hFile)
Definition: winpr/libwinpr/file/file.c:96
static BOOL FileRead(PVOID Object, LPVOID lpBuffer, DWORD nNumberOfBytesToRead, LPDWORD lpNumberOfBytesRead, LPOVERLAPPED lpOverlapped)
Definition: winpr/libwinpr/file/file.c:202

◆ shmOps