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


#define MAXPATHLEN   4096


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)
int strcasecmp (const char *s1, const char *s2)
char * strcasestr (const char *s, const char *find)
char * strdup (const char *str)
size_t strlcpy (char *dst, const char *src, size_t size)
int strncasecmp (const char *s1, const char *s2, int n)
char * tempnam (const char *dir, const char *pfx)
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.

Macro Definition Documentation


#define MAXPATHLEN   4096

Referenced by tempnam().

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

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

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

Definition at line 154 of file porting.c.

References closedir(), dirent::d_name, llevError, LOG(), MAX_BUF, opendir(), readdir(), remove_directory(), S_ISDIR, snprintf, 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.

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 346 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:

◆ strcasecmp()

int strcasecmp ( const char *  s1,
const char *  s2 

◆ strcasestr()

char* strcasestr ( const char *  s,
const char *  find 

Finds a substring in a string, in a case-insensitive manner.

sstring we're searching into.
findstring we're searching for.
pointer to first occurrence of find in s, NULL if not found.

Definition at line 284 of file porting.c.

References strncasecmp(), and tolower.

+ Here is the call graph for this function:

◆ strdup()

◆ strlcpy()

◆ strncasecmp()

int strncasecmp ( const char *  s1,
const char *  s2,
int  n 

Case-insensitive comparaison of strings.

This seems to be lacking on some system.

s2strings to compare.
nmaximum number of chars to compare.
  • -1 if s1 is less than s2
  • 0 if s1 equals s2
  • 1 if s1 is greater than s2

Definition at line 224 of file porting.c.

References tolower.

Referenced by examine(), find_player_options(), find_skill_by_name(), init_experience(), init_stats(), learn_skill(), object_matches_string(), strcasestr(), and use_skill().

+ Here is the caller graph for this function:

◆ tempnam()

char* tempnam ( const char *  dir,
const char *  pfx 

Portable implementation of tempnam(3).

Do not use this function for new code, use tempnam_secure() instead.

Used to generate temporary unique name.

Definition at line 52 of file porting.c.

References F_OK, getpid, MAXPATHLEN, and snprintf.

Referenced by save_map(), and tempnam_secure().

+ Here is the caller graph for this function:

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

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

Referenced by save_player().

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