[ Home ]

file.h File Reference

Access methods to file system services. More...

#include <stdio.h>
#include <time.h>
#include "../common/platform.h"
#include "../common/num_type.h"

Include dependency graph for file.h:

This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  filestats

Defines

#define FA_ARCH   BIT( 0 )
#define FA_HIDDEN   BIT( 1 )
#define FA_RDONLY   BIT( 2 )
#define FA_DIR   BIT( 3 )
#define FA_SYSTEM   BIT( 4 )

Functions

W32 UnixTimeToDosTime (time_t *t)
 Converts Unix time_t into DOS format.
SW32 FS_FileLength (FILE *filestream)
 Calculate file length.
SW32 FS_FileRead (void *ptr, size_t size, size_t nmemb, FILE *stream)
 Reads data from binary file stream.
SW32 FS_FileOpen (const char *filename, FILE **file)
 Open a file stream.
SW32 FS_FileLoad (const char *path, void **buffer)
 Load a file into memory.
wtBoolean FS_DeleteFile (const char *filename)
 Deletes an existing file.
wtBoolean FS_CreateDirectory (const char *dirname)
 Creates a new directory.
wtBoolean FS_RemoveDirectory (const char *pathname)
 Deletes an existing empty directory.
wtBoolean FS_ChangeCurrentDirectory (const char *path)
 Changes the current directory.
char * FS_GetCurrentDirectory (void)
 Gets the current working directory.
wtBoolean FS_CompareFileAttributes (const char *path, W32 musthave, W32 canthave)
 Compare directory and file attributes.
wtBoolean FS_GetFileAttributes (const char *filename, struct filestats *fs)
 Retrieves attributes for a specified file or directory.
char * FS_FindFirst (const char *path)
 Searches a directory for a file or subdirectory with a name that matches a specific name.
char * FS_FindNext (void)
 Continues a file search from a previous call to the FS_FindFirst function.
void FS_FindClose (void)
 Closes the search handle.
char * FS_getFileName (char *path)
 Returns file name from path string.
void FS_RemoveExtension (const char *in, char *out)
 Removes file extension from path string.
char * FS_getFileExtension (const char *in)
 Returns file extension from path string.
wtBoolean FS_getFileBase (const char *in, char *out, W32 size_out)
 Returns base file name from path string.
wtBoolean FS_getPath (const char *in, char *out, W32 size_out)
 Returns path from full path.


Detailed Description

Access methods to file system services.

Author:
Michael Liebscher
Date:
2006-2007

Function Documentation

wtBoolean FS_ChangeCurrentDirectory ( const char *  path  ) 

Changes the current directory.

Parameters:
[in] path Pointer to a NUL-terminated string that specifies the path to the new directory.
Returns:
On success nonzero, otherwise zero.

Here is the caller graph for this function:

wtBoolean FS_CompareFileAttributes ( const char *  path,
W32  musthave,
W32  canthave 
)

Compare directory and file attributes.

Parameters:
[in] path Specifies the path to compare file attributes.
[in] musthave File or directory must have these attributes.
[in] canthave File or directory can not have these attributes.
Returns:
On success true, otherwise false.

Here is the caller graph for this function:

wtBoolean FS_CreateDirectory ( const char *  dirname  ) 

Creates a new directory.

Parameters:
[in] dirname Pointer to a NUL-terminated string that specifies the path of the directory to be created.
Returns:
On success true, otherwise false.

Here is the caller graph for this function:

wtBoolean FS_DeleteFile ( const char *  filename  ) 

Deletes an existing file.

Parameters:
[in] filename Pointer to a NUL-terminated string that specifies the file to be deleted.
Returns:
If successful the return value is nonzero, otherwise zero.

Here is the caller graph for this function:

SW32 FS_FileLength ( FILE *  stream  ) 

Calculate file length.

Parameters:
[in] filestream Pointer to valid FILE structure.
Returns:
Length of the file in bytes on success, otherwise -1.

Here is the caller graph for this function:

SW32 FS_FileLoad ( const char *  path,
void **  buffer 
)

Load a file into memory.

Parameters:
[in] path File name to load.
[in,out] buffer Buffer to hold data
Returns:
On success file length in bytes, otherwise -1. Returned data is NUL-terminated.
Note:
Caller is responsible for freeing buffered data. Data is also NUL-terminated.

Here is the call graph for this function:

Here is the caller graph for this function:

SW32 FS_FileOpen ( const char *  filename,
FILE **  file 
)

Open a file stream.

Parameters:
[in] filename Name of file to open.
[out] file FILE pointer.
Returns:
On success length of the file in bytes, otherwise -1.

Here is the call graph for this function:

Here is the caller graph for this function:

SW32 FS_FileRead ( void *  ptr,
size_t  size,
size_t  nmemb,
FILE *  stream 
)

Reads data from binary file stream.

Parameters:
[in,out] ptr Storage location.
[in] size Size of object in bytes.
[in] nmemb Number of objects to read.
[in] stream Stream to read from.
Returns:
Length of the file in bytes on success, otherwise -1.

Here is the caller graph for this function:

char* FS_FindFirst ( const char *  path  ) 

Searches a directory for a file or subdirectory with a name that matches a specific name.

Parameters:
[in] path Pointer to a NUL-terminated string that specifies a valid directory or path and file name that can contain wildcard characters.
Returns:
On success string of file name or directory, otherwise NULL.
Note:
Caller is responsible for freeing allocated memory block by calling MM_FREE.
Parameters:
[in] path Pointer to a NUL-terminated string that specifies a valid directory or path and file name that can contain wildcard characters.
Returns:
On success string of file name or directory, otherwise NULL.

Here is the call graph for this function:

Here is the caller graph for this function:

char* FS_FindNext ( void   ) 

Continues a file search from a previous call to the FS_FindFirst function.

Returns:
On success string of file name or directory, otherwise NULL.

Here is the call graph for this function:

Here is the caller graph for this function:

char* FS_GetCurrentDirectory ( void   ) 

Gets the current working directory.

Returns:
If the function succeeds, a pointer to a NUL-terminated string. Otherwise NULL.
Note:
Caller is responsible for freeing allocated memory.

wtBoolean FS_GetFileAttributes ( const char *  filename,
struct filestats *  fs 
)

Retrieves attributes for a specified file or directory.

Parameters:
[in] filename Pointer to a NUL-terminated string that specifies a file or directory.
[in] fs Pointer to a filestats structure that receives the attribute information.
Returns:
On success true, otherwise false.

Here is the call graph for this function:

Here is the caller graph for this function:

wtBoolean FS_getFileBase ( const char *  in,
char *  out,
W32  size_out 
)

Returns base file name from path string.

Parameters:
[in] in Path to get file extension from.
[in,out] out File name.
[in] size_out Size of out buffer in bytes.
Returns:
On success true, otherwise false.

Here is the call graph for this function:

char* FS_getFileExtension ( const char *  in  ) 

Returns file extension from path string.

Parameters:
[in] in Path to get file extension from.
Returns:
Pointer to file extension, otherwise NULL.
Note:
Extension cannot be longer than 31 characters.

char* FS_getFileName ( char *  path  ) 

Returns file name from path string.

Parameters:
[in] path Path to get file name from.
Returns:
Pointer to start of file name, otherwise NULL.

wtBoolean FS_getPath ( const char *  in,
char *  out,
W32  size_out 
)

Returns path from full path.

Parameters:
[in] in Path with file name.
[in,out] out path.
[in] size_out Size of out buffer in bytes.
Returns:
On success true, otherwise false.

Here is the call graph for this function:

wtBoolean FS_RemoveDirectory ( const char *  pathname  ) 

Deletes an existing empty directory.

Parameters:
[in] dirname Pointer to a NUL-terminated string that specifies the directory to be deleted.
Returns:
If successful the return value is nonzero, otherwise zero.

Here is the caller graph for this function:

void FS_RemoveExtension ( const char *  in,
char *  out 
)

Removes file extension from path string.

Parameters:
[in] in Path to remove file extension.
[in] out Pointer to hold path string.
Returns:
Nothing.

W32 UnixTimeToDosTime ( time_t *  t  ) 

Converts Unix time_t into DOS format.

Parameters:
[in] t unix time to convert.
Returns:
Unix time_t in DOS format, rounded up to the next two second boundary.

Here is the caller graph for this function: