

#UTIME FUNCTION C CODE#
Let’s look more closely at what happens when we run our code that uses stat.st_mtime and os.utime: If newvalue is omitted, return the current setting. If newvalue is True, future calls to stat() return floats, if it is False, future calls return ints. Nothing under stat, but there’s something interesting called stat_float_times:ĭetermine whether stat_result represents time stamps as float objects. Now, to see if we can guess how the new way works:ĪttributeError: 'posix.stat_result' object has no attribute 'st_mtim' Os.utime(" timmy", (s.st_atime, s.st_mtime)) Incidentally, POSIX.1-2008 considers the non-nanosecond-resolution functions and members to be deprecated, although since the nanosecond resolution functions aren’t universally available yet, a certain amount of autovoodoo is generally required… If (- 1 = utimensat(AT_FDCWD, "timmy", times, 0)) Thus, we need a way to set a file’s mtime to a given value, and to do this we would historically have used a function from the utime family: #include #include #include #include #include #include int main( int argc, char * argv)įd = open( "timmy", O_WRONLY, O_TRUNC | O_CREAT)


Sometimes we might want to modify a file, but not affect its mtime. Printf( "stat.st_mtime for timmy is %ld \n ", s.st_mtime) To get the mtime of a file, historically we would have used the st_mtime field, which is of type time_t, which is an integer of some kind: #include #include #include #include #include int main( int argc, char * argv) The stat system call places information about a file into a struct also named stat (which is possible thanks to a lesser case of brain damage in C’s design). Two groups of system calls are of interest to us here.įirst, stat (and its fstat and lstat variants). The modification time for a file is one place such a timestamp has been used. On Unix, timestamps have traditionally been held as an integer number of seconds since the epoch. Today, however, we shall be looking at a particularly egregious case of stupidity the likes of which not even PHP has managed to replicate. The primary design principle behind the Python programming language is to take everything that’s horrible and wrong with Perl and get it horrible and wrong in a completely different and even more hideous way.
