common

Name

common -- 

Synopsis



void*       prelude_realloc                 (void *ptr,
                                             size_t size);
int         prelude_resolve_addr            (const char *hostname,
                                             struct in_addr *addr);
int         prelude_open_persistant_tmpfile (const char *filename,
                                             int flags,
                                             mode_t mode);
int         prelude_read_multiline          (FILE *fd,
                                             int *line,
                                             char *buf,
                                             size_t size);

Description

Details

prelude_realloc ()

void*       prelude_realloc                 (void *ptr,
                                             size_t size);

prelude_realloc() changes the size of the memory block pointed to by ptr to size bytes. The contents will be unchanged to the minimum of the old and new sizes; newly allocated memory will be uninitialized. If ptr is NULL, the call is equivalent to malloc(size); if size is equal to zero, the call is equivalent to free(ptr). Unless ptr is NULL, it must have been returned by an earlier call to malloc(), calloc() or realloc().

This function exist because some version of realloc() doesn't handle the case where ptr is NULL. Even thought ANSI allow it.

ptr :

Pointer on a memory block.

size :

New size.


prelude_resolve_addr ()

int         prelude_resolve_addr            (const char *hostname,
                                             struct in_addr *addr);

Lookup hostname, and store the resolved IP address in addr.

hostname :

Hostname to lookup.

addr :

Pointer on an in_addr structure to store the result in.

Returns :

0 on success, -1 if an error occured.


prelude_open_persistant_tmpfile ()

int         prelude_open_persistant_tmpfile (const char *filename,
                                             int flags,
                                             mode_t mode);

Open a *possibly persistant* file for writing, trying to avoid symlink attack as much as possible.

The file is created if it does not exist. Refer to open(2) for flags and mode meaning.

filename :

Path to the file to open.

flags :

Flags that should be used to open the file.

mode :

Mode that should be used to open the file.

Returns :

A valid file descriptor on success, -1 if an error occured.


prelude_read_multiline ()

int         prelude_read_multiline          (FILE *fd,
                                             int *line,
                                             char *buf,
                                             size_t size);

This function handle reading line separated by the '\' character.

fd :

File descriptor to read input from.

line :

Pointer to a line counter.

buf :

Pointer to a buffer where the line should be stored.

size :

Size of the buf buffer.

Returns :

0 on success, -1 if an error ocurred.