naev 0.10.4
Functions | Variables
nfile.c File Reference

Handles read/write abstractions to the users directory. More...

#include "nfile.h"
#include "array.h"
#include "conf.h"
#include "log.h"
#include "nstring.h"

Go to the source code of this file.

Functions

const char * nfile_configPath (void)
 Gets Naev's config path (for user preferences such as conf.lua) More...
 
const char * nfile_cachePath (void)
 Gets Naev's cache path (for cached data such as generated textures) More...
 
 if (strncpy(path==NULL)
 
 for (;p >=opath;p--)
 
 for (;p[0] !='\0';p++)
 
 if (!nfile_dirExists(opath))
 
int nfile_dirMakeExist (const char *path)
 Creates a directory if it doesn't exist. More...
 
int nfile_dirExists (const char *path)
 Checks to see if a directory exists. More...
 
int nfile_fileExists (const char *path)
 Checks to see if a file exists. More...
 
int nfile_backupIfExists (const char *path)
 Backup a file, if it exists. More...
 
int nfile_copyIfExists (const char *file1, const char *file2)
 Copy a file, if it exists. More...
 
char * nfile_readFile (size_t *filesize, const char *path)
 Tries to read a file. More...
 
int nfile_touch (const char *path)
 Tries to create the file if it doesn't exist. More...
 
int nfile_writeFile (const char *data, size_t len, const char *path)
 Tries to write a file. More...
 
int nfile_isSeparator (uint32_t c)
 Checks to see if a character is used to separate files in a path. More...
 
int _nfile_concatPaths (char buf[static 1], int maxLength, const char path[static 1],...)
 

Variables

static char naev_configPath [PATH_MAX] = "\0"
 
static char naev_cachePath [PATH_MAX] = "\0"
 
char * p
 
size_t len
 
int ret
 
 return
 

Detailed Description

Handles read/write abstractions to the users directory.

Todo:
Add support for Windows and macOS.

Definition in file nfile.c.

Function Documentation

◆ _nfile_concatPaths()

int _nfile_concatPaths ( char  buf[static 1],
int  maxLength,
const char  path[static 1],
  ... 
)

Definition at line 592 of file nfile.c.

◆ for() [1/2]

for ( ;p >=opath;p--  )

Definition at line 225 of file nfile.c.

◆ for() [2/2]

for ( ;p !  [0] = '\0'; p++)

Definition at line 240 of file nfile.c.

◆ if() [1/2]

if ( nfile_dirExistsopath)

Definition at line 251 of file nfile.c.

◆ if() [2/2]

if ( strncpy(  path = = NULL)

Definition at line 211 of file nfile.c.

◆ nfile_backupIfExists()

int nfile_backupIfExists ( const char *  path)

Backup a file, if it exists.

Parameters
pathprintf formatted string pointing to the file to backup.
Returns
0 on success, or if file does not exist, -1 on error.

Definition at line 343 of file nfile.c.

◆ nfile_cachePath()

const char * nfile_cachePath ( void  )

Gets Naev's cache path (for cached data such as generated textures)

Returns
The xdg cache path.

Definition at line 159 of file nfile.c.

◆ nfile_configPath()

const char * nfile_configPath ( void  )

Gets Naev's config path (for user preferences such as conf.lua)

Returns
The xdg config path.

Definition at line 116 of file nfile.c.

◆ nfile_copyIfExists()

int nfile_copyIfExists ( const char *  file1,
const char *  file2 
)

Copy a file, if it exists.

Parameters
file1Filename to copy from.
file2Filename to copy to.
Returns
0 on success, or if file1 does not exist, -1 on error.

Definition at line 365 of file nfile.c.

◆ nfile_dirExists()

int nfile_dirExists ( const char *  path)

Checks to see if a directory exists.

Parameters
pathPath to directory
Returns
1 on exists, 0 otherwise

Definition at line 296 of file nfile.c.

◆ nfile_dirMakeExist()

int nfile_dirMakeExist ( const char *  path)

Creates a directory if it doesn't exist.

Parameters
pathPath to create directory if it doesn't exist.
Returns
0 on success.

Definition at line 267 of file nfile.c.

◆ nfile_fileExists()

int nfile_fileExists ( const char *  path)

Checks to see if a file exists.

Parameters
pathstring pointing to the file to check for existence.
Returns
1 if file exists, 0 if it doesn't or -1 on error.

Definition at line 316 of file nfile.c.

◆ nfile_isSeparator()

int nfile_isSeparator ( uint32_t  c)

Checks to see if a character is used to separate files in a path.

Parameters
cCharacter to check.
Returns
1 if is a separator, 0 otherwise.

Definition at line 581 of file nfile.c.

◆ nfile_readFile()

char * nfile_readFile ( size_t *  filesize,
const char *  path 
)

Tries to read a file.

Parameters
filesizeStores the size of the file.
pathPath of the file.
Returns
The file data.

Definition at line 427 of file nfile.c.

◆ nfile_touch()

int nfile_touch ( const char *  path)

Tries to create the file if it doesn't exist.

Parameters
pathPath of the file to create.

Definition at line 512 of file nfile.c.

◆ nfile_writeFile()

int nfile_writeFile ( const char *  data,
size_t  len,
const char *  path 
)

Tries to write a file.

Parameters
dataPointer to the data to write.
lenThe size of data.
pathPath of the file.
Returns
0 on success, -1 on error.

Definition at line 538 of file nfile.c.

Variable Documentation

◆ len

size_t len

Definition at line 208 of file nfile.c.

◆ naev_cachePath

char naev_cachePath[PATH_MAX] = "\0"
static

Store Naev's cache path.

Definition at line 153 of file nfile.c.

◆ naev_configPath

char naev_configPath[PATH_MAX] = "\0"
static

Store Naev's config path.

Definition at line 110 of file nfile.c.

◆ p

p
Initial value:
{
char opath[PATH_MAX]
#define PATH_MAX
Definition: naev.h:50

Definition at line 207 of file nfile.c.

◆ ret

int ret

Definition at line 209 of file nfile.c.

◆ return

return

Definition at line 257 of file nfile.c.