35 const char *slash = NULL;
38 slash = strrchr(path,
'/');
45 while (slash > path && *slash ==
'/')
47 length = slash - path + 1;
49 newpath = (
char *)malloc(length + 1);
52 strncpy(newpath, path, length);
69#if defined(_WIN32) || defined(vxWorks)
72 int size = 100, nchars = -1;
73 char *tmpbuf = NULL, *dir = NULL, *tempname = NULL;
74 tmpbuf = (
char *)calloc(size,
sizeof(
char));
76 nchars = readlink(filename, tmpbuf, size);
86 tempname = (
char *)malloc(
sizeof(
char) * (strlen(filename) + strlen(tmpbuf) + 2));
88 strcat(tempname, dir);
89 strcat(tempname,
"/");
90 strcat(tempname, tmpbuf);
97 tmpbuf = (
char *)realloc(tmpbuf,
sizeof(
char) * size);
113 char *linkname = NULL;
114 const char *lastlink = NULL;
135 char *linkname = NULL;
140 tmpname = (
char *)calloc(1024,
sizeof(
char));
145 }
while (linkname != NULL);
162long get_file_stat(
const char *filename,
const char *final_file,
struct stat *filestat) {
163 const char *input = NULL;
165 fprintf(stderr,
"%s file does not exist, unable to get the state of it!\n", filename);
171 if (stat(input, filestat) != 0) {
172 fprintf(stderr,
"Problem getting state of file %s\n", input);
192 struct stat filestat;
193 char *tempfile = NULL;
194 const char *tmpinput = NULL;
197 fprintf(stderr,
"%s file does not exist!\n", inputfile);
200 if (*final_file && !
fexists(*final_file)) {
201 fprintf(stderr,
"linked file %s of inputfile %s does not exist!\n", *final_file, inputfile);
205 fprintf(stderr,
"The previous state of file %s is not known.\n", inputfile);
212 if (tempfile && *final_file && strcmp(tempfile, *final_file)) {
215 *final_file = tempfile;
218 if ((tempfile && !(*final_file)) || (!tempfile && *final_file)) {
221 *final_file = tempfile;
228 tmpinput = *final_file;
230 tmpinput = inputfile;
231 filestat = *input_stat;
232 if (stat(tmpinput, input_stat) != 0) {
233 fprintf(stderr,
"Problem getting modification time for %s\n", tmpinput);
236 if (input_stat->st_ctime != filestat.st_ctime) {
long fexists(const char *filename)
Checks if a file exists.
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.
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.
long file_is_modified(const char *inputfile, char **final_file, struct stat *input_stat)
Checks if a file has been modified.
char * read_last_link_to_file(const char *filename)
Resolves the final target file that a symbolic link points to.
char * dir_name(const char *path)
Retrieves the leading directories from a given path.
char * strcpy_ss(char *dest, const char *src)
Safely copies a string, handling memory overlap.
char * tmpname(char *s)
Supplies a unique temporary filename.