Atrinik Client 2.5
Functions
client/misc.c File Reference
#include <global.h>

Go to the source code of this file.

Functions

unsigned long isqrt (unsigned long n)
size_t split_string (char *str, char *array[], size_t array_size, char sep)
void * reallocz (void *ptr, size_t old_size, size_t new_size)
void convert_newline (char *str)
void browser_open (const char *url)
int rndm (int min, int max)
char * package_get_version_full (char *dst, size_t dstlen)
char * package_get_version_partial (char *dst, size_t dstlen)

Detailed Description

Miscellaneous functions.

Definition in file misc.c.


Function Documentation

void browser_open ( const char *  url)

Opens an url in the system's default browser.

Parameters:
urlURL to open.

Definition at line 156 of file misc.c.

void convert_newline ( char *  str)

Replaces "\n" by a newline char.

Since we are replacing 2 chars by 1, no overflow should happen.

Parameters:
lineText to replace into.

Definition at line 140 of file misc.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 36 of file misc.c.

char* package_get_version_full ( char *  dst,
size_t  dstlen 
)

Get the full package version as string.

If patch version is 0, it will not be appended to the version string.

Parameters:
dstWhere to store the version.
dstlenSize of dst.
Returns:
'dst'.

Definition at line 208 of file misc.c.

char* package_get_version_partial ( char *  dst,
size_t  dstlen 
)

Get the partial package version. This means that the patch version will not be included, even if it's not 0.

Parameters:
dstWhere to store the version.
dstlenSize of dst.
Returns:
'dst'

Definition at line 224 of file misc.c.

void* reallocz ( void *  ptr,
size_t  old_size,
size_t  new_size 
)

Like realloc(), but if more bytes are being allocated, they get set to 0 using memset().

Parameters:
ptrOriginal pointer.
old_sizeSize of the pointer.
new_sizeNew size the pointer should have.
Returns:
Resized pointer, NULL on failure.

Definition at line 123 of file misc.c.

int rndm ( int  min,
int  max 
)

Calculates a random number between min and max.

It is suggested one uses this function rather than RANDOM()%, as it would appear that a number of off-by-one-errors exist due to improper use of %.

This should also prevent SIGFPE.

Parameters:
minStarting range.
maxEnding range.
Returns:
The random number.

Definition at line 190 of file misc.c.

size_t split_string ( char *  str,
char *  array[],
size_t  array_size,
char  sep 
)

Splits a string delimited by passed in sep value into characters into an array of strings.

Parameters:
strThe string to be split; will be modified.
arrayThe string array; will be filled with pointers into str.
array_sizeThe number of elements in array; if str contains more fields excess fields are not split but included into the last element.
sepSeparator to use.
Returns:
The number of elements found; always less or equal to array_size.

Definition at line 72 of file misc.c.