Crossfire Server, Trunk  R20513
Macros | Functions
porting.c File Reference

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

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

Macros

#define MAXPATHLEN   4096
 

Functions

void make_path_to_file (const char *filename)
 Checks if any directories in the given path doesn't exist, and creates if necessary. More...
 
void remove_directory (const char *path)
 This function removes everything in the directory, and the directory itself. More...
 
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. More...
 
int strcasecmp (const char *s1, const char *s2)
 Case-insensitive comparaison of strings. More...
 
char * strcasestr (const char *s, const char *find)
 Finds a substring in a string, in a case-insensitive manner. More...
 
char * strdup (const char *str)
 Portable implementation of strdup(3). More...
 
size_t strlcpy (char *dst, const char *src, size_t size)
 Portable implementation of strlcpy(3). More...
 
int strncasecmp (const char *s1, const char *s2, int n)
 Case-insensitive comparaison of strings. More...
 
char * tempnam (const char *dir, const char *pfx)
 Portable implementation of tempnam(3). More...
 
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. More...
 

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

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

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

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

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

Here is the caller graph for this function:

int strcasecmp ( const char *  s1,
const char *  s2 
)
char* strcasestr ( const char *  s,
const char *  find 
)

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

Parameters
sstring we're searching into.
findstring we're searching for.
Returns
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:

char* strdup ( const char *  str)
size_t strlcpy ( char *  dst,
const char *  src,
size_t  size 
)

Portable implementation of strlcpy(3).

Definition at line 365 of file porting.c.

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

Case-insensitive comparaison of strings.

This seems to be lacking on some system.

Parameters
s1
s2strings to compare.
nmaximum number of chars to compare.
Returns
  • -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:

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:

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