Skip to content

Convert st_mtim reference to returning a copy

Calvin Buckley requested to merge calvin/poppler:aix-mtim into master

The reason why we need to do this is because on AIX, st_mtim is not defined as a timespec, but rather, as a a struct { time_t, int }, which isn't compatible. As such, we can't return a direct reference, nor just pass through the struct itself (except the macOS case), so we instead return a new struct with the same field values.

Specifically, from the AIX sys/stat.h...

// [...]

#ifdef _POSIX_SOURCE 

#if _XOPEN_SOURCE>=700
#ifndef _TIMESPEC
#define _TIMESPEC
struct timespec {
        time_t  tv_sec;         /* seconds */
        long    tv_nsec;        /* and nanoseconds */
};
#endif

/* internal timespec to preserve binary compatibility */
typedef struct st_timespec {
        time_t  tv_sec;         /* seconds */
        int     tv_nsec;        /* and nanoseconds */
} st_timespec_t;
#endif

// [...]

struct stat {
        // [...]
#if _XOPEN_SOURCE>=700
        st_timespec_t st_atim;  /* Time of last access  */
        st_timespec_t st_mtim;  /* Time of last data modification */
        st_timespec_t st_ctim;  /* Time of last file status change */
#else
        time_t  st_atime;       /* Time of last access  */
        int     st_atime_n;
        time_t  st_mtime;       /* Time of last data modification */
        int     st_mtime_n;
        time_t  st_ctime;       /* Time of last file status change */
        int     st_ctime_n;
#endif
        // [...]
};

// [...]

I think the performance impact should be minimal.

Merge request reports