Crossfire Server, Trunk  R22010
porting.c File Reference
#include <assert.h>
#include <ctype.h>
#include <errno.h>
#include <fcntl.h>
#include <stdarg.h>
#include <stdlib.h>
#include <string.h>
#include <sys/param.h>
#include <sys/stat.h>
#include <sys/wait.h>
#include "global.h"
+ Include dependency graph for porting.c:

Go to the source code of this file.

Functions

void make_path_to_file (const char *filename)
 
void remove_directory (const char *path)
 
void safe_strcat (char *dest, const char *orig, size_t *curlen, size_t maxlen)
 
size_t strlcpy (char *dst, const char *src, size_t size)
 
FILE * tempnam_secure (const char *dir, const char *pfx, char **filename)
 

Detailed Description

This file contains various functions that are not really unique for crossfire, but rather provides what should be standard functions for systems that do not have them. In this way, most of the nasty system dependent stuff is contained here, with the program calling these functions.

Definition in file porting.c.

Function Documentation

◆ make_path_to_file()

void make_path_to_file ( const char *  filename)

Checks if any directories in the given path doesn't exist, and creates if necessary.

Parameters
filenamefile path we'll want to access. Can be NULL.
Note
will LOG() to debug and error.

Definition at line 316 of file porting.c.

References buf, llevDebug, llevError, LOG(), MAX_BUF, mkdir, S_ISDIR, safe_strncpy, and SAVE_DIR_MODE.

Referenced by apply_race_and_class(), create_destination(), key_change_class(), process_map(), save_map(), save_player(), and write_map_page().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ remove_directory()

void remove_directory ( const char *  path)

This function removes everything in the directory, and the directory itself.

Errors are LOG() to error level.

Parameters
pathdirectory to remove.
Note
will fail if any file has a name starting by .

Definition at line 156 of file porting.c.

References buf, closedir(), dirent::d_name, llevError, LOG(), MAX_BUF, opendir(), readdir(), remove_directory(), S_ISDIR, snprintf, strcasecmp(), strncasecmp(), tolower, and unlink.

Referenced by delete_character(), and remove_directory().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ safe_strcat()

void safe_strcat ( char *  dest,
const char *  orig,
size_t *  curlen,
size_t  maxlen 
)

Simple function we use below to keep adding to the same string but also make sure we don't overwrite that string.

Parameters
deststring to append to.
origstring to append.
[out]curlencurrent length of dest. Will be updated by this function.
maxlenmaximum length of dest buffer.

Definition at line 350 of file porting.c.

Referenced by display_motd(), query_base_name(), query_name(), query_short_name(), send_new_char_info(), send_news(), send_rules(), and spellbook_type_describe().

+ Here is the caller graph for this function:

◆ strlcpy()

◆ tempnam_secure()

FILE* tempnam_secure ( const char *  dir,
const char *  pfx,
char **  filename 
)

A replacement for the tempnam_local() function since that one is not very secure. This one will open the file in an atomic way on platforms where it is possible.

Parameters
dirDirectory where to create the file. Can be NULL, in which case NULL is returned.
pfxPrefix to create unique name. Can be NULL.
filenameThis should be a pointer to a char*, the function will overwrite the char* with the name of the resulting file. Must be freed by caller. Value is unchanged if the function returns NULL.
Returns
A pointer to a FILE opened exclusively, or NULL if failure. It is up to the caller to properly close it.
Note
The file will be opened read-write.
Todo:
Maybe adding some ifdef for non-UNIX? I don't have any such system around to test with.

Definition at line 110 of file porting.c.

References llevError, LOG(), S_IRUSR, and S_IWUSR.

Referenced by save_player().

+ Here is the call graph for this function:
+ Here is the caller graph for this function: