Header File
io.h
Category
Input/output Routines
Prototype
int getftime(int handle, struct ftime *ftimep);
int setftime(int handle, struct ftime *ftimep);
Description
Gets and sets the file date and time.
getftime retrieves the file time and date for the disk file associated with the open handle. The ftime structure pointed to by ftimep is filled in with the file's time and date.
setftime sets the file date and time of the disk file associated with the open handle to the date and time in the ftime structure pointed to by ftimep. The file must not be written to after the setftime call or the changed information will be lost. The file must be open for writing; an EACCES error will occur if the file is open for read-only access.
setftime requires the file to be open for writing; an EACCES error will occur if the file is open for read-only access.
The ftime structure is defined as follows:
struct ftime {
unsigned ft_tsec: 5; /* two seconds */
unsigned ft_min: 6; /* minutes */
unsigned ft_hour: 5; /* hours */
unsigned ft_day: 5; /* days */
unsigned ft_month: 4; /* months */
unsigned ft_year: 7; /* year - 1980*/
};
Return Value
getftime and setftime return 0 on success.
In the event of an error return -1 is returned and the global variable errno is set to one of the following values:
EACCES |
Permission denied |
EBADF |
Bad file number |
EINVFNC |
Invalid function number |
Example
#include <stdio.h> #include <io.h> int main(void) { FILE *stream; std::ftime ft; if ((stream = fopen("TEST.$$$", "wt")) == NULL) { fprintf(stderr, "Cannot open output file.\n"); return 1; } getftime(fileno(stream), &ft); printf("File time: %u:%u:%u\n", ft.ft_hour, ft.ft_min, ft.ft_tsec * 2); printf("File date: %u/%u/%u\n", ft.ft_month, ft.ft_day, ft.ft_year+1980); fclose(stream); return 0; }
Copyright(C) 2008 CodeGear(TM). All Rights Reserved.
|
What do you think about this topic? Send feedback!
|