On Wed, 25 May 2022, nil-admir...@mailo.com wrote:

+ struct win32_stat
+ {
+ _dev_t st_dev; /* ID of device containing file */
+ _ino_t st_ino; /* inode number */
+ unsigned short st_mode; /* protection */
+ short st_nlink; /* number of hard links */
+ short st_uid; /* user ID of owner */
+ short st_gid; /* group ID of owner */
+ _dev_t st_rdev; /* device ID (if special file) */
+ int64_t st_size; /* total size, in bytes */
+ int64_t st_atime; /* time of last access */
+ int64_t st_mtime; /* time of last modification */
+ int64_t st_ctime; /* time of last status change */
+ };

Wouldn't it make sense to add a
static_assert(sizeof(struct win32_stat) == sizeof(struct _stati64))
somewhere?

+static inline void copy_stat(struct _stati64 *winstat, struct win32_stat *par)
+{
+ par->st_dev = winstat->st_dev;
+ par->st_ino = winstat->st_ino;
+ par->st_mode = winstat->st_mode;
+ par->st_nlink = winstat->st_nlink;
+ par->st_uid = winstat->st_uid;
+ par->st_gid = winstat->st_gid;
+ par->st_rdev = winstat->st_rdev;
+ par->st_size = winstat->st_size;
+ par->st_atime = winstat->st_atime;
+ par->st_mtime = winstat->st_mtime;
+ par->st_ctime = winstat->st_ctime;
}

Would memcpy make more sense here?

As explained elsewhere too, the explicit intent is that this is a different struct than the real _stati64 or whichever happens to be used, not necessarily identical.

We don't know the exact layout of the real stat struct (and technically, different C runtimes, e.g. msvcrt.dll, msvcr100.dll, msvcr120.dll, UCRT, could all have different layouts/sizes), and it's brittle to try to guess/mimic it. So instead of trying to mimic it, we just make our own (which is what ends up used in the calling libavformat code) - our wrapper then explicitly uses one from the C runtime (which we don't know the size/layout of), and we just copy it field by field into the one we expose to the caller.

This could use any random layout, as long as it contains the subset of fields from stat that we actually use anywhere.

And if we wanted a static assert, the only relevant assert would be to make sure that our wrapper struct's fields are as large as, or larger, than the ones that the original stat returns.

// Martin

_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".

Reply via email to