ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
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.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
I have a question about this program. This program is supposed to take the inode information modtime and atime of a file and modify it. I did not really think much about this code so there are some consistencies but its better than nothing. My code is:
backdate.c:54: request for member `actime' in something not a structure or union
backdate.c:55: request for member `modtime' in something not a structure or union
#include <sys/types.h>
#include <sys/stat.h>
#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
#include <dirent.h>
#include <time.h>
#include <utime.h> /* FIXED: You forgot this one */
int main(int argc, char *argv[]) /* FIXED: forgot return type, not important though. */
{
DIR *dirp;
struct dirent *dentry;
struct stat buffer;
struct utimbuf date;
char* fname;
int days;
if(argc < 1 || argc > 3) {
fprintf(stderr, "usage: backdate [path] filename days\n");
exit(1);
}
if(argc == 2) {
fname = argv[1];
days = atoi(argv[2]); /* FIXED: need to convert string to int */
} else {
if(chdir(argv[1]) < 0) { /* FIXED: chdir returns int not pointer */
fprintf(stderr, "%s: cannot open %s\n", argv[0], argv[1]);
exit(1);
} else {
fname = argv[2];
days = atoi(argv[3]); /* FIXED: need to convert string to int */
}
}
while((dentry = readdir(chdir(argv[1]))) != NULL) {
/* After checking the line above I gave up. Doesn't make sense.
Please read the man pages on the functions you call
and try to fix at least some things yourself first.
*/
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.