ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
Hi, I am new to both C++ and Linux. I am working on a license key generator. One of the unique characteristics that we are going to grab off of a linux machine is the datestamp of when /bin was created. I would like the date as a long. Is there an easy way to do this?
thank you very much in advance.
"The person who suggested you start with the discrepency" is correct.
Here's sample code:
#define BIN_DIR "/bin"
main (int argc, char *argv)
struct stat st;
int ierr = stat (BIN_DIR, &st);
if (ierr != 0)
printf("Sorry: couldn't find %s: ierr= %d\n", BIN_DIR, ierr);
"dev_t st_dev: %lu /* device */\n"
"ino_t st_ino: %lu /* inode */\n"
"mode_t st_mode: %lu /* protection */\n"
"nlink_t st_nlink: %lu /* number of hard links */\n"
"uid_t st_uid: %lu /* user ID of owner */\n"
"gid_t st_gid: %lu /* group ID of owner */\n"
"dev_t st_rdev: %lu /* device type (if inode device) */\n"
"off_t st_size: %lu /* total size, in bytes */\n"
"blksize_t st_blksize: %lu /* blocksize for filesystem I/O */\n"
"blkcnt_t st_blocks: %lu /* number of blocks allocated */\n"
"time_t st_atime: %lu /* time of last access */\n"
"time_t st_mtime: %lu /* time of last modification */\n"
"time_t st_ctime: %lu /* time of last status change */\n",
gcc -Wall -g -o x x.c
dev_t st_dev: 770 /* device */
ino_t st_ino: 52 /* inode */
mode_t st_mode: 16877 /* protection */
nlink_t st_nlink: 2 /* number of hard links */
uid_t st_uid: 0 /* user ID of owner */
gid_t st_gid: 0 /* group ID of owner */
dev_t st_rdev: 0 /* device type (if inode device) */
off_t st_size: 2896 /* total size, in bytes */
blksize_t st_blksize: 4096 /* blocksize for filesystem I/O */
blkcnt_t st_blocks: 5 /* number of blocks allocated */
time_t st_atime: 1237848350 /* time of last access */
time_t st_mtime: 1160427118 /* time of last modification */
time_t st_ctime: 1160427118 /* time of last status change */
'Hope that helps - "The person who suggested the code that used st_mtime" ;-)
OK, nm those last messages, it was just a c++ linking error. I compiled w/ g++ and everything was fine.
My concern now is that it is getting the mtime or the ctime, which are modified and changed, correct?
The time that I get absolutely has to be something that is not going to change, because it is for a unique key for a system. If these times change, then the key will cease to work. Are these times something that will change?
I've been able to simply execute "touch bin", at which point the ctime, mtime, and atime all change from their previous values. I have read on some forums that linux actually does not save any "creation" time variables and that it is basically impossible to retrieve this information. I am ready to give up on this idea and chalk it up to impossible.
On a side note, I was able to get the first logins to the system with the function "last" called from command line. Do you know if this can also be stored in a struct? I have searched around but have been unable so far to find information.