F
Florian Quetting
Hi,
I'm getting mad with following problem: The code compiles, but I always get
a segfault and I don't have any clue why. I can't see any differences in my
way of calling mktime and others.
---------------------------------------------------------------------------
#include <iostream>
#include <sys/stat.h>
#include <time.h>
// -1 bei Fehler (z.B.: File not found)
// 0 -> nicht modifiziert
// 1 -> wurde modifiziert
int file_modified_since(char* file, char* date) {
struct stat* fileattribs;
time_t last_modification;
struct tm brokentime;
time_t datestamp;
stat(file, fileattribs);
std::cout << "File: " << file << "\n";
std::cout << "Last Content Change: " << fileattribs->st_mtime <<
"\n"; //time_t
std::cout << "Last Attrib Change: " << fileattribs->st_ctime << "\n";
if (fileattribs->st_mtime > fileattribs->st_ctime) {
last_modification = fileattribs->st_mtime;
} else {
last_modification = fileattribs->st_ctime;
}
std::cout << "Last Modification: " << last_modification << "\n\n";
std::cout << "Date: " << date << "\n";
brokentime.tm_year = 104;
brokentime.tm_mon = 11;
brokentime.tm_mday = 31;
brokentime.tm_hour = 12;
brokentime.tm_min = 15;
brokentime.tm_sec = 59;
mktime(&brokentime); // segfaults.
return -1;
};
I'm getting mad with following problem: The code compiles, but I always get
a segfault and I don't have any clue why. I can't see any differences in my
way of calling mktime and others.
---------------------------------------------------------------------------
#include <iostream>
#include <sys/stat.h>
#include <time.h>
// -1 bei Fehler (z.B.: File not found)
// 0 -> nicht modifiziert
// 1 -> wurde modifiziert
int file_modified_since(char* file, char* date) {
struct stat* fileattribs;
time_t last_modification;
struct tm brokentime;
time_t datestamp;
stat(file, fileattribs);
std::cout << "File: " << file << "\n";
std::cout << "Last Content Change: " << fileattribs->st_mtime <<
"\n"; //time_t
std::cout << "Last Attrib Change: " << fileattribs->st_ctime << "\n";
if (fileattribs->st_mtime > fileattribs->st_ctime) {
last_modification = fileattribs->st_mtime;
} else {
last_modification = fileattribs->st_ctime;
}
std::cout << "Last Modification: " << last_modification << "\n\n";
std::cout << "Date: " << date << "\n";
brokentime.tm_year = 104;
brokentime.tm_mon = 11;
brokentime.tm_mday = 31;
brokentime.tm_hour = 12;
brokentime.tm_min = 15;
brokentime.tm_sec = 59;
mktime(&brokentime); // segfaults.
return -1;
};