Crossfire Server, Trunk
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.


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.

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

Definition at line 162 of file porting.c.

References buf, npc_dialog::filename, llevDebug, llevError, LOG(), MAX_BUF, safe_strncpy, and SAVE_DIR_MODE.

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

+ 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.

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

Definition at line 115 of file porting.c.

References buf, closedir(), dirent, llevError, LOG(), MAX_BUF, opendir(), python_init::path, readdir(), remove_directory(), and takeitem::status.

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.

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 200 of file porting.c.

References convert::dest.

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

+ 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.

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.
A pointer to a FILE opened exclusively, or NULL if failure. It is up to the caller to properly close it.
The file will be opened read-write.
Maybe adding some ifdef for non-UNIX? I don't have any such system around to test with.

Definition at line 69 of file porting.c.

References mad_mage_user::file, npc_dialog::filename, llevError, LOG(), CFBank::open(), 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: