PHOEBE accessories

PHOEBE accessories — functions that facilitate common type manipulation

Synopsis

int                 phoebe_open_directory               (DIR **dirlist,
                                                         const char *dirname);
int                 phoebe_close_directory              (DIR **dir);
bool                phoebe_filename_exists              (const char *filename);
bool                phoebe_filename_has_write_permissions
                                                        (const char *filename);
bool                phoebe_filename_has_read_permissions
                                                        (const char *filename);
bool                phoebe_filename_has_execute_permissions
                                                        (const char *filename);
bool                phoebe_filename_has_full_permissions
                                                        (const char *filename);
bool                phoebe_filename_is_directory        (const char *filename);
bool                phoebe_filename_is_regular_file     (const char *filename);
char*               phoebe_get_current_working_directory
                                                        ();
char*               phoebe_resolve_relative_filename    (char *filename);
int                 phoebe_list_directory_contents      (char *dir);
char*               phoebe_concatenate_strings          (const char *str,
                                                         ...);
char*               phoebe_clean_data_line              (char *line);
bool                atob                                (char *str);
char*               phoebe_strdup                       (const char *s);
char*               phoebe_readline                     (FILE *stream);
char*               phoebe_create_temp_filename         (char *templ);

Description

These are the functions that facilitate common type manipulation. They mostly pertain to I/O and string handling.

Details

phoebe_open_directory ()

int                 phoebe_open_directory               (DIR **dirlist,
                                                         const char *dirname);

This is a wrapper to opendir() for opening the directory dirname gracefully. In case opendir() is successful, a pointer to the directory stream dir is set and SUCCESS is returned. Otherwise dir is set to NULL and error code is returned.

dirlist :

dirname :

path to the directory

Returns :

PHOEBE_error_code.

phoebe_close_directory ()

int                 phoebe_close_directory              (DIR **dir);

This is a wrapper to closedir() for closing the directory stream dir gracefully. In case closedir() is successful, SUCCESS is returned; otherwise error code is returned.

dir :

pointer to the directory stream

Returns :

PHOEBE_error_code.

phoebe_filename_exists ()

bool                phoebe_filename_exists              (const char *filename);

Checks for existence of the file filename. Returns YES if it exists and NO if it does not exist.

filename :

path to the file to be checked for existence

Returns :

bool.

phoebe_filename_has_write_permissions ()

bool                phoebe_filename_has_write_permissions
                                                        (const char *filename);

Checks for write permissions of the file filename. Returns YES if it has write permissions and NO if it does not.

filename :

path to the file to be checked for permissions

Returns :

bool.

phoebe_filename_has_read_permissions ()

bool                phoebe_filename_has_read_permissions
                                                        (const char *filename);

Checks for read permissions of the file filename. Returns YES if it has read permissions and NO if it does not.

filename :

path to the file to be checked for permissions

Returns :

bool.

phoebe_filename_has_execute_permissions ()

bool                phoebe_filename_has_execute_permissions
                                                        (const char *filename);

Checks for execute permissions of the file filename. Returns YES if it has execute permissions and NO if it does not.

filename :

path to the file to be checked for permissions

Returns :

bool.

phoebe_filename_has_full_permissions ()

bool                phoebe_filename_has_full_permissions
                                                        (const char *filename);

Checks for full (read, write, execute) permissions of the file filename. Returns YES if it has full permissions and NO if it does not.

filename :

path to the file to be checked for permissions

Returns :

bool.

phoebe_filename_is_directory ()

bool                phoebe_filename_is_directory        (const char *filename);

Checks whether the file filename is a directory. Returns YES if it is a directory and NO if it is not.

filename :

path to the file to be checked for type

Returns :

bool.

phoebe_filename_is_regular_file ()

bool                phoebe_filename_is_regular_file     (const char *filename);

Checks whether the file filename is a regular file. Returns YES if it is a regular file and NO if it is not.

filename :

path to the file to be checked for type

Returns :

bool.

phoebe_get_current_working_directory ()

char*               phoebe_get_current_working_directory
                                                        ();

Queries the system for the current working directory and returns it. This function allocates the memory to hold the path; the calling function has to free the allocated memory after it is done using it.

Returns :

path to the current working directory.

phoebe_resolve_relative_filename ()

char*               phoebe_resolve_relative_filename    (char *filename);

This function takes a relative filename and resolves it to absolute; it allocates the memory for the string itself, the calling function has to free it.

filename :

relative path to be resolved (made absolute)

Returns :

bool.

phoebe_list_directory_contents ()

int                 phoebe_list_directory_contents      (char *dir);

This function lists the contents of the directory dir on screen. It is used mostly for debugging purposes.

dir :

path to the directory to be listed

Returns :

bool.

phoebe_concatenate_strings ()

char*               phoebe_concatenate_strings          (const char *str,
                                                         ...);

Concatenates all passed strings into one string. The last argument to be passed must be NULL. The user should free the returned string when it is no longer necessary.

str :

first string to be concatenated

... :

a NULL-terminated list of strings to be concatenated

Returns :

a newly allocated, concatenated string.

phoebe_clean_data_line ()

char*               phoebe_clean_data_line              (char *line);

Takes a string, cleans it of all comment delimeters, spaces, tabs and newlines, and copies the contents to a newly allocated string. The original string is not modified in any way.

line :

input string to be cleaned

Returns :

clean string.

atob ()

bool                atob                                (char *str);

This is a natural extension to C's ato* family of functions that converts a string str to a boolean.

str :

string to be converted to boolean

Returns :

bool.

phoebe_strdup ()

char*               phoebe_strdup                       (const char *s);

The strdup() function is used excessively throughout PHOEBE sources. Although virtually every single modern C library defines it in the string.h header file, we supply here a copy just to be sure for the remaining C libraries.

s :

string to be duplicated

Returns :

a duplicate of string s.

phoebe_readline ()

char*               phoebe_readline                     (FILE *stream);

Reads a line from the file stream stream. The memory to hold the line is allocated dynamically, so there is no limit to the length of the line. It also means that the user must not allocate the string before the call to this function, and that the memory should be freed after its use.

stream :

file stream from which to read a line

Returns :

a string containing the read line.

phoebe_create_temp_filename ()

char*               phoebe_create_temp_filename         (char *templ);

Creates a unique temporary filename in the directory PHOEBE_TEMP_DIR. If a unique filename cannot be found, or if templ is invalid, NULL is returned. The calling function should free the returned string.

templ :

filename template; it must end with XXXXXX

Returns :

string with a unique filename.