Main Page   Alphabetical List   Data Structures   File List   Data Fields   Globals   Examples  

dir.c File Reference

Go to the source code of this file.

Functions

int read_directory (char *dir_name, struct file_list *flist)
 List the content of a directory (compatible SUN/LINUX).

int read_directory_only (char *dir_name, struct file_list *flist_out)
 List the content of a directory, and keeps only the directories.

void free_file_list (struct file_list *flist)
 Free all allocated memory after you called read_directory().

int base_dir_name (char *dirname, char **res)
 Extract the directory base name from a file name.


Detailed Description

This file contains various utilities to manipulate directory.

Definition in file dir.c.


Function Documentation

int base_dir_name char *    dirname,
char **    res
 

Extract the directory base name from a file name.

Parameters:
dirname Pointer to a NULL terminated that represents the file name.
res Pointer to a pointer that will receive the directory base name.
Returns:
If the function found the directory base name, then it returns BASE_DIR_FOUND and in this case 'res' contains the directory base name. If the function can not extract the directory base name it returns BASE_DIR_NOT_FOUND and in this case 'res' is a NULL pointer. If the function returns BASE_DIR_NO_MEM, it means that the function can not allocate memory (in this case 'res' is NULL).
Warning:
'res' has been allocated within the function. You must delete it yoursef (using free()). But before you free it, make sure to check that 'res' is not NULL (if (res != NULL) { free (res); }).
Examples:
test_basename.c.

Definition at line 187 of file dir.c.

References BASE_DIR_FOUND, BASE_DIR_NO_MEM, and BASE_DIR_NOT_FOUND.

void free_file_list struct file_list   flist
 

Free all allocated memory after you called read_directory().

Parameters:
flist Pointer to a structure 'file_list' that should have been filled by read_directory().
Warning:
ALWAYS call this function after read_directory().
Examples:
test_dir.c.

Definition at line 162 of file dir.c.

References file_list::list, file_list::num, and file_list::total_alloc.

Referenced by read_directory_only().

int read_directory char *    dir_name,
struct file_list   flist
 

List the content of a directory (compatible SUN/LINUX).

Parameters:
dir_name Pointer to a zero terminated string of characters that represents the name of the directory to list.
flist Pointer to a 'file_list' structure that will be used to store directory's content.
Returns:
If the function succed, it returns a positive number that represents the number of entries in the directory. Oterwise, the function returns -1.
Warning:
Some fields in the structure 'flist' has been allocated within the function. You must call free_file_list() of 'flist' to free all the allocated memory.
Examples:
test_dir.c.

Definition at line 18 of file dir.c.

References FILE_NUMBER, file_list::list, file_list::num, and file_list::total_alloc.

Referenced by read_directory_only().

int read_directory_only char *    dir_name,
struct file_list   flist_out
 

List the content of a directory, and keeps only the directories.

Parameters:
dir_name Pointer to a zero terminated string of characters that represents the name of the directory to list.
flist_out Pointer to a 'file_list' structure that will be used to store directory's content.
Returns:
If the function succed, it returns a positive number that represents the number of entries in the directory. Oterwise, the function returns -1.
Warning:
Some fields in the structure 'flist' has been allocated within the function. You must call free_file_list() of 'flist' to free all the allocated memory.
Examples:
test_dir.c.

Definition at line 87 of file dir.c.

References free_file_list(), file_list::list, file_list::num, read_directory(), and file_list::total_alloc.


Generated on Thu Apr 3 16:23:45 2003 for Common_C_libraries by doxygen1.3-rc1