Atrinik Server 2.5
Functions | Variables
server/porting.c File Reference
#include <global.h>

Go to the source code of this file.

Functions

char * tempnam_local (const char *dir, const char *pfx)
char * strdup_local (const char *str)
char * strerror_local (int errnum)
unsigned long isqrt (unsigned long n)
static FILE * open_and_uncompress_file (const char *ext, const char *uncompressor, const char *name, int flag, int *compressed)
FILE * open_and_uncompress (const char *name, int flag, int *compressed)
void close_and_delete (FILE *fp, int compressed)
void make_path_to_file (char *filename)
const char * strcasestr_local (const char *s, const char *find)

Variables

static uint32 curtmp = 0
char * uncomp [NROF_COMPRESS_METHODS][3]

Detailed Description

This file contains various functions that are not really unique for Atrinik, 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

void close_and_delete ( FILE *  fp,
int  compressed 
)

Closes specified file.

Parameters:
fpFile to close.
compressedWhether the file was compressed or not. Set by open_and_uncompress().

Definition at line 303 of file porting.c.

unsigned long isqrt ( unsigned long  n)

Computes the integer square root.

Parameters:
nNumber of which to compute the root.
Returns:
Integer square root.

Definition at line 118 of file porting.c.

void make_path_to_file ( 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.

Definition at line 319 of file porting.c.

FILE* open_and_uncompress ( const char *  name,
int  flag,
int *  compressed 
)

open_and_uncompress() first searches for the original filename. If it exists, then it opens it and returns the file-pointer.

Parameters:
nameThe base file name without compression extension.
flagOnly used for compressed files:
  • If set, uncompress and open the file
  • If unset, uncompress the file via pipe
[out]compressedSet to zero if the file was uncompressed
Returns:
Pointer to opened file, NULL on failure.
Note:
Will set ::errno if an error occurs.

Definition at line 279 of file porting.c.

static FILE* open_and_uncompress_file ( const char *  ext,
const char *  uncompressor,
const char *  name,
int  flag,
int *  compressed 
) [static]

Open and possibly uncompress a file.

Parameters:
extThe extension if the file is compressed.
uncompressorThe command to uncompress the file if the file is compressed.
nameThe base file name without compression extension.
flagOnly used for compressed files:
  • If set, uncompress and open the file
  • If unset, uncompress the file via pipe
[out]compressedSet to zero if the file was uncompressed.
Returns:
Pointer to opened file, NULL on failure.
Note:
Will set ::errno if an error occurs.

Definition at line 172 of file porting.c.

const char* strcasestr_local ( const char *  s,
const char *  find 
)

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

Parameters:
sString we're searching in.
findString we're searching for.
Returns:
Pointer to first occurrence of find in s, NULL if not found.

Definition at line 353 of file porting.c.

char* strdup_local ( const char *  str)

A replacement of strdup(), since it's not defined at some UNIX variants.

Parameters:
strString to duplicate.
Returns:
Copy, needs to be freed by caller. NULL on memory allocation error.

Definition at line 87 of file porting.c.

char* strerror_local ( int  errnum)

Takes an error number and returns a string with a description of the error.

Parameters:
errnumThe error number.
Returns:
The description of the error.

Definition at line 105 of file porting.c.

char* tempnam_local ( const char *  dir,
const char *  pfx 
)

A replacement for the tempnam() function since it's not defined at some UNIX variants.

Parameters:
dirDirectory where to create the file. Can be NULL, in which case NULL is returned.
pfxprefix to create unique name. Can be NULL.
Returns:
Path to temporary file, or NULL if failure. Must be freed by caller.

Definition at line 47 of file porting.c.


Variable Documentation

uint32 curtmp = 0 [static]

Used to generate temporary unique name.

Definition at line 37 of file porting.c.

char* uncomp[NROF_COMPRESS_METHODS][3]
Initial value:
{
    {NULL, NULL, NULL},
    {".Z", UNCOMPRESS, COMPRESS},
    {".gz", GUNZIP, GZIP},
    {".bz2", BUNZIP, BZIP}
}

This is a list of the suffix, uncompress and compress functions. Thus, if you have some other compress program you want to use, the only thing that needs to be done is to extended this.

The first entry must be NULL - this is what is used for non compressed files.

Definition at line 153 of file porting.c.