SDDSlib
|
Utility functions for handling file links and retrieving file information. More...
#include <unistd.h>
#include "mdb.h"
Go to the source code of this file.
Functions | |
char * | dir_name (const char *path) |
Retrieves the leading directories from a given path. | |
char * | read_file_link (const char *filename) |
Reads the first link of a file. | |
const char * | read_file_lastlink (const char *filename) |
Retrieves the last link in a chain of symbolic links. | |
char * | read_last_link_to_file (const char *filename) |
Resolves the final target file that a symbolic link points to. | |
long | get_file_stat (const char *filename, const char *final_file, struct stat *filestat) |
Retrieves the file status of a given file or its final link target. | |
long | file_is_modified (const char *inputfile, char **final_file, struct stat *input_stat) |
Checks if a file has been modified. | |
Utility functions for handling file links and retrieving file information.
Definition in file filestat.c.
char * dir_name | ( | const char * | path | ) |
Retrieves the leading directories from a given path.
Allocates memory for the leading directories part of the provided PATH. If memory allocation fails, returns NULL. Assumes that any trailing slashes in PATH have already been removed. This function avoids using the dirname
builtin to maintain consistent behavior across different environments.
path | The file path from which to extract the leading directories. |
Definition at line 33 of file filestat.c.
long file_is_modified | ( | const char * | inputfile, |
char ** | final_file, | ||
struct stat * | input_stat ) |
Checks if a file has been modified.
Determines whether the specified input file has been modified by comparing its current state against a previously recorded state. If the file is a symbolic link, it checks the final target file for modifications. The function updates the final_file pointer if the link target has changed.
inputfile | The path to the input file to check for modifications. |
final_file | Pointer to a string containing the final target file name. May be updated. |
input_stat | Pointer to a struct stat containing the previous state of the file. |
Definition at line 191 of file filestat.c.
long get_file_stat | ( | const char * | filename, |
const char * | final_file, | ||
struct stat * | filestat ) |
Retrieves the file status of a given file or its final link target.
Obtains the file status information for the specified filename. If the file is a symbolic link and a final_file is provided, it retrieves the status of the final target file. If the file does not exist or an error occurs during the retrieval, an error message is printed to stderr.
filename | The name of the file to retrieve the status for. |
final_file | Optional parameter specifying the final target file if filename is a link. |
filestat | Pointer to a struct stat where the file status will be stored. |
Definition at line 162 of file filestat.c.
const char * read_file_lastlink | ( | const char * | filename | ) |
Retrieves the last link in a chain of symbolic links.
Traverses the chain of symbolic links starting from the given filename and returns the name of the last link that directly points to the final target file. If the file is not a link, returns the original filename.
filename | The starting file name to resolve the last link from. |
Definition at line 112 of file filestat.c.
char * read_file_link | ( | const char * | filename | ) |
Reads the first link of a file.
Returns the first link of the specified file. If the file is not a link or if an error occurs (including unsupported platforms), returns NULL. On successful retrieval, the returned string is dynamically allocated and should be freed by the caller.
filename | The name of the file to read the link from. |
Definition at line 68 of file filestat.c.
char * read_last_link_to_file | ( | const char * | filename | ) |
Resolves the final target file that a symbolic link points to.
Follows the chain of symbolic links starting from the given filename and returns the name of the final target file. The returned string is dynamically allocated and should be freed by the caller. If the filename is not a link, returns NULL.
filename | The starting file name to resolve to the final target. |
Definition at line 134 of file filestat.c.