Setting the access/modify time on a file

Dave Decot decot at hpisod2.HP.COM
Tue Mar 13 15:16:05 AEST 1990


> Here is what I'm attempting:
> 
> 	FILE *fp;
> >>>   long times;
> 
> 	fp = fopen("filename", "w");
> 	flock(fileno(fp), LOCK_EX);
> 
> 	... much i/o to the file ...
> 
> 	fflush(fp);
> >>>	times[1] = time(&times[0]) - (long)2;
> >>>	utime(mailfile, times);
> 
> 	flock(fileno(fp), LOCK_UN);
> 	fclose(fp);

The lines I marked with >>> above are parts of the problem:

    You did not declare "times" to be an array or initialize it as
    a pointer, but later use it as an array or initialized pointer.

    The argument and return value of time() are supposed to be a pointers
    to type time_t, which is not necessarily a long.

    You did not use lint before bothering 30,000 people.

Dave Decot



More information about the Comp.unix.wizards mailing list