[v2,09/16] libelf: uid_t, gid_t and mode_t are not comes with msvcrt, so using long/unsigned long instead on win32

Message ID 20221217165213.152-10-luoyonggang@gmail.com
State Under Review
Headers
Series Patches for building with mingw/gcc msvc/clang-cl |

Commit Message

Yonggang Luo Dec. 17, 2022, 4:52 p.m. UTC
  Signed-off-by: Yonggang Luo <luoyonggang@gmail.com>
---
 libelf/libelf.h | 6 ++++++
 1 file changed, 6 insertions(+)
  

Comments

Mark Wielaard March 2, 2023, 1:24 p.m. UTC | #1
Hi,

On Sun, 2022-12-18 at 00:52 +0800, Yonggang Luo via Elfutils-devel
wrote:
> Signed-off-by: Yonggang Luo <luoyonggang@gmail.com>
> ---
>  libelf/libelf.h | 6 ++++++
>  1 file changed, 6 insertions(+)
> 
> diff --git a/libelf/libelf.h b/libelf/libelf.h
> index a139e733..2fa3838b 100644
> --- a/libelf/libelf.h
> +++ b/libelf/libelf.h
> @@ -195,9 +195,15 @@ typedef struct
>  {
>    char *ar_name;		/* Name of archive member.  */
>    time_t ar_date;		/* File date.  */
> +#if defined(_WIN32)
> +  long ar_uid;
> +  long ar_gid;
> +  unsigned long ar_mode;
> +#else
>    uid_t ar_uid;			/* User ID.  */
>    gid_t ar_gid;			/* Group ID.  */
>    mode_t ar_mode;		/* File mode.  */
> +#endif
>    int64_t ar_size;		/* File size.  */
>    char *ar_rawname;		/* Original name of archive member.  */
>  } Elf_Arhdr;

uid_t, gid_t and mode_t are all defined by POSIX to be provided through
sys/types.h. Except for defining them as integer types it doesn't
really say how big they are. elf_begin has some macros to handle either
int or long types generically. But ar.c also simply uses uid_t, gid_t
and mode_t. So those should then also be adjusted.

Can't we use some configure check instead?

I am somewhat hesitant to change this because it is in a public header.

Cheers,

Mark
  

Patch

diff --git a/libelf/libelf.h b/libelf/libelf.h
index a139e733..2fa3838b 100644
--- a/libelf/libelf.h
+++ b/libelf/libelf.h
@@ -195,9 +195,15 @@  typedef struct
 {
   char *ar_name;		/* Name of archive member.  */
   time_t ar_date;		/* File date.  */
+#if defined(_WIN32)
+  long ar_uid;
+  long ar_gid;
+  unsigned long ar_mode;
+#else
   uid_t ar_uid;			/* User ID.  */
   gid_t ar_gid;			/* Group ID.  */
   mode_t ar_mode;		/* File mode.  */
+#endif
   int64_t ar_size;		/* File size.  */
   char *ar_rawname;		/* Original name of archive member.  */
 } Elf_Arhdr;